List of usage examples for com.google.common.collect Iterables any
public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.eclipse.emf.compare.internal.utils.DiffUtil.java
/** * When computing the insertion index of an element in a list, we need to ignore all elements present in * that list that feature unresolved Diffs on the same feature. * //from w w w . ja va 2s . c o m * @param candidates * The sequence in which we need to compute an insertion index. * @param diff * The diff we are computing an insertion index for. * @param <E> * Type of the list's content. * @param rightToLeft * Direction of the merging. {@code true} if the merge is to be done on the left side, making * 'target' the right side, {@code false} otherwise. * @return The list of elements that should be ignored when computing the insertion index for a new * element in {@code candidates}. */ private static <E> Iterable<E> computeIgnoredElements(Iterable<E> candidates, final Diff diff, boolean rightToLeft) { final Match match = diff.getMatch(); final Iterable<? extends Diff> filteredCandidates = Lists.newArrayList(match.getDifferences()); final Set<E> ignored = Sets.newLinkedHashSet(); for (E candidate : candidates) { if (candidate instanceof EObject) { final Iterable<? extends Diff> differences = match.getComparison() .getDifferences((EObject) candidate); if (Iterables.any(differences, new UnresolvedDiffMatching(diff, candidate, rightToLeft))) { ignored.add(candidate); } } else { if (Iterables.any(filteredCandidates, new UnresolvedDiffMatching(diff, candidate, rightToLeft))) { ignored.add(candidate); } } } return ignored; }
From source file:org.eclipse.emf.compare.conflict.DefaultConflictDetector.java
/** * Checks whether the given {@code match} presents a difference of any kind on the given {@code feature}'s * {@code value}./*from ww w. j ava 2s . com*/ * * @param match * The match which differences we'll check. * @param feature * The feature on which we expect a difference. * @param value * The value we expect to have changed inside {@code feature}. * @return <code>true</code> if there is such a Diff on {@code match}, <code>false</code> otherwise. */ private boolean hasDiff(Match match, EStructuralFeature feature, Object value) { return Iterables.any(match.getDifferences(), and(onFeature(feature.getName()), valueIs(value))); }
From source file:org.eclipse.emf.compare.conflict.DefaultConflictDetector.java
/** * Checks whether the given {@code value} has been deleted from the given {@code feature} of {@code match} * ./* w w w .j ava 2 s . c o m*/ * * @param match * The match which differences we'll check. * @param feature * The feature on which we expect a difference. * @param value * The value we expect to have been removed from {@code feature}. * @return <code>true</code> if there is such a Diff on {@code match}, <code>false</code> otherwise. */ @SuppressWarnings("unchecked") private boolean hasDeleteDiff(Match match, EStructuralFeature feature, Object value) { final Comparison comparison = match.getComparison(); final Object expectedValue; if (value instanceof EObject && comparison.isThreeWay()) { final Match valueMatch = comparison.getMatch((EObject) value); if (valueMatch != null) { expectedValue = valueMatch.getOrigin(); } else { expectedValue = value; } } else { expectedValue = value; } return Iterables.any(match.getDifferences(), and(onFeature(feature.getName()), valueIs(expectedValue), ofKind(DifferenceKind.DELETE))); }
From source file:org.summer.ss.core.validation.SsJavaValidator.java
@Check public void checkDispatchFunctions(XtendClass clazz) { JvmGenericType type = associations.getInferredType(clazz); if (type != null) { Multimap<DispatchHelper.DispatchSignature, JvmOperation> dispatchMethods = dispatchHelper .getDeclaredOrEnhancedDispatchMethods(type); checkDispatchNonDispatchConflict(clazz, dispatchMethods); for (DispatchHelper.DispatchSignature signature : dispatchMethods.keySet()) { Collection<JvmOperation> dispatchOperations = dispatchMethods.get(signature); JvmOperation syntheticDispatchMethod = dispatchHelper.getDispatcherOperation(type, signature); if (syntheticDispatchMethod != null) { JvmOperation overriddenOperation = overrideHelper .findOverriddenOperation(syntheticDispatchMethod); Boolean expectStatic = null; if (overriddenOperation != null) { if (isMorePrivateThan(syntheticDispatchMethod.getVisibility(), overriddenOperation.getVisibility())) { String msg = "Synthetic dispatch method reduces visibility of overridden method " + overriddenOperation.getIdentifier(); addDispatchError(type, dispatchOperations, msg, null, OVERRIDE_REDUCES_VISIBILITY); }//from w w w. java 2 s. c o m expectStatic = overriddenOperation.isStatic(); } LightweightTypeReference dispatchMethodReturnType = getActualType(clazz, syntheticDispatchMethod); if (dispatchOperations.size() == 1) { JvmOperation singleOp = dispatchOperations.iterator().next(); XtendFunction function = associations.getXtendFunction(singleOp); addIssue("Single dispatch method.", function, XTEND_MEMBER__MODIFIERS, function.getModifiers().indexOf("dispatch"), SINGLE_DISPATCH_FUNCTION); } else { Multimap<List<JvmType>, JvmOperation> signatures = HashMultimap.create(); boolean isFirstLocalOperation = true; JvmVisibility commonVisibility = null; Boolean commonStatic = null; for (JvmOperation jvmOperation : dispatchOperations) { signatures.put(getParamTypes(jvmOperation, true), jvmOperation); if (jvmOperation.getDeclaringType() == type) { if (expectStatic != null) { if (expectStatic && !jvmOperation.isStatic()) { String msg = "The dispatch method must be static because the dispatch methods in the superclass are static."; addDispatchError(jvmOperation, msg, "static", DISPATCH_FUNCTIONS_STATIC_EXPECTED); } if (!expectStatic && jvmOperation.isStatic()) { String msg = "The dispatch method must not be static because the dispatch methods in the superclass are not static."; addDispatchError(jvmOperation, msg, "static", DISPATCH_FUNCTIONS_NON_STATIC_EXPECTED); } } if (isFirstLocalOperation) { commonVisibility = jvmOperation.getVisibility(); commonStatic = jvmOperation.isStatic(); isFirstLocalOperation = false; } else { if (jvmOperation.getVisibility() != commonVisibility) { commonVisibility = null; } if (commonStatic != null && commonStatic != jvmOperation.isStatic()) { commonStatic = null; } } } // TODO move validation to type computation if (dispatchMethodReturnType != null) { XtendFunction function = associations.getXtendFunction(jvmOperation); if (function != null) { LightweightTypeReference operationType = getActualType(function.getExpression(), jvmOperation); if (!dispatchMethodReturnType.isAssignableFrom(operationType)) { error("Incompatible return type of dispatch method. Expected " + syntheticDispatchMethod.getSimpleName() + " but was " + operationType.getSimpleName(), function, SsPackage.Literals.XTEND_FUNCTION__RETURN_TYPE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_RETURN_TYPE); } } } } if (commonVisibility == null) { addDispatchError(type, dispatchOperations, "All local dispatch methods must have the same visibility.", null, DISPATCH_FUNCTIONS_WITH_DIFFERENT_VISIBILITY); } if (expectStatic == null && commonStatic == null) { addDispatchError(type, dispatchOperations, "Static and non-static dispatch methods can not be mixed.", "static", DISPATCH_FUNCTIONS_MIXED_STATIC_AND_NON_STATIC); } for (final List<JvmType> paramTypes : signatures.keySet()) { Collection<JvmOperation> ops = signatures.get(paramTypes); if (ops.size() > 1) { if (Iterables.any(ops, new Predicate<JvmOperation>() { public boolean apply(JvmOperation input) { return !getParamTypes(input, false).equals(paramTypes); } })) { for (JvmOperation jvmOperation : ops) { XtendFunction function = associations.getXtendFunction(jvmOperation); error("Duplicate dispatch methods. Primitives cannot overload their wrapper types in dispatch methods.", function, null, DUPLICATE_METHOD); } } } } } } } } }
From source file:forge.game.player.Player.java
public final boolean cantLose() { if (getOutcome() != null && getOutcome().lossState == GameLossReason.Conceded) { return false; }/*w w w. java 2s.c o m*/ return (hasKeyword("You can't lose the game.") || Iterables.any(getOpponents(), Predicates.CANT_WIN)); }
From source file:forge.game.player.Player.java
public final boolean hasLandfall() { final CardCollectionView list = getZone(ZoneType.Battlefield).getCardsAddedThisTurn(null); return Iterables.any(list, CardPredicates.Presets.LANDS); }
From source file:com.eucalyptus.bootstrap.Hosts.java
private static Function<List<DBStatus>, Function<DBStatus, List<DBStatus>>> distinctStatus() { return new Function<List<DBStatus>, Function<DBStatus, List<DBStatus>>>() { @Override//from ww w . j a v a 2 s . c om public Function<DBStatus, List<DBStatus>> apply(final List<DBStatus> statusList) { return new Function<DBStatus, List<DBStatus>>() { @Override public List<DBStatus> apply(final DBStatus input) { if (!Iterables.any(statusList, consistentWith(input))) { statusList.add(input); } return statusList; } }; } }; }
From source file:forge.learnedai.ComputerUtil.java
public static String chooseSomeType(Player ai, String kindOfType, String logic, List<String> invalidTypes) { if (invalidTypes == null) { invalidTypes = ImmutableList.<String>of(); }/*from w ww.j a v a2 s.c o m*/ final Game game = ai.getGame(); String chosen = ""; if (kindOfType.equals("Card")) { // TODO // computer will need to choose a type // based on whether it needs a creature or land, // otherwise, lib search for most common type left // then, reveal chosenType to Human if (game.getPhaseHandler().is(PhaseType.UNTAP) && logic == null) { // Storage Matrix double amount = 0; for (String type : CardType.getAllCardTypes()) { if (!invalidTypes.contains(type)) { CardCollection list = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.isType(type), Presets.TAPPED); double i = type.equals("Creature") ? list.size() * 1.5 : list.size(); if (i > amount) { amount = i; chosen = type; } } } } if (StringUtils.isEmpty(chosen)) { chosen = "Creature"; } } else if (kindOfType.equals("Creature")) { Player opp = ai.getOpponent(); if (logic != null) { if (logic.equals("MostProminentOnBattlefield")) { chosen = ComputerUtilCard.getMostProminentCreatureType(game.getCardsIn(ZoneType.Battlefield)); } else if (logic.equals("MostProminentComputerControls")) { chosen = ComputerUtilCard.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Battlefield)); } else if (logic.equals("MostProminentHumanControls")) { chosen = ComputerUtilCard.getMostProminentCreatureType(opp.getCardsIn(ZoneType.Battlefield)); if (!CardType.isACreatureType(chosen) || invalidTypes.contains(chosen)) { chosen = ComputerUtilCard.getMostProminentCreatureType( CardLists.filterControlledBy(game.getCardsInGame(), opp)); } } else if (logic.equals("MostProminentInComputerDeck")) { chosen = ComputerUtilCard .getMostProminentCreatureType(CardLists.filterControlledBy(game.getCardsInGame(), ai)); } else if (logic.equals("MostProminentInComputerGraveyard")) { chosen = ComputerUtilCard.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Graveyard)); } } if (!CardType.isACreatureType(chosen) || invalidTypes.contains(chosen)) { chosen = "Sliver"; } } else if (kindOfType.equals("Basic Land")) { if (logic != null) { if (logic.equals("MostNeededType")) { // Choose a type that is in the deck, but not in hand or on the battlefield final List<String> basics = new ArrayList<String>(); basics.addAll(CardType.Constant.BASIC_TYPES); CardCollectionView presentCards = CardCollection.combine(ai.getCardsIn(ZoneType.Battlefield), ai.getCardsIn(ZoneType.Hand)); CardCollectionView possibleCards = ai.getAllCards(); for (String b : basics) { if (!Iterables.any(presentCards, CardPredicates.isType(b)) && Iterables.any(possibleCards, CardPredicates.isType(b))) { chosen = b; } } if (chosen.equals("")) { for (String b : basics) { if (Iterables.any(possibleCards, CardPredicates.isType(b))) { chosen = b; } } } } else if (logic.equals("ChosenLandwalk")) { for (Card c : ai.getOpponent().getLandsInPlay()) { for (String t : c.getType()) { if (!invalidTypes.contains(t) && CardType.isABasicLandType(t)) { chosen = t; break; } } } } } if (!CardType.isABasicLandType(chosen) || invalidTypes.contains(chosen)) { chosen = "Island"; } } else if (kindOfType.equals("Land")) { if (logic != null) { if (logic.equals("ChosenLandwalk")) { for (Card c : ai.getOpponent().getLandsInPlay()) { for (String t : c.getType().getLandTypes()) { if (!invalidTypes.contains(t)) { chosen = t; break; } } } } } if (StringUtils.isEmpty(chosen)) { chosen = "Island"; } } return chosen; }
From source file:forge.ai.ComputerUtil.java
public static String chooseSomeType(Player ai, String kindOfType, String logic, List<String> invalidTypes) { if (invalidTypes == null) { invalidTypes = ImmutableList.<String>of(); }// w w w . j a v a 2s .c o m final Game game = ai.getGame(); String chosen = ""; if (kindOfType.equals("Card")) { // TODO // computer will need to choose a type // based on whether it needs a creature or land, // otherwise, lib search for most common type left // then, reveal chosenType to Human if (game.getPhaseHandler().is(PhaseType.UNTAP) && logic == null) { // Storage Matrix double amount = 0; for (String type : CardType.getAllCardTypes()) { if (!invalidTypes.contains(type)) { CardCollection list = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.isType(type), Presets.TAPPED); double i = type.equals("Creature") ? list.size() * 1.5 : list.size(); if (i > amount) { amount = i; chosen = type; } } } } if (StringUtils.isEmpty(chosen)) { chosen = "Creature"; } } else if (kindOfType.equals("Creature")) { Player opp = ai.getOpponent(); if (logic != null) { if (logic.equals("MostProminentOnBattlefield")) { chosen = ComputerUtilCard.getMostProminentCreatureType(game.getCardsIn(ZoneType.Battlefield)); } else if (logic.equals("MostProminentComputerControls")) { chosen = ComputerUtilCard.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Battlefield)); } else if (logic.equals("MostProminentHumanControls")) { chosen = ComputerUtilCard.getMostProminentCreatureType(opp.getCardsIn(ZoneType.Battlefield)); if (!CardType.isACreatureType(chosen) || invalidTypes.contains(chosen)) { chosen = ComputerUtilCard.getMostProminentCreatureType( CardLists.filterControlledBy(game.getCardsInGame(), opp)); } } else if (logic.equals("MostProminentInComputerDeck")) { chosen = ComputerUtilCard .getMostProminentCreatureType(CardLists.filterControlledBy(game.getCardsInGame(), ai)); } else if (logic.equals("MostProminentInComputerGraveyard")) { chosen = ComputerUtilCard.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Graveyard)); } } if (!CardType.isACreatureType(chosen) || invalidTypes.contains(chosen)) { chosen = "Sliver"; } } else if (kindOfType.equals("Basic Land")) { if (logic != null) { if (logic.equals("MostNeededType")) { // Choose a type that is in the deck, but not in hand or on the battlefield final List<String> basics = new ArrayList<String>(); basics.addAll(CardType.Constant.BASIC_TYPES); CardCollectionView presentCards = CardCollection.combine(ai.getCardsIn(ZoneType.Battlefield), ai.getCardsIn(ZoneType.Hand)); CardCollectionView possibleCards = ai.getAllCards(); for (String b : basics) { if (!Iterables.any(presentCards, CardPredicates.isType(b)) && Iterables.any(possibleCards, CardPredicates.isType(b))) { chosen = b; } } if (chosen.equals("")) { for (String b : basics) { if (Iterables.any(possibleCards, CardPredicates.isType(b))) { chosen = b; } } } } else if (logic.equals("ChosenLandwalk")) { for (Card c : ai.getOpponent().getLandsInPlay()) { for (String t : c.getType()) { if (!invalidTypes.contains(t) && CardType.isABasicLandType(t)) { chosen = t; break; } } } } } if (!CardType.isABasicLandType(chosen) || invalidTypes.contains(chosen)) { chosen = "Island"; } } else if (kindOfType.equals("Land")) { if (logic != null) { if (logic.equals("ChosenLandwalk")) { for (Card c : ai.getOpponent().getLandsInPlay()) { for (String t : c.getType().getLandTypes()) { if (!invalidTypes.contains(t)) { chosen = t; break; } } } } } if (StringUtils.isEmpty(chosen)) { chosen = "Island"; } } return chosen; }
From source file:org.eclipse.xtend.core.validation.XtendJavaValidator.java
@Check public void checkDispatchFunctions(XtendClass clazz) { JvmGenericType type = associations.getInferredType(clazz); if (type != null) { Multimap<DispatchHelper.DispatchSignature, JvmOperation> dispatchMethods = dispatchHelper .getDeclaredOrEnhancedDispatchMethods(type); checkDispatchNonDispatchConflict(clazz, dispatchMethods); for (DispatchHelper.DispatchSignature signature : dispatchMethods.keySet()) { Collection<JvmOperation> dispatchOperations = dispatchMethods.get(signature); JvmOperation syntheticDispatchMethod = dispatchHelper.getDispatcherOperation(type, signature); if (syntheticDispatchMethod != null) { JvmOperation overriddenOperation = overrideHelper .findOverriddenOperation(syntheticDispatchMethod); Boolean expectStatic = null; if (overriddenOperation != null) { if (isMorePrivateThan(syntheticDispatchMethod.getVisibility(), overriddenOperation.getVisibility())) { String msg = "Synthetic dispatch method reduces visibility of overridden method " + overriddenOperation.getIdentifier(); addDispatchError(type, dispatchOperations, msg, null, OVERRIDE_REDUCES_VISIBILITY); }/*from w ww .ja v a2 s . c o m*/ expectStatic = overriddenOperation.isStatic(); } LightweightTypeReference dispatchMethodReturnType = getActualType(clazz, syntheticDispatchMethod); if (dispatchOperations.size() == 1) { JvmOperation singleOp = dispatchOperations.iterator().next(); XtendFunction function = associations.getXtendFunction(singleOp); addIssue("Single dispatch method.", function, XTEND_MEMBER__MODIFIERS, function.getModifiers().indexOf("dispatch"), SINGLE_DISPATCH_FUNCTION); } else { Multimap<List<JvmType>, JvmOperation> signatures = HashMultimap.create(); boolean isFirstLocalOperation = true; JvmVisibility commonVisibility = null; Boolean commonStatic = null; for (JvmOperation jvmOperation : dispatchOperations) { signatures.put(getParamTypes(jvmOperation, true), jvmOperation); if (jvmOperation.getDeclaringType() == type) { if (expectStatic != null) { if (expectStatic && !jvmOperation.isStatic()) { String msg = "The dispatch method must be static because the dispatch methods in the superclass are static."; addDispatchError(jvmOperation, msg, "static", DISPATCH_FUNCTIONS_STATIC_EXPECTED); } if (!expectStatic && jvmOperation.isStatic()) { String msg = "The dispatch method must not be static because the dispatch methods in the superclass are not static."; addDispatchError(jvmOperation, msg, "static", DISPATCH_FUNCTIONS_NON_STATIC_EXPECTED); } } if (isFirstLocalOperation) { commonVisibility = jvmOperation.getVisibility(); commonStatic = jvmOperation.isStatic(); isFirstLocalOperation = false; } else { if (jvmOperation.getVisibility() != commonVisibility) { commonVisibility = null; } if (commonStatic != null && commonStatic != jvmOperation.isStatic()) { commonStatic = null; } } // TODO move validation to type computation if (dispatchMethodReturnType != null) { XtendFunction function = associations.getXtendFunction(jvmOperation); if (function != null) { LightweightTypeReference operationType = getActualType( function.getExpression(), jvmOperation); if (!dispatchMethodReturnType.isAssignableFrom(operationType)) { error("Incompatible return type of dispatch method. Expected " + dispatchMethodReturnType.getHumanReadableName() + " but was " + operationType.getHumanReadableName(), function, XtendPackage.Literals.XTEND_FUNCTION__RETURN_TYPE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_RETURN_TYPE); } } } } } if (commonVisibility == null) { addDispatchError(type, dispatchOperations, "All local dispatch methods must have the same visibility.", null, DISPATCH_FUNCTIONS_WITH_DIFFERENT_VISIBILITY); } if (expectStatic == null && commonStatic == null) { addDispatchError(type, dispatchOperations, "Static and non-static dispatch methods can not be mixed.", "static", DISPATCH_FUNCTIONS_MIXED_STATIC_AND_NON_STATIC); } for (final List<JvmType> paramTypes : signatures.keySet()) { Collection<JvmOperation> ops = signatures.get(paramTypes); if (ops.size() > 1) { if (Iterables.any(ops, new Predicate<JvmOperation>() { public boolean apply(JvmOperation input) { return !getParamTypes(input, false).equals(paramTypes); } })) { for (JvmOperation jvmOperation : ops) { XtendFunction function = associations.getXtendFunction(jvmOperation); error("Duplicate dispatch methods. Primitives cannot overload their wrapper types in dispatch methods.", function, null, DUPLICATE_METHOD); } } } } } } } } }