1 24 package org.ofbiz.base.util.collections; 25 26 import java.util.AbstractSet ; 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 import java.util.LinkedList ; 30 import java.util.List ; 31 32 39 public class OrderedSet extends AbstractSet { 40 41 private List backedList = new LinkedList (); 43 44 49 public OrderedSet() {} 50 51 58 public OrderedSet(Collection c) { 59 Iterator i = c.iterator(); 60 61 while (i.hasNext()) 62 add(i.next()); 63 } 64 65 68 public Iterator iterator() { 69 return backedList.iterator(); 70 } 71 72 75 public int size() { 76 return backedList.size(); 77 } 78 79 82 public boolean add(Object obj) { 83 int index = backedList.indexOf(obj); 84 85 if (index == -1) 86 return backedList.add(obj); 87 else { 88 backedList.set(index, obj); 89 return false; 90 } 91 } 92 } 93 | Popular Tags |