1 9 package org.ozoneDB.DxLib; 10 11 12 public class DxListBag extends DxAbstractBag implements DxListCollection { 13 14 final static long serialVersionUID = 1L; 15 16 protected transient DxListNode start; 17 protected transient DxListNode top; 18 protected transient int itemCount = 0; 19 20 21 23 public DxListBag() { 24 start = new DxListNode(); 25 top = new DxListNode(); 26 start.storeBehind( top ); 27 } 28 29 30 32 public synchronized boolean add( Object obj ) { 33 return addBack( obj ); 34 } 35 36 37 39 public synchronized boolean addFront( Object obj ) { 40 DxListNode node = new DxListNode( obj ); 41 start.storeBehind( node ); 42 itemCount++; 43 return true; 44 } 45 46 47 49 public synchronized boolean addBack( Object obj ) { 50 DxListNode node = new DxListNode( obj ); 51 top.storeInfront( node ); 52 itemCount++; 53 return true; 54 } 55 56 57 59 public DxIterator iterator() { 60 return new DxListIterator( this ); 61 } 62 63 64 66 public int count() { 67 return itemCount; 68 } 69 70 71 73 public boolean isEmpty() { 74 return start.next() == top; 75 } 76 77 78 80 public synchronized void clear() { 81 start = new DxListNode(); 82 top = new DxListNode(); 83 start.storeBehind( top ); 84 itemCount = 0; 85 } 86 87 88 90 public DxListNode head() { 91 return start; 92 } 93 94 95 97 public DxListNode tail() { 98 return top; 99 } 100 101 102 104 public void decCounter() { 105 itemCount--; 106 } 107 108 } 109 | Popular Tags |