/** 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()); }
/** * 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); } } }
localResults, objectChangedMarker, true); boolean elementGotAdded = isStruct ? ((StructSet) this.cumulativeResults).addFieldValues((Object[]) obj) : this.cumulativeResults.add(obj); occurrence = elementGotAdded ? 1 : 0;
@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()); } }