List of usage examples for com.google.common.collect Maps filterEntries
@CheckReturnValue public static <K, V> BiMap<K, V> filterEntries(BiMap<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate)
From source file:com.arpnetworking.tsdcore.tailer.FilePositionStore.java
private void flush() { // Age out old state final DateTime now = DateTime.now(); final DateTime oldest = now.minus(_retention); final long sizeBefore = _state.size(); Maps.filterEntries(_state, new Predicate<Map.Entry<String, Descriptor>>() { @Override//from ww w .ja v a 2 s .c o m public boolean apply(final Map.Entry<String, Descriptor> entry) { return oldest.isBefore(entry.getValue().getLastUpdated()); } }); final long sizeAfter = _state.size(); if (sizeBefore != sizeAfter) { LOGGER.debug(String.format("Removed old entries from file position store; sizeBefore=%d, sizeAfter=%d", Long.valueOf(sizeBefore), Long.valueOf(sizeAfter))); } // Persist the state to disk try { OBJECT_MAPPER.writeValue(_file, _state); LOGGER.debug(String.format("Persisted file position state to disk; size=%d, file=%s", Long.valueOf(_state.size()), _file)); } catch (final IOException ioe) { Throwables.propagate(ioe); } finally { _lastFlush = now; } }
From source file:org.apache.druid.sql.avatica.DruidConnection.java
public DruidStatement createStatement() { final int statementId = statementCounter.incrementAndGet(); synchronized (statements) { if (statements.containsKey(statementId)) { // Will only happen if statementCounter rolls over before old statements are cleaned up. If this // ever happens then something fishy is going on, because we shouldn't have billions of statements. throw new ISE("Uh oh, too many statements"); }/*www . j a va 2 s . c om*/ if (statements.size() >= maxStatements) { throw new ISE("Too many open statements, limit is[%,d]", maxStatements); } // remove sensitive fields from the context, only the connection's context needs to have authentication // credentials Map<String, Object> sanitizedContext = Maps.newHashMap(); sanitizedContext = Maps.filterEntries(context, new Predicate<Map.Entry<String, Object>>() { @Override public boolean apply(@Nullable Map.Entry<String, Object> input) { return !SENSITIVE_CONTEXT_FIELDS.contains(input.getKey()); } }); final DruidStatement statement = new DruidStatement(connectionId, statementId, ImmutableSortedMap.copyOf(sanitizedContext), () -> { // onClose function for the statement synchronized (statements) { log.debug("Connection[%s] closed statement[%s].", connectionId, statementId); statements.remove(statementId); } }); statements.put(statementId, statement); log.debug("Connection[%s] opened statement[%s].", connectionId, statementId); return statement; } }
From source file:com.facebook.buck.util.cache.impl.LoadingCacheFileHashCache.java
@Override public void invalidateWithParents(Path path) { Iterable<Path> pathsToInvalidate = Maps.filterEntries(loadingCache.asMap(), entry -> { Objects.requireNonNull(entry); // If we get a invalidation for a file which is a prefix of our current one, this // means the invalidation is of a symlink which points to a directory (since // events // won't be triggered for directories). We don't fully support symlinks, however, // we do support some limited flows that use them to point to read-only storage // (e.g. the `project.read_only_paths`). For these limited flows to work // correctly, // we invalidate. if (entry.getKey().startsWith(path)) { return true; }//from ww w. j ava 2 s . c o m // Otherwise, we want to invalidate the entry if the path matches it. We also // invalidate any directories that contain this entry, so use the following // comparison to capture both these scenarios. return path.startsWith(entry.getKey()); }).keySet(); for (Path pathToInvalidate : pathsToInvalidate) { invalidate(pathToInvalidate); } }
From source file:org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder.java
private Map<ConfigElement.PathIdentifier, Object> getLocalSubset(Map<ConfigElement.PathIdentifier, Object> m) { return Maps.filterEntries(m, entry -> { assert entry.getKey().element.isOption(); return ((ConfigOption) entry.getKey().element).isLocal(); });/*from w w w .ja va2s. c o m*/ }
From source file:org.apache.beam.runners.spark.aggregators.metrics.WithNamedAggregatorsSupport.java
private Map<String, Gauge> extractGauges(final MetricRegistry metricRegistry, final MetricFilter filter) { // find the AggregatorMetric metrics from within all currently registered metrics final Optional<Map<String, Gauge>> gauges = FluentIterable.from(metricRegistry.getMetrics().entrySet()) .firstMatch(isAggregatorMetric()).transform(toGauges()); return gauges.isPresent() ? Maps.filterEntries(gauges.get(), matches(filter)) : ImmutableMap.<String, Gauge>of(); }
From source file:org.opentestsystem.authoring.testauth.validation.PerformanceLevelValidator.java
@Override public void validate(final Object obj, final Errors errors) { // execute JSR-303 validations (annotations) this.jsrValidator.validate(obj, errors); final PerformanceLevel performanceLevel = (PerformanceLevel) obj; if (!errors.hasErrors() && !CollectionUtils.isEmpty(performanceLevel.getPerformanceLevelValues())) { // custom validation for each performanceLevelValue for (int i = 0; i < performanceLevel.getPerformanceLevelValues().size(); i++) { final PerformanceLevelValue nextValue = performanceLevel.getPerformanceLevelValues().get(i); try { errors.pushNestedPath(PERFORMANCE_LEVEL_VALUES + "[" + i + "]"); ValidationUtils.invokeValidator(this.performanceLevelValueValidator, nextValue, errors); if (nextValue.getLevel() > performanceLevel.getPerformanceLevelValues().size()) { rejectValue(errors, "level", getErrorMessageRoot() + PERFORMANCE_LEVEL_VALUES_POSITION + MSG_INVALID, nextValue.getLevel()); }/*from w w w . j av a 2 s.com*/ } finally { errors.popNestedPath(); } } // check for duplicate performanceLevelValue level final Map<String, Collection<PerformanceLevelValue>> duplicateLevels = Maps .filterEntries( Multimaps.index(performanceLevel.getPerformanceLevelValues(), PERFORMANCE_LEVEL_TO_POSITION_TRANSFORMER).asMap(), PERFORMANCE_LEVEL_DUPLICATE_FILTER); if (!duplicateLevels.isEmpty()) { rejectValue(errors, PERFORMANCE_LEVEL_VALUES, getErrorMessageRoot() + PERFORMANCE_LEVEL_VALUES_POSITION + MSG_DUPLICATES, duplicateLevels.keySet().toString()); } else if (!errors.hasErrors()) { performanceLevel.setPerformanceLevelValues( Lists.newArrayList(Ordering.natural().onResultOf(PERFORMANCE_LEVEL_TO_POSITION_TRANSFORMER) .sortedCopy(performanceLevel.getPerformanceLevelValues()))); } } }
From source file:org.obm.push.calendar.ConsistencyEventChangesLogger.java
@VisibleForTesting NotConsistentEventChanges build(EventChanges changes) { Map<EventObmId, Collection<Object>> allEntries = buildAllEntriesMultimap(changes); Map<EventObmId, Collection<Object>> duplicatesEntries = Maps.filterEntries(allEntries, alLeastTwoElements());//from w ww .j av a 2 s .c o m return new NotConsistentEventChanges(duplicatesEntries); }
From source file:org.apache.beam.runners.spark.metrics.WithMetricsSupport.java
private Map<String, Gauge> extractGauges(final MetricRegistry metricRegistry, final MetricFilter filter) { Map<String, Gauge> gauges = new HashMap<>(); // find the AggregatorMetric metrics from within all currently registered metrics final Optional<Map<String, Gauge>> aggregatorMetrics = FluentIterable .from(metricRegistry.getMetrics().entrySet()).firstMatch(isAggregatorMetric()) .transform(aggregatorMetricToGauges()); // find the SparkBeamMetric metrics from within all currently registered metrics final Optional<Map<String, Gauge>> beamMetrics = FluentIterable.from(metricRegistry.getMetrics().entrySet()) .firstMatch(isSparkBeamMetric()).transform(beamMetricToGauges()); if (aggregatorMetrics.isPresent()) { gauges.putAll(Maps.filterEntries(aggregatorMetrics.get(), matches(filter))); }/* w w w . j ava 2s . c o m*/ if (beamMetrics.isPresent()) { gauges.putAll(Maps.filterEntries(beamMetrics.get(), matches(filter))); } return gauges; }
From source file:org.gradle.api.tasks.scala.AbstractScalaCompile.java
protected HashMap<File, File> filterForClasspath(Map<File, File> analysisMap, Iterable<File> classpath) { final Set<File> classpathLookup = Sets.newHashSet(classpath); return Maps.newHashMap(Maps.filterEntries(analysisMap, new Predicate<Map.Entry<File, File>>() { public boolean apply(Map.Entry<File, File> entry) { return classpathLookup.contains(entry.getKey()); }//ww w . ja v a 2 s .c o m })); }
From source file:org.opentestsystem.authoring.testauth.validation.ComputationRuleValidator.java
@Override public void validate(final Object obj, final Errors errors) { // execute JSR-303 validations (annotations) this.jsrValidator.validate(obj, errors); final ComputationRule computationRule = (ComputationRule) obj; if (!CollectionUtils.isEmpty(computationRule.getParameters())) { // custom validation for each computationRuleParameter for (int i = 0; i < computationRule.getParameters().size(); i++) { final ComputationRuleParameter nextParameter = computationRule.getParameters().get(i); try { errors.pushNestedPath(PARAMETERS + "[" + i + "]"); ValidationUtils.invokeValidator(this.computationRuleParameterValidator, nextParameter, errors); if (nextParameter.getPosition() > computationRule.getParameters().size()) { rejectValue(errors, "position", getErrorMessageRoot() + PARAMETERS_POSITION + MSG_INVALID, nextParameter.getPosition()); }//from w w w .j a v a 2 s. c o m } finally { errors.popNestedPath(); } } // check for duplicate parameter names final Map<String, Collection<ComputationRuleParameter>> duplicates = Maps.filterEntries( Multimaps.index(computationRule.getParameters(), PARAMETER_TO_NAME_TRANSFORMER).asMap(), PARAMETER_DUPLICATE_FILTER); if (!duplicates.isEmpty()) { rejectValue(errors, PARAMETERS, getErrorMessageRoot() + PARAMETERS_NAME + MSG_DUPLICATES, duplicates.keySet().toString()); } // check for duplicate parameter position final Map<String, Collection<ComputationRuleParameter>> duplicatePositions = Maps.filterEntries( Multimaps.index(computationRule.getParameters(), PARAMETER_TO_POSITION_TRANSFORMER).asMap(), PARAMETER_DUPLICATE_FILTER); if (!duplicatePositions.isEmpty()) { rejectValue(errors, PARAMETERS, getErrorMessageRoot() + PARAMETERS_POSITION + MSG_DUPLICATES, duplicatePositions.keySet().toString()); } else if (!errors.hasErrors()) { computationRule.setParameters( Lists.newArrayList(Ordering.natural().onResultOf(PARAMETER_TO_POSITION_TRANSFORMER) .sortedCopy(computationRule.getParameters()))); } } if (StringUtils.trimToNull(computationRule.getVersion()) != null) { final String[] parts = computationRule.getVersion().split("\\."); if (parts.length != 2) { // not the right number version parts // should be 2 parts like "1.0" rejectValue(errors, "version", "version.format", new Object() { }); return; } if (NumberUtils.toInt(parts[0], -1) < 1 || parts[1].length() > 1 || (NumberUtils.toInt(parts[1], -1) < 0 || NumberUtils.toInt(parts[1], -1) > 9)) { //major is a negative number or some other character rejectValue(errors, "version", "version.majorminor.format", new Object() { }); } } }