/** Returns an iterator over the fieldValues Object[] instances */ @Override public Iterator fieldValuesIterator() { return super.iterator(); }
@Test public void testIteration() { ResultsBag bag = new ResultsBag(); bag.add(new Integer(1)); bag.add(new Integer(2)); bag.add(new Integer(2)); int numOnes = 0; int numTwos = 0; Integer one = new Integer(1); Integer two = new Integer(2); for (Iterator itr = bag.iterator(); itr.hasNext();) { Object n = itr.next(); if (one.equals(n)) { numOnes++; } else if (two.equals(n)) { numTwos++; } else { fail(n + " did not equal 1 or 2"); } } assertEquals(1, numOnes); assertEquals(2, numTwos); }
@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 testIterationRemoval() { ResultsBag bag = new ResultsBag(); bag.add(new Integer(1)); bag.add(new Integer(2)); bag.add(new Integer(2)); bag.add(new Integer(3)); bag.add(new Integer(3)); bag.add(new Integer(4)); assertEquals(6, bag.size()); Iterator itr = bag.iterator(); for (int i = 0; i < 3; i++) { itr.next(); itr.remove(); } assertEquals(3, bag.size()); for (int i = 0; i < 3; i++) { itr.next(); itr.remove(); } assertTrue(bag.isEmpty()); assertEquals(0, bag.size()); }
Iterator itr = bag.iterator(); for (int i = 0; i < (4 - occurrence); ++i) { itr.next();
Iterator itr = bag.iterator(); for (int i = 0; i < occurrence; ++i) { itr.next();
bag.add(wrap(new Integer(5), bag.getCollectionType().getElementType())); bag.applyLimit(8); Iterator itr = bag.iterator(); if (!(bag instanceof StructBag)) { assertTrue(bag.iterator() instanceof Bag.LimitBagIterator); itr = bag.iterator(); while (i < 5) { itr.next(); itr = bag.iterator(); while (i < 3) { assertEquals(asList.get(i + 5), itr.next());
Integer one = new Integer(1); Integer two = new Integer(2); for (Iterator itr = bag.iterator(); itr.hasNext();) { Object n = itr.next(); if (one.equals(n)) {
@Test public void testIteratorType() { ResultsBag bag = getBagObject(String.class); 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())); assertTrue(bag.iterator() instanceof Bag.BagIterator); bag.applyLimit(6); assertTrue(bag.iterator() instanceof Bag.BagIterator); bag = getBagObject(String.class); 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())); bag.applyLimit(6); if (!(bag instanceof StructBag)) { assertTrue(bag.iterator() instanceof Bag.LimitBagIterator); } }