public void testArrayIterator() { Object[] objArray = {"a", "b", "c"}; ResettableIterator iterator = IteratorUtils.arrayIterator(objArray); assertTrue(iterator.next().equals("a")); assertTrue(iterator.next().equals("b")); iterator = IteratorUtils.arrayIterator(new Integer(0)); fail("Expecting IllegalArgumentException"); } catch (IllegalArgumentException ex) { iterator = IteratorUtils.arrayIterator(null); fail("Expecting NullPointerException"); } catch (NullPointerException ex) { iterator = IteratorUtils.arrayIterator(objArray, 1); assertTrue(iterator.next().equals("b")); iterator = IteratorUtils.arrayIterator(objArray, -1); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { iterator = IteratorUtils.arrayIterator(objArray, 3); assertTrue(!iterator.hasNext()); iterator.reset(); iterator = IteratorUtils.arrayIterator(objArray, 4); fail("Expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ex) { iterator = IteratorUtils.arrayIterator(objArray, 2, 3);
@SuppressWarnings("unchecked") private void run(IndentWriter writer, JadeModel model, Object result, JadeTemplate template) { if (result instanceof Iterable<?>) { runIterator(((Iterable<?>) result).iterator(), model, writer, template); } else if (result.getClass().isArray()) { Iterator<?> iterator = IteratorUtils.arrayIterator(result); runIterator(iterator, model, writer, template); } else if (result instanceof Map) { runMap((Map<Object, Object>) result, model, writer, template); } }
protected final Iterator getIterator(Object literal) { if (literal instanceof Collection) { return ((Collection) literal).iterator(); } else if (literal instanceof Iterator) { return (Iterator) literal; } else if (literal instanceof Enumeration) { return IteratorUtils.asIterator((Enumeration) literal); } else if (literal instanceof Object[]) { return IteratorUtils.arrayIterator((Object[]) literal); } else { throw new ClassCastException("Could not convert literal value to iterator!"); } }
@SuppressWarnings("unchecked") private void run(IndentWriter writer, JadeModel model, Object result, JadeTemplate template) { if (result instanceof Iterable<?>) { runIterator(((Iterable<?>) result).iterator(), model, writer, template); } else if (result.getClass().isArray()) { Iterator<?> iterator = IteratorUtils.arrayIterator(result); runIterator(iterator, model, writer, template); } else if (result instanceof Map) { runMap((Map<Object, Object>) result, model, writer, template); } }
/** * Returns an iterator over parameter sets. Each element returned from the iterator is * a java.util.Map. */ public Iterator parametersIterator() { return (parameters == null || parameters.length == 0) ? IteratorUtils .emptyIterator() : IteratorUtils.transformedIterator(IteratorUtils .arrayIterator(parameters), nullMapTransformer); }
/** * Returns an iterator over parameter sets. Each element returned from the * iterator is a java.util.Map. */ @SuppressWarnings("unchecked") public Iterator<Map<String, ?>> parametersIterator() { return (parameters == null || parameters.length == 0) ? IteratorUtils.emptyIterator() : IteratorUtils .transformedIterator(IteratorUtils.arrayIterator(parameters), nullMapTransformer); }
/** * Returns an iterator over parameter sets. Each element returned from the iterator is * a java.util.Map. */ public Iterator parametersIterator() { return (parameters == null || parameters.length == 0) ? IteratorUtils .emptyIterator() : IteratorUtils.transformedIterator(IteratorUtils .arrayIterator(parameters), nullMapTransformer); }
private final void appendList(Expression listExpr, DbAttribute paramDesc) throws IOException { Iterator<?> it; Object list = listExpr.getOperand(0); if (list instanceof List) { it = ((List<?>) list).iterator(); } else if (list instanceof Object[]) { it = IteratorUtils.arrayIterator((Object[]) list); } else { String className = (list != null) ? list.getClass().getName() : "<null>"; throw new IllegalArgumentException("Unsupported type for the list expressions: " + className); } // process first element outside the loop // (unroll loop to avoid condition checking if (it.hasNext()) { appendLiteral(it.next(), paramDesc, listExpr); } else { return; } while (it.hasNext()) { out.append(", "); appendLiteral(it.next(), paramDesc, listExpr); } }
private final void appendList(Expression listExpr, DbAttribute paramDesc) { Iterator it = null; Object list = listExpr.getOperand(0); if (list instanceof List) { it = ((List) list).iterator(); } else if (list instanceof Object[]) { it = IteratorUtils.arrayIterator((Object[]) list); } else { String className = (list != null) ? list.getClass().getName() : "<null>"; throw new IllegalArgumentException( "Unsupported type for the list expressions: " + className); } // process first element outside the loop // (unroll loop to avoid condition checking if (it.hasNext()) appendLiteral(qualBuf, it.next(), paramDesc, listExpr); else return; while (it.hasNext()) { qualBuf.append(", "); appendLiteral(qualBuf, it.next(), paramDesc, listExpr); } }
private final void appendList(Expression listExpr, DbAttribute paramDesc) { Iterator it = null; Object list = listExpr.getOperand(0); if (list instanceof List) { it = ((List) list).iterator(); } else if (list instanceof Object[]) { it = IteratorUtils.arrayIterator((Object[]) list); } else { String className = (list != null) ? list.getClass().getName() : "<null>"; throw new IllegalArgumentException( "Unsupported type for the list expressions: " + className); } // process first element outside the loop // (unroll loop to avoid condition checking if (it.hasNext()) appendLiteral(qualBuf, it.next(), paramDesc, listExpr); else return; while (it.hasNext()) { qualBuf.append(", "); appendLiteral(qualBuf, it.next(), paramDesc, listExpr); } }
/** * Returns the value as an {@link Iterator}. If the value is itself an * iterator, an instance of {@link Iterable}, or is an array, the items in * the value will be returned as the list. Otherwise, if the value is not * <code>null</code>, it will be returned as the only item in the * iterator. If the value is <code>null</code>, an empty iterator is * returned. * * @param value The value to convert. * @return The iterator. */ @API public static Iterator<?> asIterator( Object value ) { if ( value instanceof Iterator ) { return (Iterator<?>) value; } else if ( value instanceof Iterable<?> ) { return ( (Iterable<?>) value ).iterator(); } else if ( value instanceof Enumeration ) { return IteratorUtils.asIterator( (Enumeration<?>) value ); } else if ( value != null ) { if ( value.getClass().isArray() ) { return IteratorUtils.arrayIterator( (Object[]) value ); } else { return Arrays.asList( value ).iterator(); } } else { return IteratorUtils.emptyIterator(); } }
/** * Returns an iterator over a snapshot copy of this group's collected events., optionally sorted by arrival order. If you need * to iterate over the group and e.g. remove select events, do so via {@link #removeEvent(CoreEvent)}. If you need to do so * atomically in order to prevent e.g. concurrent reception/aggregation of the group during iteration, wrap the iteration in a * synchronized block on the group instance. * * @return an iterator over collected {@link CoreEvent}s. * @throws ObjectStoreException */ @SuppressWarnings("unchecked") public Iterator<CoreEvent> iterator(boolean sortByArrival) throws ObjectStoreException { synchronized (this) { if (eventsObjectStore.allKeys(eventsPartitionKey).isEmpty()) { return IteratorUtils.emptyIterator(); } else { return IteratorUtils.arrayIterator(this.toArray(sortByArrival)); } } }
/** * Returns an iterator over a snapshot copy of this group's collected events., * optionally sorted by arrival order. If * you need to iterate over the group and e.g. remove select events, do so via * {@link #removeEvent(MuleEvent)}. If you need to do so atomically in order to * prevent e.g. concurrent reception/aggregation of the group during iteration, * wrap the iteration in a synchronized block on the group instance. * * @return an iterator over collected {@link MuleEvent}s. * @throws ObjectStoreException */ @SuppressWarnings("unchecked") public Iterator<MuleEvent> iterator(boolean sortByArrival) throws ObjectStoreException { synchronized (this) { if (eventsObjectStore.allKeys(eventsPartitionKey).isEmpty()) { return IteratorUtils.emptyIterator(); } else { return IteratorUtils.arrayIterator(this.toArray(sortByArrival)); } } }
Iterator<File> children = IteratorUtils.filteredIterator(IteratorUtils.arrayIterator(files), new Predicate() { @Override public boolean evaluate(Object object) {
if (files != null) { Arrays.sort(files, FileNameComparator.INSTANCE); childIterators.add(IteratorUtils.transformedIterator(IteratorUtils.arrayIterator(files), new Transformer() { @Override public Object transform(final Object input) {