/** * Gets a list based on an iterator. * <p> * As the wrapped Iterator is traversed, an ArrayList of its values is * created. At the end, the list is returned. * * @param <E> the element type * @param iterator the iterator to use, not null * @return a list of the iterator contents * @throws NullPointerException if iterator parameter is null */ public static <E> List<E> toList(final Iterator<? extends E> iterator) { return toList(iterator, 10); }
@Override public Enumeration<? extends ZipArchiveEntry> getEntries() { return IteratorUtils.asEnumeration(zipEntries.values().iterator()); }
@Override public Iterator<O> iterator() { return IteratorUtils.transformedIterator(iterable.iterator(), transformer); } };
@Override public ZipArchiveEntry getEntry(final String path) { String normalizedPath = path.replace('\\', '/'); final ZipArchiveEntry entry = zipArchive.getEntry(normalizedPath); if (entry != null) { return entry; } // the opc spec allows case-insensitive filename matching (see #49609) for (final ZipArchiveEntry ze : asIterable(asIterator(zipArchive.getEntries()))) { if (normalizedPath.equalsIgnoreCase(ze.getName().replace('\\','/'))) { return ze; } } return null; } }
return emptyIterator(); return singletonIterator(obj);
/** * Returns the members of the given set of input variables not bound by the given test case. */ private List<VarDef> getVarsRemaining( Iterator<VarDef> vars, final TestCaseDef testCase) { return IteratorUtils.toList( IteratorUtils.filteredIterator( vars, var -> testCase.getBinding( var) == null)); }
/** * Asserts use of all tuples contained in the given test case. */ public void used( final TestCaseDef testCase) { // Note: must accumulate tuples into a separate list to avoid ConcurrentModificationException when updating used/unused membership. List<Tuple> usedTuples = IteratorUtils.toList( IteratorUtils.filteredIterator( IteratorUtils.chainedIterator( unused_.iterator(), used_.iterator()), tuple -> testCase.usesTuple( tuple))); for( Tuple tuple : usedTuples) { used( tuple); } }
/** * Returns the set of once-only tuple definitions for this combiner. */ private Set<Tuple> getOnceTupleDefs( final List<VarDef> combinedVars) { try { return new HashSet<Tuple>( IteratorUtils.toList( IteratorUtils.transformedIterator( getOnceTuples(), tupleRef -> toTuple( combinedVars, tupleRef)))); } catch( Exception e) { throw new IllegalStateException( "Invalid once-only tuple definition", e); } }
/** * Writes a set of measurements to HBase. * * @param iterator The measurements to write. * @return The number of measurements written to HBase. */ @Override public Iterator<Integer> call(Iterator<ProfileMeasurementAdapter> iterator) throws Exception { int count = 0; LOG.debug("About to write profile measurement(s) to HBase"); // do not open hbase connection, if nothing to write List<ProfileMeasurementAdapter> measurements = IteratorUtils.toList(iterator); if(measurements.size() > 0) { // open an HBase connection Configuration config = HBaseConfiguration.create(); try (HBaseClient client = new HBaseClient(tableProvider, config, tableName)) { for (ProfileMeasurementAdapter adapter : measurements) { ProfileMeasurement m = adapter.toProfileMeasurement(); client.addMutation(rowKeyBuilder.rowKey(m), columnBuilder.columns(m), durability); } count = client.mutate(); } catch (IOException e) { LOG.error("Unable to open connection to HBase", e); throw new RuntimeException(e); } } LOG.debug("{} profile measurement(s) written to HBase", count); return IteratorUtils.singletonIterator(count); }
@SuppressWarnings("unchecked") public CliBuilder<C> withCommands(Class<? extends C> command, Class<? extends C>... moreCommands) { this.defaultCommandGroupCommands.add(command); this.defaultCommandGroupCommands .addAll(ListUtils.unmodifiableList(IteratorUtils.toList(IteratorUtils.arrayIterator(moreCommands)))); return this; }
/** * Returns the set of input variables to be excluded from this combination. */ public String[] getExcluded() { return IteratorUtils.toArray( IteratorUtils.transformedIterator( excludedVars_.iterator(), VarNamePattern::toString), String.class); }
IteratorUtils.transformedIterator( IteratorUtils.filteredIterator( getPropertyProviders( unsatisfied).iterator(), binding -> testCase.isCompatible( binding));
protected void setupIterator(JsonReader reader) { JsonParser parser = new JsonParser(); JsonElement root = parser.parse(reader); if (root.isJsonArray()) { // Currently positioned to read a set of objects jsonIterator = root.getAsJsonArray().iterator(); } else { // Currently positioned to read a single object jsonIterator = IteratorUtils.singletonIterator(root); } }
/** * Creates a new FluentIterable of the single provided element. * <p> * The returned iterable's iterator does not support {@code remove()}. * * @param <T> the element type * @param singleton the singleton element * @return a new FluentIterable containing the singleton */ public static <T> FluentIterable<T> of(final T singleton) { return of(IteratorUtils.asIterable(new SingletonIterator<>(singleton, false))); }
/** * Iterate over the keys. */ @Override public Iterator<String> keys() { ResourceBundle bundle = this.getBundle(); if (bundle != null) { return IteratorUtils.asIterator(bundle.getKeys()); } return IteratorUtils.EMPTY_ITERATOR; } }
IteratorUtils.toList( IteratorUtils.filteredIterator( new VarDefIterator( inputDef), this::isUncombined));
/** * Returns the set of input variables to be included in this combination. */ public String[] getIncluded() { return IteratorUtils.toArray( IteratorUtils.transformedIterator( includedVars_.iterator(), VarNamePattern::toString), String.class); }
@Override public ZipArchiveEntry getEntry(final String path) { String normalizedPath = path.replace('\\', '/'); final ZipArchiveEntry entry = zipArchive.getEntry(normalizedPath); if (entry != null) { return entry; } // the opc spec allows case-insensitive filename matching (see #49609) for (final ZipArchiveEntry ze : asIterable(asIterator(zipArchive.getEntries()))) { if (normalizedPath.equalsIgnoreCase(ze.getName().replace('\\','/'))) { return ze; } } return null; } }
private void setupIterator(JsonReader reader) { JsonParser parser = new JsonParser(); JsonElement root = parser.parse(reader); if (root.isJsonArray()) { // Currently positioned to read a set of objects jsonIterator = root.getAsJsonArray().iterator(); } else { // Currently positioned to read a single object jsonIterator = IteratorUtils.singletonIterator(root); } }
public Swagger2MarkupExtensionRegistryBuilder() { List<SwaggerModelExtension> swaggerModelExtensions = toList(load(SwaggerModelExtension.class).iterator()); List<OverviewDocumentExtension> overviewDocumentExtensions = toList(load(OverviewDocumentExtension.class).iterator()); List<DefinitionsDocumentExtension> definitionsDocumentExtensions = toList(load(DefinitionsDocumentExtension.class).iterator()); List<PathsDocumentExtension> pathsDocumentExtensions = toList(load(PathsDocumentExtension.class).iterator()); List<SecurityDocumentExtension> securityDocumentExtensions = toList(load(SecurityDocumentExtension.class).iterator()); context = new Context( swaggerModelExtensions, overviewDocumentExtensions, definitionsDocumentExtensions, pathsDocumentExtensions, securityDocumentExtensions); }