/** * 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); }
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); }
/** * Gets an array based on an iterator. * <p> * As the wrapped Iterator is traversed, an ArrayList of its values is * created. At the end, this is converted to an array. * * @param iterator the iterator to use, not null * @return an array of the iterator contents * @throws NullPointerException if iterator parameter is null */ public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); }
/** * Return the list of keys. * * @return the list of keys. */ public List<String> getKeys() { return IteratorUtils.toList(configuration.getKeys()); }
/** * Gets a new list with the contents of the provided iterable. * * @param <E> the element type * @param iterable the iterable to use, may be null * @return a list of the iterator contents */ public static <E> List<E> toList(final Iterable<E> iterable) { return IteratorUtils.toList(emptyIteratorIfNull(iterable)); }
@Override public Iterator<E> iterator() { final List<E> list = (iterable instanceof List<?>) ? (List<E>) iterable : IteratorUtils.toList(iterable.iterator()); return new ReverseListIterator<>(list); } };
/** * Creates a list based on an enumeration. * * <p>As the enumeration is traversed, an ArrayList of its values is * created. The new list is returned.</p> * * @param <E> the element type * @param enumeration the enumeration to traverse, which should not be <code>null</code>. * @return a list containing all elements of the given enumeration * @throws NullPointerException if the enumeration parameter is <code>null</code>. */ public static <E> List<E> toList(final Enumeration<? extends E> enumeration) { return IteratorUtils.toList(new EnumerationIterator<>(enumeration)); }
/** * Gets an array based on an iterator. * <p> * As the wrapped Iterator is traversed, an ArrayList of its values is * created. At the end, this is converted to an array. * * @param <E> the element type * @param iterator the iterator to use, not null * @param arrayClass the class of array to create * @return an array of the iterator contents * @throws NullPointerException if iterator parameter or arrayClass is null * @throws ArrayStoreException if the arrayClass is invalid */ public static <E> E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (arrayClass == null) { throw new NullPointerException("Array class must not be null"); } final List<E> list = toList(iterator, 100); @SuppressWarnings("unchecked") final E[] array = (E[]) Array.newInstance(arrayClass, list.size()); return list.toArray(array); }
/** * Get the list of the keys contained in the configuration that match the * specified prefix. For instance, if the configuration contains the * following keys:<br> * {@code swagger2markup.extensions.folder1, swagger2markup.extensions.folder2, swagger2markup.folder3},<br> * an invocation of {@code getKeys("swagger2markup.extensions");}<br> * will return the key below:<br> * {@code swagger2markup.extensions.folder1, swagger2markup.extensions.folder2}.<br> * Note that the prefix itself is included in the result set if there is a * matching key. The exact behavior - how the prefix is actually * interpreted - depends on a concrete implementation. * * @param prefix The prefix to test against. * @return the list of keys. */ public List<String> getKeys(String prefix) { return IteratorUtils.toList(configuration.getKeys(prefix)); }
@Override public void start() { List<FrameworkFactory> frameworkFactories = IteratorUtils.toList(ServiceLoader.load(FrameworkFactory.class).iterator()); if (frameworkFactories.size() != 1) { throw new RuntimeException("One OSGi framework expected. Got " + frameworkFactories.size() + ": " + frameworkFactories); } try { framework = getFelixFramework(frameworkFactories); framework.start(); registerInternalServices(framework.getBundleContext()); } catch (BundleException e) { throw new RuntimeException("Failed to initialize OSGi framework", e); } }
return IteratorUtils.toList(iterator, totalSize);
/** * 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); }
public boolean equals( Object object) { IConjunct other = object != null && object instanceof IConjunct ? (IConjunct) object : null; return other != null && disjuncts_.equals( new HashSet<IDisjunct>( IteratorUtils.toList( other.getDisjuncts()))); }
/** * Returns an iterator that visits the elements of the given sequence in a random order. */ public <T> Iterator<T> reorder( Iterator<T> sequence) { return reorder( IteratorUtils.toList( sequence)).iterator(); }
public static <T> List<T> unmodifiableListCopy(Iterable<T> iterable) { if (iterable == null) return Collections.emptyList(); return ListUtils.unmodifiableList(IteratorUtils.toList(iterable.iterator())); }
/** * Return all keys contained in this chain. */ @Override public Iterator<String> keys() { Set<String> keys = new HashSet<>(); for (Iterator<Messages> messagesIterator = chain.iterator(); messagesIterator.hasNext(); ) { Messages messages = messagesIterator.next(); List<String> current = IteratorUtils.toList(messages.keys()); keys.addAll(current); } return keys.iterator(); }
@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 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)); }
public ParseResult<T> parseWithResult(ParserMetadata<T> parserConfig, CommandMetadata commandMetadata, Iterable<GlobalRestriction> restrictions, Iterable<String> args) { if (args == null) throw new NullPointerException("args is null"); ParseState<T> state = tryParse(parserConfig, commandMetadata, args); validate(state, IteratorUtils.toList(restrictions.iterator())); return state.getParserConfiguration().getErrorHandler().finished(state); }
@Test public void listenerCanBeRegisteredAndUnregistered() throws Exception { // GIVEN // WHEN WorkspaceEventListenerRegistration.Handle handle = WorkspaceEventListenerRegistration.observe(RepositoryConstants.WEBSITE, "/foo", listener).register(); // THEN assertThat(1, is(IteratorUtils.toList(observationManager.getRegisteredEventListeners()).size())); // WHEN handle.unregister(); // THEN assertThat(0, is(IteratorUtils.toList(observationManager.getRegisteredEventListeners()).size())); }