home *** CD-ROM | disk | FTP | other *** search
- class IDChain {
- IDChain next = null;
- int id;
- long time;
- int depth;
-
- public IDChain() { // sentinel
- id = -1;
- time = -1;
- depth = -1;
- }
-
- public IDChain(int i, long tim, int d){
- id = i;
- time = tim;
- depth = d;
- }
-
- public void setNext(IDChain nxt){next = nxt;}
- public void setID(int i) {id = i;}
- public void setTime(long tim) {time = tim;}
- public void setDepth(int d) {depth = d;}
-
- public IDChain getNext() {return next;}
- public int getID() {return id;}
- public long getTime() {return time;}
- public long getDepth() {return depth;}
-
- public void insert(IDChain idc) { // insert idc after this
- if (next != null) {
- idc.setNext(next);
- }
- next = idc;
- }
-
- public void insertByTime(IDChain idc) { // insert idc by Time order
- IDChain p = this;
-
- for (p = this; p.getNext() != null; p = p.getNext()) {
- if (p.getNext().getTime() >= idc.getTime()) {
- idc.setNext(p.getNext());
- p.setNext(idc);
- return;
- }
- }
- p.setNext(idc);
- }
-
- public void insertByDepth(IDChain idc) { // insert idc by depth order
- IDChain p = this;
-
- for (p = this; p.getNext() != null; p = p.getNext()) {
- if (p.getNext().getDepth() >= idc.getDepth()) {
- idc.setNext(p.getNext());
- p.setNext(idc);
- return;
- }
- }
- p.setNext(idc);
- }
-
- public void remove() { // remove next element
- if (next == null) {
- return;
- }
- next = next.getNext();
- }
-
- }
-
-