/** takes collection of Object[] fieldValues *or* another StructSet */ public StructSet(Collection c, StructType structType) { this.contents = new ObjectOpenCustomHashSet(c, new ObjectArrayHashingStrategy()); if (structType == null) { throw new IllegalArgumentException( "structType must not be null"); } this.structType = structType; }
public static boolean in(Object objectValue, ObjectOpenCustomHashSet<?> set) { return set.contains(objectValue); }
/** * For internal use. Just add the Object[] values for a struct with same type */ @Override public boolean addFieldValues(Object[] fieldValues) { return this.contents.add(fieldValues); }
@Override public int size() { return this.contents.size(); }
/** Remove the field values from a struct of the correct type */ @Override public boolean removeFieldValues(Object[] fieldValues) { return this.contents.remove(fieldValues); }
@Override public boolean addAll(Collection<? extends K> c) { // The resulting collection will be at least c.size() big if (f <= .5) ensureCapacity(c.size()); // The resulting collection will be sized for c.size() elements else tryCapacity(size() + c.size()); // The resulting collection will be tentatively sized for size() + c.size() // elements return super.addAll(c); } @Override
/** Returns an iterator over the fieldValues Object[] instances */ @Override public Iterator fieldValuesIterator() { return this.contents.iterator(); }
/** * Creates a new hash set copying a given collection. * * @param c * a {@link Collection} to be copied into the new hash set. * @param f * the load factor. * @param strategy * the strategy. */ public ObjectOpenCustomHashSet(final Collection<? extends K> c, final float f, final Strategy<? super K> strategy) { this(c.size(), f, strategy); addAll(c); } /**
@Override public Object[] toArray() { Struct[] structs = new Struct[this.contents.size()]; int i = 0; for (Iterator iter = this.iterator(); iter.hasNext();) { structs[i++] = (Struct) iter.next(); } return structs; }
@Override public boolean remove(Object o) { if (o instanceof Struct) { o = ((Struct) o).getFieldValues(); } return this.contents.remove(o); }
/** Returns an iterator over the fieldValues Object[] instances */ public Iterator fieldValuesIterator() { return this.contents.iterator(); }
public boolean addAll(Collection c) { if (c instanceof StructSet) { return addAll((StructSet) c); } return this.contents.addAll(c); }
public StructSet(int initialCapacity, float loadFactor, StructType structType) { this.contents = new ObjectOpenCustomHashSet(initialCapacity, loadFactor, new ObjectArrayHashingStrategy()); if (structType == null) { throw new IllegalArgumentException( "structType must not be null"); } this.structType = structType; }
/** * Does this set contain a Struct of the correct type with the specified values? */ @Override public boolean containsFieldValues(Object[] fieldValues) { return this.contents.contains(fieldValues); }
public boolean addAll(StructSet ss) { boolean modified = false; if (!this.structType.equals(ss.structType)) { throw new IllegalArgumentException( "types do not match"); } for (Iterator itr = ss.fieldValuesIterator(); itr.hasNext();) { Object[] vals = (Object[]) itr.next(); if (this.contents.add(vals)) { modified = true; } } return modified; }
@Override public int size() { return this.contents.size(); }
public boolean removeAll(StructSet ss) { boolean modified = false; if (!this.structType.equals(ss.structType)) { return false; // nothing // modified } for (Iterator itr = ss.fieldValuesIterator(); itr.hasNext();) { Object[] vals = (Object[]) itr.next(); if (this.contents.remove(vals)) { modified = true; } } return modified; }
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { final ObjectIterator<K> i = iterator(); s.defaultWriteObject(); for (int j = size; j-- != 0;) s.writeObject(i.next()); } @SuppressWarnings("unchecked")
/** * Creates a new hash set copying a given type-specific collection. * * @param c * a type-specific collection to be copied into the new hash set. * @param f * the load factor. * @param strategy * the strategy. */ public ObjectOpenCustomHashSet(final ObjectCollection<? extends K> c, final float f, Strategy<? super K> strategy) { this(c.size(), f, strategy); addAll(c); } /**
public StructSet(int initialCapacity, StructType structType) { this.contents = new ObjectOpenCustomHashSet(initialCapacity, new ObjectArrayHashingStrategy()); if (structType == null) { throw new IllegalArgumentException( "structType must not be null"); } this.structType = structType; }