@Override public Set asSet() { return new StructSet(this); }
@Override public boolean retainAll(Collection c) { if (c instanceof StructSet) { return retainAll((StructSet) c); } return this.contents.retainAll(c); }
public boolean retainAll(StructSet ss) { if (!this.structType.equals(ss.structType)) { if (isEmpty()) { return false; // nothing modified } else { clear(); return true; // nothing retained in receiver collection } } boolean changed = false; int size = size(); Iterator it; it = fieldValuesIterator(); while (size-- > 0) { Object[] vals = (Object[]) it.next(); if (!ss.containsFieldValues(vals)) { it.remove(); changed = true; } } return changed; }
@Test public void testIntersectionAndRetainAll() { String names[] = {"p", "pos"}; ObjectType types[] = {TypeUtils.OBJECT_TYPE, TypeUtils.OBJECT_TYPE}; StructTypeImpl sType = new StructTypeImpl(names, types); StructSet set1 = new StructSet(sType); Portfolio ptf = new Portfolio(0); Iterator pIter = ptf.positions.values().iterator(); while (pIter.hasNext()) { Object arr[] = {ptf, pIter.next()}; set1.addFieldValues(arr); } StructSet set2 = new StructSet(sType); pIter = ptf.positions.values().iterator(); while (pIter.hasNext()) { Object arr[] = {ptf, pIter.next()}; set2.addFieldValues(arr); } assertEquals(2, set1.size()); assertEquals(2, set2.size()); // tests that retainAll does not modify set1 assertTrue(!set1.retainAll(set2)); assertEquals(2, set1.size()); assertEquals(2, set2.size()); SelectResults sr = QueryUtils.intersection(set1, set2, null); assertEquals(2, sr.size()); } }
if (isStruct) { StructType stype = (StructType) elementType; this.cumulativeResults = new StructSet(stype); } else { this.cumulativeResults = new ResultsSet(elementType); localResults, objectChangedMarker, true); boolean elementGotAdded = isStruct ? ((StructSet) this.cumulativeResults).addFieldValues((Object[]) obj) : this.cumulativeResults.add(obj); occurrence = elementGotAdded ? 1 : 0;
/** Add a Struct */ @Override public boolean add(Object obj) { if (!(obj instanceof StructImpl)) { throw new IllegalArgumentException( "This set only accepts StructImpl"); } StructImpl s = (StructImpl) obj; if (!s.getStructType().equals(this.structType)) { throw new IllegalArgumentException( String.format("obj does not have the same StructType: required: %s , actual: %s", new Object[] {this.structType, s.getStructType()})); } return addFieldValues(s.getFieldValues()); }
/** Returns an Iterator over the Structs in this set */ @Override public ObjectIterator iterator() { return new StructIterator(fieldValuesIterator()); }
/** Does this set contain specified struct? */ @Override public boolean contains(Object obj) { if (!(obj instanceof Struct)) { return false; } Struct s = (Struct) obj; if (!this.structType.equals(StructTypeImpl.typeFromStruct(s))) { return false; } return containsFieldValues(s.getFieldValues()); }
@Override public int occurrences(Object element) { return contains(element) ? 1 : 0; }
@Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { this.contents = new ObjectOpenCustomHashSet(new ObjectArrayHashingStrategy()); int size = in.readInt(); this.structType = (StructTypeImpl) DataSerializer.readObject(in); for (int j = size; j > 0; j--) { this.add(DataSerializer.readObject(in)); } }
/** * Creates a StructSet directly from a StructBag; (internal use) * * @since GemFire 5.1 */ StructSet(StructBag bag) { this.contents = new ObjectOpenCustomHashSet(new ObjectArrayHashingStrategy()); this.structType = (StructType) bag.elementType; if (bag.hasLimitIterator) { // Asif: Since the number of unique keys which // will be returned by Bag with limit in place // cannot be more than the size of the bag ( i.e // the limit) , we can safely assume HashMap size // to equal to bag's size Iterator itr = bag.fieldValuesIterator(); while (itr.hasNext()) { addFieldValues((Object[]) itr.next()); } } else { Set keys = bag.map.keySet(); for (Object key : keys) { addFieldValues((Object[]) key); } } }
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; }
public boolean retainAll(StructSet ss) { if (!this.structType.equals(ss.structType)) { if (isEmpty()) { return false; // nothing modified } else { clear(); return true; // nothing retained in receiver collection } } boolean changed = false; int size = size(); Iterator it; it = fieldValuesIterator(); while (size-- > 0) { Object[] val = (Object[]) it.next(); // if (!ss.containsFieldValues(vals)) { if (!ss.containsFieldValues(val)) { it.remove(); changed = true; } } return changed; }
public static SelectResults createStructCollection(boolean distinct, StructType elementType, ExecutionContext context) { return distinct ? new StructSet(elementType) : new StructBag(elementType, context.getCachePerfStats()); }
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; }
public static SelectResults createStructCollection(ExecutionContext context, StructType elementType) { return context.isDistinct() ? new StructSet(elementType) : new StructBag(elementType, context.getCachePerfStats()); }
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();) { if (this.addFieldValues((Object[]) itr.next())) { modified = true; } } return modified; }
fieldTypes[i] = iter.getElementType(); emptySet = context.isDistinct() ? new StructSet(new StructTypeImpl(fieldNames, fieldTypes)) : new StructBag(0, new StructTypeImpl(fieldNames, fieldTypes), context.getCachePerfStats());