@Test public void testDuplicates() { ResultsBag bag = new ResultsBag(); bag.add("one"); bag.add("two"); assertEquals(2, bag.size()); bag.add("two"); assertEquals(3, bag.size()); assertEquals(1, bag.occurrences("one")); assertEquals(2, bag.occurrences("two")); assertTrue(bag.remove("two")); assertEquals(1, bag.occurrences("two")); assertTrue(bag.remove("one")); assertEquals(0, bag.occurrences("one")); assertTrue(!bag.remove("one")); assertEquals(0, bag.occurrences("one")); }
@Test public void testIterationNullRemoval() { ResultsBag bag = new ResultsBag(); bag.add(null); bag.add(null); bag.add(new Integer(1)); bag.add(new Integer(2)); bag.add(new Integer(2)); assertEquals(5, bag.size()); for (Iterator itr = bag.iterator(); itr.hasNext();) { Object n = itr.next(); if (n == null) { itr.remove(); } } assertEquals(3, bag.size()); assertEquals(0, bag.occurrences(null)); }
@Test public void testSerializingSetViewWithNulls() throws Exception { ResultsBag bag = new ResultsBag(); bag.add(new Integer(4)); bag.add(new Integer(2)); bag.add(new Integer(42)); bag.add(null); bag.add(null); bag.add(null); assertEquals(6, bag.size()); assertEquals(1, bag.occurrences(new Integer(4))); assertEquals(3, bag.occurrences(null)); Set set = bag.asSet(); assertEquals(4, set.size()); assertTrue(set.contains(new Integer(4))); assertTrue(set.contains(null)); ResultsCollectionWrapper w = new ResultsCollectionWrapper(new ObjectTypeImpl(Integer.class), set); HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(w, hdos); DataInputStream in = new DataInputStream(hdos.getInputStream()); SelectResults setCopy = (SelectResults) DataSerializer.readObject(in); assertEquals(4, setCopy.size()); assertTrue(setCopy.contains(new Integer(4))); assertTrue(setCopy.contains(null)); }
assertTrue(!bag.isEmpty()); assertEquals(1, bag.size()); assertEquals(1, bag.occurrences(null)); assertEquals(2, bag.occurrences(null)); assertEquals(1, bag.occurrences(null)); assertTrue(bag.remove(null)); assertEquals(0, bag.occurrences(null)); assertTrue(!bag.remove(null)); assertEquals(0, bag.occurrences(null));
int occurrence = bag.occurrences(asList.get(0));
int occurrence = bag.occurrences(asList.get(0));
int occurrence = bag.occurrences(asList.get(0));
fromBag.fromData(dis); assertEquals(toBag.size(), fromBag.size()); assertEquals(toBag.occurrences(wrap(null, toBag.getCollectionType().getElementType())), fromBag.occurrences(wrap(null, fromBag.getCollectionType().getElementType()))); assertEquals(toBag.occurrences(wrap("one", toBag.getCollectionType().getElementType())), fromBag.occurrences(wrap("one", fromBag.getCollectionType().getElementType()))); assertEquals(toBag.occurrences(wrap("two", toBag.getCollectionType().getElementType())), fromBag.occurrences(wrap("two", fromBag.getCollectionType().getElementType()))); assertEquals(toBag.occurrences(wrap("three", toBag.getCollectionType().getElementType())), fromBag.occurrences(wrap("three", fromBag.getCollectionType().getElementType()))); assertEquals(toBag.occurrences(wrap("four", toBag.getCollectionType().getElementType())), fromBag.occurrences(wrap("four", fromBag.getCollectionType().getElementType()))); assertEquals(toBag.occurrences(wrap(null, toBag.getCollectionType().getElementType())), fromBag.occurrences(wrap(null, fromBag.getCollectionType().getElementType()))); assertFalse(toBag.asList().retainAll(fromBag.asList()));
@Test public void testOccurrence() { ResultsBag bag = getBagObject(String.class); bag.add(wrap(null, bag.getCollectionType().getElementType())); bag.add(wrap(null, bag.getCollectionType().getElementType())); bag.add(wrap("one", bag.getCollectionType().getElementType())); bag.add(wrap("two", bag.getCollectionType().getElementType())); bag.add(wrap("two", bag.getCollectionType().getElementType())); bag.add(wrap("three", bag.getCollectionType().getElementType())); bag.add(wrap("three", bag.getCollectionType().getElementType())); bag.add(wrap("three", bag.getCollectionType().getElementType())); bag.add(wrap("four", bag.getCollectionType().getElementType())); bag.add(wrap("four", bag.getCollectionType().getElementType())); bag.add(wrap("four", bag.getCollectionType().getElementType())); bag.add(wrap("four", bag.getCollectionType().getElementType())); assertEquals(12, bag.size()); bag.applyLimit(6); int total = bag.occurrences(wrap(null, bag.getCollectionType().getElementType())); total += bag.occurrences(wrap("one", bag.getCollectionType().getElementType())); total += bag.occurrences(wrap("two", bag.getCollectionType().getElementType())); total += bag.occurrences(wrap("three", bag.getCollectionType().getElementType())); total += bag.occurrences(wrap("four", bag.getCollectionType().getElementType())); assertEquals(6, total); }
bag.remove(wrap(null, bag.getCollectionType().getElementType())); assertEquals(11, bag.size()); assertEquals(1, bag.occurrences(wrap(null, bag.getCollectionType().getElementType()))); bag.remove(wrap("three", bag.getCollectionType().getElementType())); assertEquals(10, bag.size()); assertEquals(2, bag.occurrences(wrap("three", bag.getCollectionType().getElementType()))); Integer intg = new Integer(i); if (temp.contains(wrap(intg, bag.getCollectionType().getElementType()))) { int occurrence = bag.occurrences(wrap(intg, bag.getCollectionType().getElementType())); assertTrue(bag.remove(wrap(intg, bag.getCollectionType().getElementType()))); assertEquals(--occurrence, bag.occurrences(wrap(intg, bag.getCollectionType().getElementType()))); --currSize; assertEquals(currSize, bag.size()); } else { assertEquals(0, bag.occurrences(wrap(intg, bag.getCollectionType().getElementType()))); int occurrence = bag.occurrences(wrap(null, bag.getCollectionType().getElementType())); assertTrue(bag.remove(wrap(null, bag.getCollectionType().getElementType()))); assertEquals(--occurrence, bag.occurrences(wrap(null, bag.getCollectionType().getElementType()))); --currSize; assertEquals(currSize, bag.size());