List of usage examples for java.util Iterator forEachRemaining
default void forEachRemaining(Consumer<? super E> action)
From source file:Main.java
public static void main(String[] args) { // Create a list of strings List<String> names = new ArrayList<>(); names.add("A"); names.add("B"); names.add("C"); Iterator<String> nameIterator = names.iterator(); nameIterator.forEachRemaining(System.out::println); }
From source file:Main.java
/** * Converts the given iterator to collection created via the provided {@link Supplier}. * <p>/*ww w .j a v a 2 s . c o m*/ * Example use: <code>List<String> list = CollectionUtils.toCollection(iterator, LinkedList::new);</code> * * @param <T> * the generic type * @param <C> * the generic type * @param iterator * the iterator * @param newInstance * the new instance * @return the c */ public static <T, C extends Collection<T>> C toCollection(Iterator<T> iterator, Supplier<C> newInstance) { Objects.requireNonNull(iterator, "The iterator is required"); Objects.requireNonNull(newInstance, "New Instance supplier is required"); C list = newInstance.get(); iterator.forEachRemaining(list::add); return list; }
From source file:io.gravitee.policy.oauth2.Oauth2Policy.java
static boolean hasRequiredScopes(JsonNode oauthResponseNode, List<String> requiredScopes, String scopeSeparator) {/*ww w. ja v a2 s . c o m*/ if (requiredScopes == null) { return true; } JsonNode scopesNode = oauthResponseNode.path(OAUTH_PAYLOAD_SCOPE_NODE); List<String> scopes; if (scopesNode instanceof ArrayNode) { Iterator<JsonNode> scopeIterator = scopesNode.elements(); scopes = new ArrayList<>(scopesNode.size()); List<String> finalScopes = scopes; scopeIterator.forEachRemaining(jsonNode -> finalScopes.add(jsonNode.asText())); } else { scopes = Arrays.asList(scopesNode.asText().split(scopeSeparator)); } return scopes.containsAll(requiredScopes); }
From source file:com.vmware.loginsightapi.Configuration.java
/** * Builds the Configuration object from the properties file (apache commons * properties file format). <br>/*from ww w . j av a2 s.c om*/ * The values provided in the config file will be overwritten environment * variables (if present) * * List of the properties <br> * loginsight.host = host name <br> * loginsight.port = port number <br> * loginsight.user = User name <br> * loginsight.password = password <br> * loginsight.ingestion.agentId = agentId <br> * loginsight.connection.scheme = http protocol scheme <br> * loginsight.ingestion.port = Ingestion port number <br> * * @param configFileName * Name of the config file to read * @return Newly created Configuration object */ public static Configuration buildFromConfig(String configFileName) { try { List<FileLocationStrategy> subs = Arrays.asList(new ProvidedURLLocationStrategy(), new FileSystemLocationStrategy(), new ClasspathLocationStrategy()); FileLocationStrategy strategy = new CombinedLocationStrategy(subs); FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>( PropertiesConfiguration.class).configure( new Parameters().fileBased().setLocationStrategy(strategy).setFileName(configFileName)); PropertiesConfiguration propConfig = builder.getConfiguration(); Map<String, String> propMap = new HashMap<String, String>(); Iterator<String> keys = propConfig.getKeys(); keys.forEachRemaining(key -> { logger.info(key + ":" + propConfig.getString(key)); propMap.put(key, propConfig.getString(key)); }); Configuration config = Configuration.buildConfig(propMap); config.loadFromEnv(); return config; } catch (ConfigurationException e1) { throw new RuntimeException("Unable to load config", e1); } }
From source file:org.apache.geode.geospatial.grid.IndexHAMaintenance.java
@Override public void afterBucketRemoved(int bucketId, Iterable<?> keys) { Iterator<?> it = keys.iterator(); it.forEachRemaining(key -> geospatialIndex.remove(key)); }
From source file:io.gravitee.gateway.service.ratelimit.RateLimitPoller.java
@Override public void run() { try {/*from w ww . ja v a2s.c o m*/ LOGGER.debug("Refresh rate-limits from repository"); Iterator<RateLimit> rateLimitIterator = delegateRateLimitRepository.findAsyncAfter(lastCheck); rateLimitIterator.forEachRemaining(rateLimit -> { String[] parts = KeySplitter.split(rateLimit.getKey()); // Handle the rate-limit only if it's not a "local" rate-limit // (ie. not stored by this gateway instance) if (!node.id().equals(parts[0])) { String rateLimitKey = parts[1]; long hits = rateLimit.getCounter(); RateLimit oldRateLimit = aggregateCacheRateLimitRepository.get(rateLimit.getKey()); if (oldRateLimit != null) { // Already known, what is the diff ? // Is it a new value for the same rate-limit key ? if (rateLimit.getCreatedAt() > oldRateLimit.getCreatedAt()) { hits = rateLimit.getCounter(); } else { hits = rateLimit.getCounter() - oldRateLimit.getCounter(); } } updateAggregateRateLimit(rateLimitKey, rateLimit, hits); } }); lastCheck = System.currentTimeMillis(); } catch (Exception ex) { LOGGER.error("Unable to retrieve latest values of rate-limit from repository", ex); } }
From source file:io.mindmaps.graql.internal.analytics.CountMapReduce.java
@Override public Map<Serializable, Long> generateFinalResult(final Iterator<KeyValue<Serializable, Long>> keyValues) { final Map<Serializable, Long> count = new HashMap<>(); keyValues.forEachRemaining(pair -> count.put(pair.getKey(), pair.getValue())); return count; }
From source file:org.openmhealth.shim.withings.mapper.WithingsIntradayStepCountDataPointMapper.java
/** * Creates a map that contains only the entries from the intraday activities dictionary that have step counts. * * @param fieldsIterator an iterator of map entries containing the key-value pairs related to each intraday * activity/* w w w . j a v a 2s.co m*/ * event * @return a map with keys as the start datetime (in unix epoch seconds) of each activity event, and values as * the information related to the activity event starting at the key datetime */ private Map<Long, JsonNode> getNodesWithSteps(Iterator<Map.Entry<String, JsonNode>> fieldsIterator) { HashMap<Long, JsonNode> nodesWithSteps = Maps.newHashMap(); fieldsIterator.forEachRemaining(n -> addNodeIfHasSteps(nodesWithSteps, n)); return nodesWithSteps; }
From source file:com.thinkbiganalytics.metadata.cache.AlertsCache.java
protected List<AlertSummaryGrouped> fetchUnhandledAlerts() { List<AlertSummary> alerts = new ArrayList<>(); AlertCriteria criteria = alertProvider.criteria(); new AlertCriteriaInput.Builder().state(Alert.State.UNHANDLED).asServiceAccount(true) .onlyIfChangesDetected(true).applyToCriteria(criteria); Iterator<? extends AlertSummary> itr = alertProvider.getAlertsSummary(criteria); if (itr.hasNext()) { itr.forEachRemaining(alerts::add); List<AlertSummaryGrouped> latestAlerts = new ArrayList<>(alertsModel.groupAlertSummaries(alerts)); return latestAlerts; } else {//ww w . j a va2 s .c om return Collections.emptyList(); } }
From source file:org.openmhealth.shim.withings.mapper.WithingsIntradayCaloriesBurnedDataPointMapper.java
/** * Creates a hashmap that contains only the entries from the intraday activities dictionary that have calories * burned counts.//from w w w. ja v a 2 s .c om * * @param fieldsIterator an iterator of map entries containing the key-value pairs related to each intraday * activity event * @return a hashmap with keys as the start datetime (in unix epoch seconds) of each activity event, and values as * the information related to the activity event starting at the key datetime */ private Map<Long, JsonNode> getNodesWithCalories(Iterator<Map.Entry<String, JsonNode>> fieldsIterator) { HashMap<Long, JsonNode> nodesWithCalories = Maps.newHashMap(); fieldsIterator.forEachRemaining(n -> addNodesIfHasCalories(nodesWithCalories, n)); return nodesWithCalories; }