1 package org.apache.ojb.odmg.collections; 2 3 17 18 import org.apache.ojb.broker.PBKey; 19 import org.odmg.DBag; 20 21 import java.util.Iterator ; 22 23 26 public class DBagImpl extends DListImpl implements org.odmg.DBag 27 { 28 private static final long serialVersionUID = -4937635522392824190L; 29 30 public DBagImpl() 31 { 32 super(); 33 } 34 35 38 public DBagImpl(PBKey key) 39 { 40 super(key); 41 } 42 43 53 public DBag difference(DBag otherBag) 54 { 55 DBagImpl result = new DBagImpl(getPBKey()); 56 Iterator iter = this.iterator(); 57 while (iter.hasNext()) 58 { 59 Object candidate = iter.next(); 60 if (!otherBag.contains(candidate)) 61 { 62 result.add(candidate); 63 } 64 } 65 return result; 66 } 67 68 78 public DBag intersection(DBag otherBag) 79 { 80 DBagImpl result = new DBagImpl(getPBKey()); 81 Iterator iter = otherBag.iterator(); 82 while (iter.hasNext()) 83 { 84 Object candidate = iter.next(); 85 if (this.contains(candidate)) 86 { 87 result.add(candidate); 88 } 89 } 90 return result; 91 } 92 93 99 public int occurrences(Object obj) 100 { 101 int count = 0; 102 for (int i = 0; i < this.size(); i++) 103 { 104 if ((obj == null) ? this.get(i) == null : this.get(i).equals(obj)) 105 { 106 count++; 107 } 108 } 109 return count; 110 } 111 112 122 public DBag union(DBag otherBag) 123 { 124 return (DBagImpl) concat((DBagImpl) otherBag); 125 } 126 } 127 | Popular Tags |