1 package xdoclet.modules.ojb; 2 3 17 18 import java.util.Iterator ; 19 import java.util.StringTokenizer ; 20 21 26 public class CommaListIterator implements Iterator 27 { 28 29 private StringTokenizer _list; 30 31 private String _current = ""; 32 33 38 public CommaListIterator(String list) 39 { 40 _list = new StringTokenizer (list == null ? "" : list, ","); 41 } 42 43 46 public void remove() 47 { 48 throw new UnsupportedOperationException (); 49 } 50 51 54 public boolean hasNext() 55 { 56 while (_list.hasMoreTokens() && (_current.length() == 0)) 57 { 58 _current = _list.nextToken(); 59 } 60 return (_current.length() > 0); 61 } 62 63 66 public Object next() 67 { 68 return getNext(); 69 } 70 71 76 public String getNext() 77 { 78 String result = _current; 79 80 _current = ""; 81 return result.trim(); 82 } 83 84 92 public boolean contains(String element) 93 { 94 while (hasNext()) 95 { 96 if (element.equals(getNext())) 97 { 98 return true; 99 } 100 } 101 return false; 102 } 103 104 113 public boolean equals(Object obj) 114 { 115 if (!(obj instanceof CommaListIterator)) 116 { 117 return false; 118 } 119 120 CommaListIterator otherIt = (CommaListIterator)obj; 121 122 while (hasNext() || otherIt.hasNext()) 123 { 124 if (!hasNext() || !otherIt.hasNext()) 125 { 126 return false; 127 } 128 if (!getNext().equals(otherIt.getNext())) 129 { 130 return false; 131 } 132 } 133 return true; 134 } 135 136 143 public static boolean sameLists(String list1, String list2) 144 { 145 return new CommaListIterator(list1).equals(new CommaListIterator(list2)); 146 } 147 } 148 | Popular Tags |