/** * 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 iterator the iterator to use, not null * @return a list of the iterator contents * @throws NullPointerException if iterator parameter is null */ public static List toList(Iterator iterator) { return toList(iterator, 10); }
/** * 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 iterator the iterator to use, not null * @return a list of the iterator contents * @throws NullPointerException if iterator parameter is null */ public static List toList(Iterator iterator) { return toList(iterator, 10); }
/** * 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(Iterator iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } List list = toList(iterator, 100); return list.toArray(); }
/** * 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 enumeration the enumeration to traverse, which should not be <code>null</code>. * @throws NullPointerException if the enumeration parameter is <code>null</code>. */ public static List toList(Enumeration 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 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(Iterator iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } List list = toList(iterator, 100); return list.toArray(); }
/** * 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 enumeration the enumeration to traverse, which should not be <code>null</code>. * @throws NullPointerException if the enumeration parameter is <code>null</code>. */ public static List toList(Enumeration 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 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 is null * @throws NullPointerException if arrayClass is null * @throws ClassCastException if the arrayClass is invalid */ public static Object[] toArray(Iterator iterator, Class arrayClass) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (arrayClass == null) { throw new NullPointerException("Array class must not be null"); } List list = toList(iterator, 100); return list.toArray((Object[]) Array.newInstance(arrayClass, list.size())); }
public List<Map<String, Object>> read(String fileName) throws IOException { List<Map<String, Object>> result = IteratorUtils.toList(new CSVIterator(fileName)); return result; }
/** * 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 * @param arrayClass the class of array to create * @return an array of the iterator contents * @throws NullPointerException if iterator parameter is null * @throws NullPointerException if arrayClass is null * @throws ClassCastException if the arrayClass is invalid */ public static Object[] toArray(Iterator iterator, Class arrayClass) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (arrayClass == null) { throw new NullPointerException("Array class must not be null"); } List list = toList(iterator, 100); return list.toArray((Object[]) Array.newInstance(arrayClass, list.size())); }
public void testToList() { List list = new ArrayList(); list.add(new Integer(1)); list.add("Two"); list.add(null); List result = IteratorUtils.toList(list.iterator()); assertEquals(list, result); }
public void testKeyedIterator() { final MultiValueMap map = createTestMap(); final ArrayList actual = new ArrayList(IteratorUtils.toList(map.iterator("one"))); final ArrayList expected = new ArrayList(Arrays.asList(new String[]{"uno", "un"})); assertEquals(expected, actual); }
/** * Resolves all instances of a specified class and add it to the list of default implementations * @param clazz Type of the instance to resolve * @param defaultInstances {@link List} of instances that match the type clazz * @param <T> Type of class passed * @return {@link List} of instance of the specified class. Newly found instances will be added * to the existing contents of defaultInstances */ @SuppressWarnings("unchecked") public static <T> List get(Class<T> clazz, List<T> defaultInstances) { Iterator<T> iterator = ServiceLoader.load(clazz).iterator(); if (defaultInstances != null) { defaultInstances.addAll(IteratorUtils.toList(iterator)); } else { defaultInstances = IteratorUtils.toList(iterator); } return defaultInstances; }
Iterator<HugeTask<Object>> itor; itor = scheduler.findTask(TaskStatus.RUNNING, -1); System.out.println(">>>> running task: " + IteratorUtils.toList(itor));
@Test @Description("Stores an object stream in a variable leaving without modifying the original payload") public void getObjectStreamWithTargetVariable() throws Exception { CoreEvent event = flowRunner("getStreamWithTarget").keepStreamsOpen().withPayload(data).run(); assertThat(event.getVariables().get(MY_STREAM_VAR).getValue(), is(instanceOf(CursorIteratorProvider.class))); assertThat(IteratorUtils.toList(((CursorIteratorProvider) event.getVariables().get(MY_STREAM_VAR).getValue()).openCursor()), equalTo(data)); assertThat(event.getMessage().getPayload().getValue(), is(instanceOf(List.class))); assertThat(event.getMessage().getPayload().getValue(), equalTo(data)); }
@SuppressWarnings("unchecked") public Iterator<String> getSortedKeysIterator(JSONObject object) { List<String> keys = IteratorUtils.toList(object.keys()); Collections.sort(keys); Iterator<String> it = keys.iterator(); return it; }
private List<String> cellsFrom(String line) { line = line.trim(); if (line.startsWith("|")) { line = line.substring(1); } if (line.endsWith("|")) { line = line.substring(0,line.length() - 1); } return toList(Splitter.on("|").trimResults().split(line).iterator()); }
/** * 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 enumeration the enumeration to traverse, which should not be <code>null</code>. * @throws NullPointerException if the enumeration parameter is <code>null</code>. */ public static List toList(Enumeration enumeration) { return IteratorUtils.toList(new EnumerationIterator(enumeration)); }
/** * Returns a List representation of the Job graph. Returned list is an * ArrayList * * @return List<JobStats> */ @SuppressWarnings("unchecked") public List<JobStats> getJobList() { return IteratorUtils.toList(iterator()); }
@SuppressWarnings("unchecked") public static List<Record> listRecords(AnalyticsDataService ads, AnalyticsDataResponse response) throws AnalyticsException { List<Record> result = new ArrayList<Record>(); for (Entry entry : response.getEntries()) { result.addAll(IteratorUtils.toList(ads.readRecords(entry.getRecordStoreName(), entry.getRecordGroup()))); } return result; }
@Override public List<WikidataStatement> getStatements(LocalPage page) throws DaoException { int conceptId = upDao.getUnivPageId(page); if (conceptId < 0) { return new ArrayList<WikidataStatement>(); } WikidataFilter filter = new WikidataFilter.Builder() .withEntityType(WikidataEntity.Type.ITEM) .withEntityId(conceptId) .build(); return IteratorUtils.toList(get(filter).iterator()); }