List of usage examples for com.google.common.collect Maps filterValues
@CheckReturnValue public static <K, V> BiMap<K, V> filterValues(BiMap<K, V> unfiltered, final Predicate<? super V> valuePredicate)
From source file:no.ssb.vtl.script.operations.union.UnionOperation.java
private Set<String> nonAttributeNames(DataStructure dataStructure) { return Maps.filterValues(dataStructure.getRoles(), role -> role != Component.Role.ATTRIBUTE).keySet(); }
From source file:greenapi.core.model.resources.net.NetworkInterfaces.java
/** * Removes a {@link NetworkInterface} that has a given id. * /* w ww . j a v a2 s .c o m*/ * @param id * The id of the {@link NetworkInterface} that must be removed. * @return the {@link NetworkInterface} removed. */ public NetworkInterface remove(String id) { NetworkInterface removed = this.interfaces.remove(id); if (primary != null && primary.equals(removed)) { Map<String, NetworkInterface> primaries = Maps.filterValues(this.interfaces, new Predicate<NetworkInterface>() { @Override public boolean apply(NetworkInterface input) { return input.isPrimary() || input.isActive(); } }); this.primary = (primaries.isEmpty()) ? null : primaries.values().iterator().next(); } return removed; }
From source file:info.magnolia.jcr.node2bean.impl.CollectionPropertyHidingTransformer.java
@Override public void setProperty(TypeMapping mapping, TransformationState state, PropertyTypeDescriptor descriptor, Map<String, Object> values) throws RepositoryException { if (descriptor.getName().equals(collectionName)) { Object bean = state.getCurrentBean(); Map<String, Object> value = Maps.filterValues(values, new Predicate<Object>() { @Override/*from ww w. j a v a 2 s . co m*/ public boolean apply(Object input) { return getPropertyType().getType().isInstance(input); } }); try { if (propertyDescriptor.isMap()) { writeMethod.invoke(bean, value); } else if (propertyDescriptor.isArray()) { Class<?> entryClass = getPropertyType().getType(); Collection<Object> list = new LinkedList<Object>(value.values()); Object[] arr = (Object[]) Array.newInstance(entryClass, list.size()); for (int i = 0; i < arr.length; i++) { arr[i] = Iterables.get(list, i); } writeMethod.invoke(bean, new Object[] { arr }); } else if (propertyDescriptor.isCollection()) { Collection<?> collection = createCollectionFromMap(value, propertyDescriptor.getType().getType()); writeMethod.invoke(bean, collection); } } catch (Exception e) { log.error("Can't call set method " + propertyDescriptor.getWriteMethod(), e); } } else { super.setProperty(mapping, state, descriptor, values); } }
From source file:org.locationtech.geogig.model.internal.RocksdbDAGStore.java
public void putAll(Map<TreeId, DAG> dags) { Map<TreeId, DAG> changed = Maps.filterValues(dags, (d) -> d.isMutated()); changed.forEach((id, dag) -> {/*from w w w .j av a 2 s . c o m*/ try { db.put(column, writeOptions, toKey(id), encode(dag)); } catch (RocksDBException e) { throw Throwables.propagate(e); } }); }
From source file:edu.mit.streamjit.impl.compiler.Schedule.java
private static <T> Schedule<T> schedule(ImmutableSet<T> things, ImmutableSet<ExecutionConstraint<T>> executionConstraints, ImmutableSet<BufferingConstraint<T>> bufferingConstraints, int multiplier, int fireCost, int excessBufferCost) { ILPSolver solver = new ILPSolver(); //There's one variable for each thing, which represents the number of //times it fires. This uses the default bounds. (TODO: perhaps a bound //at 1 if we're steady-state scheduling, maybe by marking things as //must-fire and marking the bottommost thing?) ImmutableMap.Builder<T, ILPSolver.Variable> variablesBuilder = ImmutableMap.builder(); for (T thing : things) variablesBuilder.put(thing, solver.newVariable(thing.toString())); ImmutableMap<T, ILPSolver.Variable> variables = variablesBuilder.build(); for (ExecutionConstraint<T> constraint : executionConstraints) solver.constrainAtLeast(variables.get(constraint.thing).asLinearExpr(1), constraint.minExecutions); HashMap<ILPSolver.Variable, Integer> sumOfConstraints = new HashMap<>(); for (ILPSolver.Variable v : variables.values()) sumOfConstraints.put(v, 0);/*w w w .j a va 2 s . c om*/ for (BufferingConstraint<T> constraint : bufferingConstraints) { ILPSolver.Variable upstreamVar = variables.get(constraint.upstream), downstreamVar = variables.get(constraint.downstream); ILPSolver.LinearExpr expr = upstreamVar.asLinearExpr(constraint.pushRate).minus(constraint.popRate, downstreamVar); switch (constraint.condition) { case LESS_THAN_EQUAL: solver.constrainAtMost(expr, constraint.bufferDelta); break; case EQUAL: solver.constrainEquals(expr, constraint.bufferDelta); break; case GREATER_THAN_EQUAL: solver.constrainAtLeast(expr, constraint.bufferDelta); break; default: throw new AssertionError(constraint.condition); } sumOfConstraints.put(upstreamVar, sumOfConstraints.get(upstreamVar) + constraint.pushRate); sumOfConstraints.put(downstreamVar, sumOfConstraints.get(downstreamVar) - constraint.popRate); } //Add a special constraint to ensure at least one filter fires. //TODO: in init schedules we might not always need this... Iterator<ILPSolver.Variable> variablesIter = variables.values().iterator(); ILPSolver.LinearExpr totalFirings = variablesIter.next().asLinearExpr(1); while (variablesIter.hasNext()) totalFirings = totalFirings.plus(1, variablesIter.next()); solver.constrainAtLeast(totalFirings, 1); for (ILPSolver.Variable v : variables.values()) sumOfConstraints.put(v, sumOfConstraints.get(v) * excessBufferCost + fireCost); ILPSolver.ObjectiveFunction objFn = solver.minimize( solver.newLinearExpr(Maps.filterValues(sumOfConstraints, Predicates.not(Predicates.equalTo(0))))); try { solver.solve(); } catch (SolverException ex) { throw new ScheduleException(ex); } ImmutableMap.Builder<T, Integer> schedule = ImmutableMap.builder(); for (Map.Entry<T, ILPSolver.Variable> e : variables.entrySet()) schedule.put(e.getKey(), e.getValue().value() * multiplier); return new Schedule<>(things, bufferingConstraints, schedule.build()); }
From source file:org.apache.activemq.broker.jmx.DestinationsViewFilter.java
/** * Filter, sort and page results.//from ww w.j a v a 2s . c o m * * Returns JSON map with resulting destination views and total number of matched destinations * * @param page - defines result page to be returned * @param pageSize - defines page size to be used * @throws IOException */ String filter(int page, int pageSize) throws IOException { ObjectMapper mapper = new ObjectMapper(); destinations = Maps.filterValues(destinations, getPredicate()); Map<ObjectName, DestinationView> pagedDestinations = getPagedDestinations(page, pageSize); Map<String, Object> result = new HashMap<String, Object>(); result.put("data", pagedDestinations); result.put("count", destinations.size()); StringWriter writer = new StringWriter(); mapper.writeValue(writer, result); return writer.toString(); }
From source file:co.cask.cdap.app.runtime.AbstractProgramRuntimeService.java
@Override public synchronized Map<RunId, RuntimeInfo> list(final Id.Program program) { return Maps.filterValues(list(program.getType()), new Predicate<RuntimeInfo>() { @Override//from w w w. ja v a 2 s . c o m public boolean apply(RuntimeInfo info) { return info.getProgramId().equals(program); } }); }
From source file:com.isotrol.impe3.pms.core.obj.DevicePagesObject.java
/** * Returns the portal error pages, except the default. * @return The portal error pages, except the default. *//*from w w w.j ava 2 s.c om*/ public final Map<UUID, PageObject> getErrorPages() { final Map<UUID, PageObject> errorPages = byClass(PageClass.ERROR); final PageObject defaultError = getByKey(PageMapKey.error()); if (defaultError == null) { return errorPages; } return Maps.filterValues(errorPages, not(equalTo(defaultError))); }
From source file:com.google.errorprone.refaster.PlaceholderMethod.java
/** * Parameters which must be referenced in any tree matched to this placeholder. *//*w w w. j ava 2 s .com*/ Set<UVariableDecl> requiredParameters() { return Maps.filterValues(annotatedParameters(), new Predicate<ImmutableClassToInstanceMap<Annotation>>() { @Override public boolean apply(ImmutableClassToInstanceMap<Annotation> annotations) { return !annotations.containsKey(MayOptionallyUse.class); } }).keySet(); }
From source file:org.eclipse.sw360.licenseinfo.outputGenerators.OutputGenerator.java
@NotNull protected SortedMap<String, Set<String>> getSortedAcknowledgements( Map<String, LicenseInfoParsingResult> sortedLicenseInfos) { Map<String, Set<String>> acknowledgements = Maps.filterValues( Maps.transformValues(sortedLicenseInfos, pr -> Optional.ofNullable(pr.getLicenseInfo()) .map(LicenseInfo::getLicenseNamesWithTexts).filter(Objects::nonNull) .map(s -> s.stream().map(LicenseNameWithText::getAcknowledgements).filter(Objects::nonNull) .collect(Collectors.toSet())) .orElse(Collections.emptySet())), set -> !set.isEmpty());//from w w w. j a va 2 s. c om return sortStringKeyedMap(acknowledgements); }