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:org.graylog2.restclient.models.api.results.MessageResult.java
public Map<String, Object> getFilteredFields() { // return a _view_ of the fields map, do not make a copy, because subsequent manipulation would get lost! return Maps.filterEntries(getFields(), new Predicate<Map.Entry<String, Object>>() { @Override/*from w w w . j a v a 2s . c om*/ public boolean apply(@Nullable Map.Entry<String, Object> input) { return input != null && !HIDDEN_FIELDS.contains(input.getKey()); } }); }
From source file:com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator.java
@Override public void delete(final Predicate<SkyKey> deletePredicate) { valuesToDelete.addAll(//from ww w. j av a2 s. c o m Maps.filterEntries(graph.getAllValues(), new Predicate<Entry<SkyKey, ? extends NodeEntry>>() { @Override public boolean apply(Entry<SkyKey, ? extends NodeEntry> input) { Preconditions.checkNotNull(input.getKey(), "Null SkyKey in entry: %s", input); return input.getValue().isDirty() || deletePredicate.apply(input.getKey()); } }).keySet()); }
From source file:com.eucalyptus.util.async.Futures.java
public static <T> Map<T, Future<T>> waitAll(Map<T, Future<T>> futures) { Predicate<Map.Entry<T, Future<T>>> func = waitForResults(); Map<T, Future<T>> res = Maps.filterEntries(futures, func); return res;//from w ww .j a v a 2 s .com }
From source file:net.conquiris.api.index.IndexInfo.java
/** * Creates a new index info object from a string map. Reserved properties are extracted with * default values provided if needed. Invalid user properties are filtered out. * @param documents Number of documents. Must be >= 0. * @param data Commit data./*from ww w. j av a 2 s . co m*/ * @return The created object. */ public static IndexInfo fromMap(int documents, Map<String, String> data) { if (data == null || data.isEmpty()) { return of(null, null, documents, 0L, 0L, ImmutableMap.<String, String>of()); } return of(data.get(CHECKPOINT), data.get(TARGET_CHECKPOINT), documents, safe2Long(data.get(TIMESTAMP)), safe2Long(data.get(SEQUENCE)), Maps.filterEntries(data, isUserProperty())); }
From source file:org.opentestsystem.authoring.testauth.validation.ScoringRuleValidator.java
@Override public void validate(final Object obj, final Errors errors) { // execute JSR-303 validations (annotations) this.jsrValidator.validate(obj, errors); final ScoringRule scoringRule = (ScoringRule) obj; // parameterDataMap can only be evaluated if corresponding ComputationRule is passed along if (StringUtils.isNotBlank(scoringRule.getComputationRuleId()) && scoringRule.getComputationRule() != null) { validateFileUploads(errors, scoringRule); if (!CollectionUtils.isEmpty(scoringRule.getParameters())) { // check for duplicate parameter names final Map<String, Collection<ScoringRuleParameter>> duplicates = Maps.filterEntries( Multimaps.index(scoringRule.getParameters(), RULE_PARAMETER_TO_NAME_TRANSFORMER).asMap(), PARAMETER_DUPLICATE_FILTER); if (!duplicates.isEmpty()) { rejectValue(errors, PARAMETERS, getErrorMessageRoot() + PARAMETERS + MSG_PARAMETER_NAME + MSG_DUPLICATES, duplicates.keySet().toString()); }/*from w w w .j a va 2 s .co m*/ for (int i = 0; i < scoringRule.getParameters().size(); i++) { final ScoringRuleParameter scoringRuleParameter = scoringRule.getParameters().get(i); try { errors.pushNestedPath(PARAMETERS + "[" + i + "]"); final ComputationRuleParameter computationRuleParameter = Iterables .find(scoringRule.getComputationRule().getParameters(), FUNCTION_PARAMETER_FINDER .getInstance(scoringRuleParameter.getComputationRuleParameterName())); if (computationRuleParameter == null) { rejectValue(errors, PARAMETER_NAME, getErrorMessageRoot() + PARAMETERS + MSG_PARAMETER_NAME + MSG_NOT_FOUND, scoringRuleParameter.getComputationRuleParameterName()); } else { // evaluate every value within the rule parameter to ensure it adheres to the constraints of the ComputationRuleParameter ValidationUtils.invokeValidator(this.scoringRuleParameterValidator, scoringRuleParameter, errors, computationRuleParameter); } } catch (final NoSuchElementException e) { rejectValue(errors, PARAMETER_NAME, getErrorMessageRoot() + PARAMETERS + MSG_PARAMETER_NAME + MSG_NOT_FOUND, scoringRuleParameter.getComputationRuleParameterName()); } finally { errors.popNestedPath(); } } for (final ComputationRuleParameter computationRuleParameter : scoringRule.getComputationRule() .getParameters()) { if (!Iterables.any(scoringRule.getParameters(), RULE_PARAMETER_FINDER.getInstance(computationRuleParameter.getParameterName()))) { rejectValue(errors, PARAMETERS, getErrorMessageRoot() + PARAMETERS + MSG_PARAMETER_NAME + MSG_MISSING, computationRuleParameter.getParameterName()); } } } } }
From source file:org.opentestsystem.authoring.testauth.validation.ItemSelectionAlgorithmValidator.java
@Override public void validate(final Object obj, final Errors errors) { // execute JSR-303 validations (annotations) this.jsrValidator.validate(obj, errors); final ItemSelectionAlgorithm algorithm = (ItemSelectionAlgorithm) obj; if (algorithm.getParameters() != null) { // custom validation for each itemSelectionAlgorithmParameter for (int i = 0; i < algorithm.getParameters().size(); i++) { final ItemSelectionAlgorithmParameter nextParameter = algorithm.getParameters().get(i); try { errors.pushNestedPath(PARAMETERS_FIELD + "[" + i + "]"); ValidationUtils.invokeValidator(this.itemSelectionAlgorithmParameterValidator, nextParameter, errors);/*from ww w. jav a2s .c om*/ if (nextParameter.getPosition() > algorithm.getParameters().size()) { rejectValue(errors, "position", getErrorMessageRoot() + PARAMETERS_POSITION_FIELD + MSG_INVALID, nextParameter.getPosition()); } } finally { errors.popNestedPath(); } } // check if parameters have duplicate names final Map<String, Collection<ItemSelectionAlgorithmParameter>> duplicates = Maps.filterEntries( Multimaps.index(algorithm.getParameters(), ITEM_SELECTION_ALGORITHM_PARAMETER_TO_NAME_TRANSFORMER).asMap(), ITEM_SELECTION_ALGORITHM_PARAMETER_DUPLICATE_FILTER); if (!duplicates.isEmpty()) { rejectValue(errors, PARAMETERS_FIELD, getErrorMessageRoot() + PARAMETERS_NAME_FIELD + MSG_DUPLICATES, duplicates.keySet().toString()); } // check if parameters have duplicate position final Map<String, Collection<ItemSelectionAlgorithmParameter>> duplicatePositions = Maps.filterEntries( Multimaps.index(algorithm.getParameters(), ITEM_SELECTION_ALGORITHM_PARAMETER_TO_POSITION_TRANSFORMER).asMap(), ITEM_SELECTION_ALGORITHM_PARAMETER_DUPLICATE_FILTER); if (!duplicatePositions.isEmpty()) { rejectValue(errors, PARAMETERS_FIELD, getErrorMessageRoot() + PARAMETERS_POSITION_FIELD + MSG_DUPLICATES, duplicatePositions.keySet().toString()); } } if (StringUtils.trimToNull(algorithm.getVersion()) != null) { String[] parts = algorithm.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() { }); } } if (!errors.hasErrors()) { algorithm.trimParameterValues(); } }
From source file:com.tacitknowledge.flip.servlet.FlipOverrideFilter.java
/** * Moves the features descriptors generated on request parameters to the {@link FeatureDescriptorsMap}. * // ww w . ja v a 2 s. c o m * @param request the request where to extract the request parameters. * @param featureDescriptors the {@link FeatureDescriptorsMap} where to store the {@link FeatureDescriptor} objects. */ private void applyRequestFeaturesToFeatureDescriptorsMap(final ServletRequest request, final FeatureDescriptorsMap featureDescriptors) { final Map<String, FeatureDescriptor> transformedParamMap = Maps.transformEntries(request.getParameterMap(), new RequestParametersTransformer()); final Map<String, FeatureDescriptor> parameterMap = Maps.filterEntries(transformedParamMap, new RequestParametersFilter()); for (final FeatureDescriptor descriptor : parameterMap.values()) { featureDescriptors.put(descriptor.getName(), descriptor); } }
From source file:components.cells.Cells.java
@Override public Map<IPosition, T> filter(final Predicate<Entry<IPosition, T>> predicate) { Preconditions.checkArgument(predicate != null); return Maps.filterEntries(this.get(), predicate); // TODO ? allow predicate on initial symbol }
From source file:org.jpmml.evaluator.ScorecardEvaluator.java
static private ScoreClassificationMap createScoreMap(Number value, Map<String, Double> reasonCodePoints) { ScoreClassificationMap result = new ScoreClassificationMap(value); // Filter out meaningless (ie. negative values) explanations com.google.common.base.Predicate<Map.Entry<String, Double>> predicate = new com.google.common.base.Predicate<Map.Entry<String, Double>>() { @Override//from w w w . j av a 2 s. co m public boolean apply(Map.Entry<String, Double> entry) { return Double.compare(entry.getValue(), 0) >= 0; } }; result.putAll(Maps.filterEntries(reasonCodePoints, predicate)); return result; }
From source file:org.graylog2.inputs.extractors.JsonExtractor.java
private Collection<Entry> parseValue(String key, Object value) { if (value instanceof Boolean) { return Collections.singleton(Entry.create(key, value)); } else if (value instanceof Number) { return Collections.singleton(Entry.create(key, value)); } else if (value instanceof String) { return Collections.singleton(Entry.create(key, value)); } else if (value instanceof Map) { @SuppressWarnings("unchecked") final Map<String, Object> map = (Map<String, Object>) value; final Map<String, Object> withoutNull = Maps.filterEntries(map, REMOVE_NULL_PREDICATE); if (flatten) { final Joiner.MapJoiner joiner = Joiner.on(listSeparator).withKeyValueSeparator(kvSeparator); return Collections.singleton(Entry.create(key, joiner.join(withoutNull))); } else {/*from ww w.j a v a 2 s. c om*/ final List<Entry> result = new ArrayList<>(map.size()); for (Map.Entry<String, Object> entry : map.entrySet()) { result.addAll(parseValue(key + keySeparator + entry.getKey(), entry.getValue())); } return result; } } else if (value instanceof List) { final List values = (List) value; final Joiner joiner = Joiner.on(listSeparator).skipNulls(); return Collections.singleton(Entry.create(key, joiner.join(values))); } else if (value == null) { // Ignore null values so we don't try to create fields for that in the message. return Collections.emptySet(); } else { LOG.debug("Unknown type \"{}\" in key \"{}\"", value.getClass(), key); return Collections.emptySet(); } }