?? recodequeue.java
字號:
package autoencodeinfinit.QueueProcess;import java.util.Collection;import java.util.Iterator;import autoencodeinfinit.XMLProcess.XMLProcess;import org.w3c.dom.Element;import org.w3c.dom.Node;/** * create a queue with its basically functions and provide parameter change function from the data of * XML * @author ulysess */public class ReCodeQueue extends java.util.AbstractQueue { private QueueEntity first = null , last = null , temp = null; private int maxlength = 30 , length = 0; private String statusxml = null; /** * Add queue entity toadd into the queue by use the method offer() , if offer() * return true then return true otherwise throw the IllegalStateException. * this method is add according the defination of the class java.util.AbstractQueue * recommend use the offer method to add entity * @param toadd : the QueueEntity to be added to the last of the queue * @return only return true while offer method return true */ public boolean add(QueueEntity toadd) { if ( this.offer(toadd) ) { return true; } else { throw new java.lang.IllegalStateException("Can't add Queue Entity into the queue") ; } } /** * Add queue entity to the last of the queue if possible * @param e : the QueueEntity to be added to the last of the queue * @return only when the queue is full or toadd is null this method will return false */ public boolean offer(Object e) { if(e instanceof QueueEntity) { QueueEntity toadd =(QueueEntity) e; if (first == null && toadd != null) { first = toadd; last = toadd; this.length += 1; this.fresh(); return true; } else if (this.length < this.maxlength && toadd != null ){ last.setNext(toadd); last = toadd; this.length += 1; this.fresh(); return true; } else { return false; } } else { throw new java.lang.IllegalStateException("Insert a object which is't instanceof QueueEntity"); } } /** * return the first entity of the queue and remove it from the queue , if the queue is empty throw a exception * @return */ public QueueEntity remove() { if (this.first != null) { this.temp = this.first; this.first = this.first.getNext(); this.length -=1; this.fresh(); return temp; } else { throw new java.lang.IllegalStateException("Can remove entity from empty queue"); } } /** * Return the first entity of the queue and remove if from the queue ,if the queue is empty return null; * @return the first entity of the queue,if queue is empty return null */ public QueueEntity poll() { if (this.first != null) { this.temp = this.first; this.first = this.first.getNext(); this.length -= 1; this.fresh(); return temp; } else { return null; } } /** * return the first entity of the queue,if the queue is empty ,throw a exception * @return */ public QueueEntity element() { if (this.first != null) { return this.first; } else { throw new java.lang.IllegalStateException("The queue is empty"); } } /** * return the first entity of the queue. * @return */ public QueueEntity peek() { return this.first; } /** * move the queue entity in the index number orginal to the index number object * @param orginal * @param object * @return */ public boolean jumpQueue(int orginal , int object){ if( orginal > this.length || object > this.length || orginal*object < 0) { return false; } QueueEntity temp1 = this.first , temp2 = first , temp3 = null; int count = 1; for(; count == orginal - 2 ; count++ ) { temp1 = temp1.getNext(); } for(count = 0 ; count == object - 2 ; count++){ temp2 = temp2.getNext(); } temp3=temp1; temp1.setNext(temp1.getNext().getNext()); temp3.getNext().setNext(temp2.getNext()); temp2.setNext(temp3.getNext()); return true; } /** * return the length of the queue * @return */ public int size() { return this.length; } /** * check if the queue is empty * @return */ public boolean isEmpty() { return (this.first == null); } /** * check if this queue inclue the entity qe * @param qe * @return */ public boolean contains(QueueEntity qe) { for(QueueEntity temp = first ; temp != null ; temp=temp.getNext()){ if (qe.getIdentity() == temp.getIdentity() ) { return true; } } return false; } /** * not implemented yet; * @return */ public Iterator iterator() { throw new UnsupportedOperationException("Not supported yet."); } /** * not implemented yet; * @return */ public Object[] toArray() { throw new UnsupportedOperationException("Not supported yet."); } /** * not implemented yet; * @return */ public Object[] toArray(Object[] a) { throw new UnsupportedOperationException("Not supported yet."); } /** * remove the specific index queue entity * @param index : the index number of the queue * @return */ public boolean remove(int index) { int count =1; QueueEntity obj = this.first; if (index > this.length || index > this.maxlength ) { return false; } for( ; count == index - 1 ; count++) { obj = obj.getNext(); } obj.setNext(obj.getNext().getNext()); this.fresh(); return true; } /** * not implemented yet; * @return */ public boolean containsAll(Collection c) { throw new UnsupportedOperationException("Not supported yet."); } /** * not implemented yet; * @return */ public boolean addAll(Collection c) { throw new UnsupportedOperationException("Not supported yet."); } /** * not implemented yet; * @return */ public boolean removeAll(Collection c) { throw new UnsupportedOperationException("Not supported yet."); } /** * not implemented yet; * @return */ public boolean retainAll(Collection c) { throw new UnsupportedOperationException("Not supported yet."); } /** * set empty of this queue */ public void clear() { this.first=this.last=null; } /** * fresh the queue information in the xml document */ public void fresh() { } public void writeQueueStatus(String add) { XMLProcess statxmlprocess = null; if(add != null && this.statusxml != null) { statxmlprocess = XMLProcess.CreateXMLFile(add); } else { statxmlprocess = new XMLProcess(add); } } public void writeQueueStatus() { this.writeQueueStatus(this.statusxml); } private void createStatus(XMLProcess xmlnode) { QueueEntity iter = this.first; for (int i = 0; i < this.length ; i++) { Element insert = xmlnode.insertNodeIn(xmlnode.getRoot(), "Queue Entities" , null); for(int cut = 1 ; cut < 5 ; cut ++) { xmlnode.insertNodeIn(insert, "Index", java.lang.String.valueOf(i)); xmlnode.insertNodeIn(insert, "Input Address", iter.getInputAdd()); xmlnode.insertNodeIn(insert, "Output", iter.getOutputAdd()); xmlnode.insertNodeIn(insert, "Parameter", iter.toMencoderParameter()); xmlnode.insertNodeIn(insert, "Movie Information", ""); xmlnode.insertNodeIn(insert, "Index", java.lang.String.valueOf(i)); } } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -