List of usage examples for com.google.common.base Predicates in
public static <T> Predicate<T> in(Collection<? extends T> target)
From source file:org.lanternpowered.server.command.LanternCommandDisambiguator.java
@Override public Optional<CommandMapping> disambiguate(@Nullable CommandSource source, String aliasUsed, List<CommandMapping> availableOptions) { if (availableOptions.size() > 1) { final String chosenPlugin = this.game.getGlobalConfig().getCommandAliases() .get(aliasUsed.toLowerCase()); if (chosenPlugin != null) { final Optional<PluginContainer> container = this.game.getPluginManager().getPlugin(chosenPlugin); if (!container.isPresent()) { this.game.getServer().getConsole() .sendMessage(t("Unable to find plugin '%s' for command '%s', falling back to default", chosenPlugin, aliasUsed)); } else { final Set<CommandMapping> ownedCommands = this.game.getCommandManager() .getOwnedBy(container.get()); final List<CommandMapping> ownedMatchingCommands = availableOptions.stream() .filter(Predicates.in(ownedCommands)::apply).collect(ImmutableList.toImmutableList()); if (ownedMatchingCommands.isEmpty()) { this.game.getServer().getConsole() .sendMessage(t( "Plugin %s was specified as the preferred owner for %s, " + "but does not have any such command!", container.get().getName(), aliasUsed)); } else if (ownedMatchingCommands.size() > 1) { throw new IllegalStateException("Plugin " + container.get().getName() + " seems to have multiple commands registered as " + aliasUsed + "! This is a programming error!"); } else { return Optional.of(ownedMatchingCommands.get(0)); }/*from www .ja v a2 s . c o m*/ } } } return SimpleDispatcher.FIRST_DISAMBIGUATOR.disambiguate(source, aliasUsed, availableOptions); }
From source file:org.apache.abdera2.common.misc.MorePredicates.java
public static <T> Selector<T> in(Class<T> _class, String method, Collection<T> items) { return PropertySelector.<T>create(_class, method, Predicates.in(items)); }
From source file:net.automatalib.util.automata.transout.MealyFilter.java
/** * Returns a Mealy machine with all transitions removed that have an output not among the specified values. The resulting * Mealy machine will not contain any unreachable states. * //w w w . j ava 2s . c o m * @param in the input Mealy machine * @param inputs the input alphabet * @param outputs the outputs to retain * @return a Mealy machine with all transitions retained that have one of the specified outputs. */ public static <I, O> CompactMealy<I, O> retainTransitionsWithOutput(MealyMachine<?, I, ?, O> in, Alphabet<I> inputs, Collection<? super O> outputs) { return filterByOutput(in, inputs, Predicates.in(outputs)); }
From source file:eu.lp0.cursus.scoring.scores.impl.GenericRaceLapsData.java
@Override protected List<Pilot> calculateRaceLapsInOrder(Race race, Map<Pilot, Integer> laps) { ListMultimap<Integer, Pilot> raceOrder = ArrayListMultimap.create(EXPECTED_MAXIMUM_LAPS, scores.getPilots().size());//from ww w. j a v a 2s . com extractRaceLaps(race, laps, raceOrder, null); // Get penalties for each pilot ListMultimap<Pilot, Penalty> cancelLaps = ArrayListMultimap.create(EXPECTED_MAXIMUM_PENALTIES, scores.getPilots().size()); ListMultimap<Pilot, Penalty> adjustLaps = ArrayListMultimap.create(EXPECTED_MAXIMUM_PENALTIES, scores.getPilots().size()); for (RaceAttendee attendee : Maps.filterKeys(race.getAttendees(), Predicates.in(scores.getPilots())) .values()) { for (Penalty penalty : Iterables.concat(Ordering.natural().immutableSortedCopy(attendee.getPenalties()), scores.getSimulatedRacePenalties(attendee.getPilot(), race))) { if (penalty.getValue() != 0) { switch (penalty.getType()) { case CANCEL_LAPS: cancelLaps.put(attendee.getPilot(), penalty); break; case ADJUST_LAPS: adjustLaps.put(attendee.getPilot(), penalty); break; default: break; } } } } // Apply lap cancellation penalties if (!cancelLaps.isEmpty()) { final Multiset<Pilot> pilotLaps = HashMultiset.create(laps.size()); for (Map.Entry<Pilot, Integer> pilotLapCount : laps.entrySet()) { pilotLaps.setCount(pilotLapCount.getKey(), pilotLapCount.getValue()); } for (Map.Entry<Pilot, Penalty> entry : cancelLaps.entries()) { int value = entry.getValue().getValue(); if (value > 0) { pilotLaps.remove(entry.getKey(), value); } else { pilotLaps.add(entry.getKey(), Math.abs(value)); } } extractRaceLaps(race, laps, raceOrder, new Predicate<Pilot>() { @Override public boolean apply(@Nullable Pilot pilot) { return pilotLaps.remove(pilot); } }); } // Save pilot order List<Pilot> origPilotOrder = getPilotOrder(raceOrder); SortedSet<Pilot> noLaps = new TreeSet<Pilot>(new PilotRaceNumberComparator()); Set<Integer> changed = new HashSet<Integer>(); // It is intentional that pilots can end up having 0 laps but be considered to have completed the race for (Map.Entry<Pilot, Penalty> entry : adjustLaps.entries()) { Pilot pilot = entry.getKey(); int lapCount = laps.get(pilot); raceOrder.remove(lapCount, pilot); changed.add(lapCount); lapCount += entry.getValue().getValue(); if (lapCount <= 0) { lapCount = 0; noLaps.add(pilot); } laps.put(pilot, lapCount); raceOrder.put(lapCount, pilot); changed.add(lapCount); } // Apply original pilot order if (!changed.isEmpty()) { origPilotOrder.addAll(noLaps); for (Integer lapCount : changed) { raceOrder.replaceValues(lapCount, Ordering.explicit(origPilotOrder).immutableSortedCopy(raceOrder.get(lapCount))); } return getPilotOrder(raceOrder); } else { return origPilotOrder; } }
From source file:org.spongepowered.common.command.SpongeCommandDisambiguator.java
@Override @NonnullByDefault/*from w ww . ja va 2 s. com*/ public Optional<CommandMapping> disambiguate(@Nullable CommandSource source, String aliasUsed, List<CommandMapping> availableOptions) { if (availableOptions.size() > 1) { final String chosenPlugin = SpongeImpl.getGlobalConfig().getConfig().getCommands().getAliases() .get(aliasUsed.toLowerCase()); if (chosenPlugin != null) { Optional<PluginContainer> container = this.game.getPluginManager().getPlugin(chosenPlugin); if (!container.isPresent()) { SpongeImpl.getGame().getServer().getConsole().sendMessage(t("Unable to find plugin '" + chosenPlugin + "' for command '" + aliasUsed + "', falling back to default")); } else { final Set<CommandMapping> ownedCommands = this.game.getCommandManager() .getOwnedBy(container.get()); final List<CommandMapping> ownedMatchingCommands = ImmutableList .copyOf(Iterables.filter(availableOptions, Predicates.in(ownedCommands))); if (ownedMatchingCommands.isEmpty()) { SpongeImpl.getGame().getServer().getConsole() .sendMessage(t("Plugin " + container.get().getName() + " was specified as the " + "preferred owner for " + aliasUsed + ", but does not have any such command!")); } else if (ownedMatchingCommands.size() > 1) { throw new IllegalStateException("Plugin " + container.get().getName() + " seems to have multiple commands registered as " + aliasUsed + "! This is a programming error!"); } else { return Optional.of(ownedMatchingCommands.get(0)); } } } } return SimpleDispatcher.FIRST_DISAMBIGUATOR.disambiguate(source, aliasUsed, availableOptions); }
From source file:controllers.modules.base.Module.java
public <T extends ViewModel> T findViewModel(Class<T> viewModelClass, Iterable<ViewModel> exclude, T defaultViewModel) {/*from w ww . j av a2s. co m*/ exclude = ObjectUtils.defaultIfNull(exclude, Lists.<ViewModel>newArrayList()); return Iterables.getFirst( Iterables.filter(Iterables.filter(this.viewModels, Predicates.not(Predicates.in(Lists.newArrayList(exclude)))), viewModelClass), defaultViewModel); }
From source file:net.automatalib.util.graphs.ShortestPaths.java
public static <N, E> Path<N, E> shortestPath(IndefiniteGraph<N, E> graph, Collection<? extends N> start, int limit, Collection<?> targets) { return shortestPath(graph, start, limit, Predicates.in(targets)); }
From source file:com.twitter.crunch.BaseRackIsolationPlacementRules.java
/** * Use the predicate to reject already selected racks. *//*from ww w . j a v a2s . c o m*/ private Predicate<Node> getRackPredicate(Set<Node> selectedRacks) { return Predicates.not(Predicates.in(selectedRacks)); }
From source file:org.sosy_lab.cpachecker.util.refinement.PathExtractor.java
/** * This method returns an unsorted, non-empty collection of target states * found during the analysis./*from w w w .ja va2 s .co m*/ * * @param pReached the set of reached states * @return the target states * @throws org.sosy_lab.cpachecker.exceptions.RefinementFailedException */ public Collection<ARGState> getTargetStates(final ARGReachedSet pReached) throws RefinementFailedException { // extract target locations from and exclude those found to be feasible before, // e.g., when analysis.stopAfterError is set to false List<ARGState> targets = extractTargetStatesFromArg(pReached) .filter(Predicates.not(Predicates.in(feasibleTargets))).toList(); // set of targets may only be empty, if all of them were found feasible previously if (targets.isEmpty()) { assert feasibleTargets.containsAll(extractTargetStatesFromArg(pReached).toSet()); throw new RefinementFailedException(Reason.RepeatedCounterexample, ARGUtils.getOnePathTo(Iterables.getLast(feasibleTargets))); } logger.log(Level.FINEST, "number of targets found: " + targets.size()); targetCounter = targetCounter + targets.size(); return targets; }
From source file:com.webbfontaine.valuewebb.irms.impl.assignment.action.AssignmentRuleActions.java
public void assignAutomatic(final TtGen ttGen, final List<String> newAssignees) { Preconditions.checkArgument(!newAssignees.isEmpty()); final Set<String> candidates = Sets.newHashSet(newAssignees); List<String> previousAssignees = assignmentEventRepository.getAssigneesByTtId(ttGen.getId()); LOGGER.debug(//from w ww. j a v a 2 s .c o m "Found previous distinct assignees: {} for TT with id: {} and will check for presence 'automatic' assignees list: {}", new Object[] { previousAssignees, ttGen.getId(), newAssignees }); String assignee = from(previousAssignees).firstMatch(Predicates.in(candidates)).or(new Supplier<String>() { @Override public String get() { return automaticAssignmentManager.resolveAssignee(newAssignees); } }); Preconditions.checkNotNull(assignee, "We should have resolved assignee at least from automatic assignees list"); assignTTanalystForce(ttGen, assignee); }