List of usage examples for com.google.common.base Predicates equalTo
public static <T> Predicate<T> equalTo(@Nullable T target)
From source file:com.google.javascript.jscomp.graph.LinkedDirectedGraph.java
/** * DiGraphNode look ups can be expensive for a large graph operation, prefer this * method if you have the DiGraphNode available. */// w w w . j a va 2s. c om public void connectIfNotConnectedInDirection(N srcValue, E edgeValue, N destValue) { LinkedDirectedGraphNode<N, E> src = createDirectedGraphNode(srcValue); LinkedDirectedGraphNode<N, E> dest = createDirectedGraphNode(destValue); if (!this.isConnectedInDirection(src, Predicates.equalTo(edgeValue), dest)) { this.connect(src, edgeValue, dest); } }
From source file:net.automatalib.util.automata.predicates.TransitionPredicates.java
public static <S, I, T> TransitionPredicate<S, I, T> outputIsNot(TransitionOutput<? super T, ?> transOut, Object output) {/*from ww w. jav a2 s . c o m*/ return outputViolates(transOut, Predicates.equalTo(output)); }
From source file:org.apache.brooklyn.core.typereg.RegisteredTypePredicates.java
public static Predicate<RegisteredType> alias(final String alias) { return aliases(CollectionFunctionals.any(Predicates.equalTo(alias))); }
From source file:io.opencensus.stats.StatsTestUtil.java
/** * Asserts that the two sets of {@code DistributionAggregate}s are equivalent, with a given * tolerance. The tolerance is used when comparing the mean and sum of values. The order of the * {@code DistributionAggregate}s has no effect. The expected parameter is last, because it is * likely to be a larger expression./*from w ww .j av a2 s . c o m*/ * * @param tolerance the tolerance used for {@code double} comparison. * @param actual the actual test result. * @param expected the expected value. * @throws AssertionError if the {@code DistributionAggregate}s don't match. */ static void assertDistributionAggregatesEquivalent(double tolerance, Collection<DistributionAggregate> actual, Collection<DistributionAggregate> expected) { Function<DistributionAggregate, List<Tag>> getTagsFunction = new Function<DistributionAggregate, List<Tag>>() { @Override public List<Tag> apply(DistributionAggregate agg) { return agg.getTags(); } }; Iterable<List<Tag>> expectedTags = Iterables.transform(expected, getTagsFunction); Iterable<List<Tag>> actualTags = Iterables.transform(actual, getTagsFunction); Truth.assertThat(actualTags).containsExactlyElementsIn(expectedTags); for (DistributionAggregate expectedAgg : expected) { DistributionAggregate actualAgg = Iterables.find(actual, Predicates.compose(Predicates.equalTo(expectedAgg.getTags()), getTagsFunction)); assertDistributionAggregateValuesEquivalent("DistributionAggregate tags=" + expectedAgg.getTags(), tolerance, expectedAgg, actualAgg); } }
From source file:org.apache.brooklyn.util.collections.CollectionFunctionals.java
public static Predicate<Iterable<?>> sizeEquals(int targetSize) { return Predicates.compose(Predicates.equalTo(targetSize), CollectionFunctionals.sizeFunction()); }
From source file:com.twitter.aurora.scheduler.thrift.aop.AopModule.java
@Override protected void configure() { requireBinding(CapabilityValidator.class); // Layer ordering: // Log -> CapabilityValidator -> FeatureToggle -> StatsExporter -> APIVersion -> // SchedulerThriftInterface // TODO(Sathya): Consider using provider pattern for constructing interceptors to facilitate // unit testing without the creation of Guice injectors. bindThriftDecorator(new LoggingInterceptor()); // Note: it's important that the capability interceptor is only applied to AuroraAdmin.Iface // methods, and does not pick up methods on AuroraSchedulerManager.Iface. MethodInterceptor authInterceptor = new UserCapabilityInterceptor(); requestInjection(authInterceptor);/*from www . j av a2 s .c om*/ bindInterceptor(THRIFT_IFACE_MATCHER, GuiceUtils.interfaceMatcher(AuroraAdmin.Iface.class, true), authInterceptor); install(new PrivateModule() { @Override protected void configure() { // Ensure that the provided methods exist on the decorated interface. List<Method> methods = ImmutableList.copyOf(AuroraSchedulerManager.Iface.class.getMethods()); for (String toggledMethod : toggledMethods.keySet()) { Preconditions.checkArgument( Iterables.any(methods, Predicates.compose(Predicates.equalTo(toggledMethod), GET_NAME)), String.format("Method %s was not found in class %s", toggledMethod, AuroraSchedulerManager.Iface.class)); } bind(new TypeLiteral<Map<String, Boolean>>() { }).toInstance(toggledMethods); bind(IsFeatureEnabled.class).in(Singleton.class); Key<Predicate<Method>> predicateKey = Key.get(new TypeLiteral<Predicate<Method>>() { }); bind(predicateKey).to(IsFeatureEnabled.class); expose(predicateKey); } }); bindThriftDecorator(new FeatureToggleInterceptor()); bindThriftDecorator(new ThriftStatsExporterInterceptor()); bindThriftDecorator(new APIVersionInterceptor()); }
From source file:org.apache.brooklyn.core.location.LocationPredicates.java
public static Predicate<Location> idEqualTo(final String val) { return idSatisfies(Predicates.equalTo(val)); }
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 ww .j av a2 s. co m*/ 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.brooklyn.rest.resources.BundleResource.java
@Override public List<BundleSummary> listVersions(String symbolicName, boolean detail) { return list(Predicates.equalTo(symbolicName), false, detail); }
From source file:brooklyn.entity.basic.EntityPredicates.java
public static Predicate<Entity> applicationIdEqualTo(final String val) { return applicationIdSatisfies(Predicates.equalTo(val)); }