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.apache.whirr.actions.ScriptBasedClusterAction.java
private boolean containsNoneOf(Set<String> querySet, final Set<String> target) { return !Iterables.any(querySet, new Predicate<String>() { @Override/*ww w . j a va 2 s .c o m*/ public boolean apply(@Nullable String role) { return target.contains(role); } }); }
From source file:org.eclipse.rcptt.launching.ext.Q7LaunchDelegateUtils.java
/** Adds a key value pair, if this key is not already present */ private static void addIfAbsent(Collection<String> arguments, String key, String value) { Preconditions.checkNotNull(key);/*from w w w. ja v a2s. com*/ if (!Iterables.any(arguments, Predicates.equalTo(key))) { arguments.add(key); if (value != null) arguments.add(value); } }
From source file:forge.game.zone.MagicStack.java
public final void add(final SpellAbility sp) { SpellAbilityStackInstance si = null; final Card source = sp.getHostCard(); Player activator = sp.getActivatingPlayer(); // if activating player slips through the cracks, assign activating // Player to the controller here if (null == activator) { sp.setActivatingPlayer(source.getController()); activator = sp.getActivatingPlayer(); System.out.println(source.getName() + " - activatingPlayer not set before adding to stack."); }/*from w w w . j a v a2s . c o m*/ //either push onto or clear undo stack based on whether spell/ability is undoable if (sp.isUndoable()) { if (undoStackOwner != activator) { clearUndoStack(); //clear if undo stack owner changes undoStackOwner = activator; } undoStack.push(sp); } else { clearUndoStack(); } if (sp.isManaAbility()) { // Mana Abilities go straight through AbilityUtils.resolve(sp); game.getGameLog().add(GameLogEntryType.MANA, source + " - " + sp.getDescription()); sp.resetOnceResolved(); return; } if (sp.isSpell()) { source.setController(activator, 0); final Spell spell = (Spell) sp; if (spell.isCastFaceDown()) { source.turnFaceDown(); } else if (source.isFaceDown()) { source.turnFaceUp(); } } if (sp.getApi() == ApiType.Charm) { boolean remember = sp.hasParam("RememberChoice"); if (remember) { // Remember the ChoiceName here for later handling source.addRemembered(sp.getSubAbility().getParam("ChoiceName")); } } //cancel auto-pass for all opponents of activating player //when a new non-triggered ability is put on the stack if (!sp.isTrigger()) { for (final Player p : activator.getOpponents()) { p.getController().autoPassCancel(); } } if (frozen) { si = new SpellAbilityStackInstance(sp); frozenStack.push(si); return; } int totManaSpent = sp.getPayingMana().size(); if (sp instanceof AbilityStatic) { // TODO: make working triggered ability sp.setTotalManaSpent(totManaSpent); AbilityUtils.resolve(sp); } else { for (OptionalCost s : sp.getOptionalCosts()) { source.addOptionalCostPaid(s); } if (sp.isCopied()) { si = push(sp); } else { if (sp.isSpell() && source.isCreature() && Iterables.any(activator.getCardsIn(ZoneType.Battlefield), CardPredicates.hasKeyword("As an additional cost to cast creature spells," + " you may pay any amount of mana. If you do, that creature enters " + "the battlefield with that many additional +1/+1 counters on it."))) { final Cost costPseudoKicker = new Cost(ManaCost.ONE, false); boolean hasPaid = false; do { int mkMagnitude = source.getPseudoKickerMagnitude(); String prompt = String.format("Additional Cost for %s\r\nTimes Kicked: %d\r\n", source, mkMagnitude); hasPaid = activator.getController().payManaOptional(source, costPseudoKicker, sp, prompt, ManaPaymentPurpose.Multikicker); if (hasPaid) { source.addPseudoMultiKickerMagnitude(1); totManaSpent += 1; } } while (hasPaid); if (source.getPseudoKickerMagnitude() > 0) { String abStr = "DB$ PutCounter | Defined$ Self | ETB$ True | CounterType$ P1P1 | CounterNum$ " + source.getPseudoKickerMagnitude() + " | SubAbility$ ChorusDBETBCounters"; String dbStr = "DB$ ChangeZone | Hidden$ True | Origin$ All | Destination$ Battlefield" + "| Defined$ ReplacedCard"; source.setSVar("ChorusETBCounters", abStr); source.setSVar("ChorusDBETBCounters", dbStr); String repeffstr = "Event$ Moved | ValidCard$ Card.Self | Destination$ Battlefield " + "| ReplaceWith$ ChorusETBCounters | Secondary$ True | Description$ CARDNAME" + " enters the battlefield with " + source.getPseudoKickerMagnitude() + " +1/+1 counters."; ReplacementEffect re = ReplacementHandler.parseReplacement(repeffstr, source, false); re.setLayer(ReplacementLayer.Other); source.addReplacementEffect(re); } } // The ability is added to stack HERE si = push(sp); if (sp.isSpell() && (source.hasStartOfKeyword("Replicate") || ((source.isInstant() || source.isSorcery()) && Iterables.any(activator.getCardsIn(ZoneType.Battlefield), CardPredicates.hasKeyword( "Each instant and sorcery spell you cast has replicate. The replicate cost is equal to its mana cost."))))) { Integer magnitude = sp.getSVarInt("Replicate"); if (magnitude == null) { magnitude = 0; final Cost costReplicate = new Cost(source.getManaCost(), false); boolean hasPaid = false; int replicateCMC = source.getManaCost().getCMC(); do { String prompt = String.format("Replicate for %s\r\nTimes Replicated: %d\r\n", source, magnitude); hasPaid = activator.getController().payManaOptional(source, costReplicate, sp, prompt, ManaPaymentPurpose.Replicate); if (hasPaid) { magnitude++; totManaSpent += replicateCMC; } } while (hasPaid); } // Replicate Trigger String effect = String.format( "AB$ CopySpellAbility | Cost$ 0 | Defined$ SourceFirstSpell | Amount$ %d", magnitude); SpellAbility sa = AbilityFactory.getAbility(effect, source); sa.setDescription("Replicate - " + source); sa.setTrigger(true); sa.setCopied(true); addSimultaneousStackEntry(sa); } } } sp.setTotalManaSpent(totManaSpent); // Copied spells aren't cast per se so triggers shouldn't run for them. HashMap<String, Object> runParams = new HashMap<String, Object>(); if (!(sp instanceof AbilityStatic) && !sp.isCopied()) { // Run SpellAbilityCast triggers runParams.put("Cost", sp.getPayCosts()); runParams.put("Player", sp.getHostCard().getController()); runParams.put("Activator", sp.getActivatingPlayer()); runParams.put("CastSA", si.getSpellAbility(true)); runParams.put("CastSACMC", si.getSpellAbility(true).getHostCard().getCMC()); runParams.put("CurrentStormCount", thisTurnCast.size()); game.getTriggerHandler().runTrigger(TriggerType.SpellAbilityCast, runParams, true); // Run SpellCast triggers if (sp.isSpell()) { game.getTriggerHandler().runTrigger(TriggerType.SpellCast, runParams, true); executeCastCommand(si.getSpellAbility(true).getHostCard()); } // Run AbilityCast triggers if (sp.isAbility() && !sp.isTrigger()) { game.getTriggerHandler().runTrigger(TriggerType.AbilityCast, runParams, true); } // Run Cycled triggers if (sp.isCycling()) { runParams.clear(); runParams.put("Card", sp.getHostCard()); game.getTriggerHandler().runTrigger(TriggerType.Cycled, runParams, false); } } // Run BecomesTarget triggers // Create a new object, since the triggers aren't happening right away final List<TargetChoices> chosenTargets = sp.getAllTargetChoices(); if (!chosenTargets.isEmpty()) { runParams = new HashMap<String, Object>(); SpellAbility s = sp; if (si != null) { s = si.getSpellAbility(true); } runParams.put("SourceSA", s); Set<Object> distinctObjects = new HashSet<Object>(); for (final TargetChoices tc : chosenTargets) { if (tc != null && tc.getTargetCards() != null) { for (final Object tgt : tc.getTargets()) { // Track distinct objects so Becomes targets don't trigger for things like: // Seeds of Strength if (distinctObjects.contains(tgt)) { continue; } distinctObjects.add(tgt); if (tgt instanceof Card && !((Card) tgt).hasBecomeTargetThisTurn()) { runParams.put("FirstTime", null); ((Card) tgt).setBecameTargetThisTurn(true); } runParams.put("Target", tgt); game.getTriggerHandler().runTrigger(TriggerType.BecomesTarget, runParams, false); } } } } // Not sure these clauses are necessary. Consider it a precaution // for backwards compatibility for hardcoded cards. else if (sp.getTargetCard() != null) { runParams.put("Target", sp.getTargetCard()); game.getTriggerHandler().runTrigger(TriggerType.BecomesTarget, runParams, false); } game.fireEvent( new GameEventZone(ZoneType.Stack, sp.getActivatingPlayer(), EventValueChangeType.Added, source)); if (sp.getActivatingPlayer() != null && !game.getCardsPlayerCanActivateInStack().isEmpty()) { // This is a bit of a hack that forces the update of externally activatable cards in flashback zone (e.g. Lightning Storm). for (Player p : game.getPlayers()) { p.updateFlashbackForView(); } } }
From source file:org.eclipse.sirius.ui.tools.internal.views.common.action.DeleteRepresentationAction.java
/** * Test if the selection is valid./* w w w .j a v a2 s . c om*/ * * @return true if the selection is valid */ private boolean isValidSelection() { boolean anyInvalidDelete = Iterables.any(selectedRepresentations, new Predicate<DRepresentation>() { @Override public boolean apply(DRepresentation input) { EObject container = input.eContainer(); if (container instanceof DView) { IPermissionAuthority permissionAuthority = PermissionAuthorityRegistry.getDefault() .getPermissionAuthority(container); if (permissionAuthority != null && !permissionAuthority.canDeleteInstance(input)) { return true; } } return false; } }); return !anyInvalidDelete; }
From source file:fr.ippon.wip.config.WIPConfiguration.java
/** * Check if the given uri has to be proxied * /*from w w w. java 2 s . c o m*/ * @param uri * @return true if the uri has to be proxied */ public boolean isProxyURI(final String uri) { if (uri.endsWith("css")) return true; return Iterables.any(getDomainsToProxy(), new Predicate<String>() { public boolean apply(String domain) { return uri.startsWith(domain); } }); }
From source file:org.summer.dsl.xbase.compiler.TypeConvertingCompiler.java
protected void convertFunctionType(final JvmTypeReference expectedType, final JvmTypeReference functionType, final ITreeAppendable appendable, final Later expression, XExpression context) { // JvmTypeReference resolvedLeft = closures.getResolvedExpectedType(expectedType, functionType); if (expectedType.getIdentifier().equals(Object.class.getName()) || EcoreUtil.equals(expectedType.getType(), functionType.getType()) || ((expectedType instanceof JvmSynonymTypeReference) && Iterables.any(((JvmSynonymTypeReference) expectedType).getReferences(), new Predicate<JvmTypeReference>() { public boolean apply(@Nullable JvmTypeReference ref) { if (ref == null) { throw new IllegalArgumentException(); }// w ww . jav a 2s . co m return EcoreUtil.equals(ref.getType(), functionType.getType()); } }))) { // same raw type but different type parameters // at this point we know that we are compatible so we have to convince the Java compiler about that ;-) if (!getTypeConformanceComputer().isConformant(expectedType, functionType)) { // insert a cast appendable.append("("); serialize(expectedType, context, appendable); appendable.append(")"); } expression.exec(appendable); return; } JvmOperation operation = closures.findImplementingOperation(expectedType, context.eResource()); if (operation == null) { throw new IllegalStateException("expected type " + expectedType + " not mappable from " + functionType); } JvmType declaringType = (expectedType instanceof JvmParameterizedTypeReference) ? expectedType.getType() : operation.getDeclaringType(); final JvmTypeReference typeReferenceWithPlaceHolder = getTypeReferences().createTypeRef(declaringType); ITypeArgumentContext typeArgumentContext = contextProvider .getTypeArgumentContext(new TypeArgumentContextProvider.AbstractRequest() { @Override public JvmTypeReference getExpectedType() { return functionType; } @Override public JvmTypeReference getDeclaredType() { return typeReferenceWithPlaceHolder; } @Override public String toString() { return "TypeConvertingCompiler.convertFunctionType [expected=" + functionType + ",declared=" + typeReferenceWithPlaceHolder + "]"; } }); JvmTypeReference resolvedExpectedType = typeArgumentContext.resolve(typeReferenceWithPlaceHolder); appendable.append("new "); serialize(resolvedExpectedType, context, appendable, true, false); appendable.append("() {"); appendable.increaseIndentation().increaseIndentation(); appendable.newLine().append("public "); serialize(typeArgumentContext.resolve(operation.getReturnType()), context, appendable, true, false); appendable.append(" ").append(operation.getSimpleName()).append("("); EList<JvmFormalParameter> params = operation.getParameters(); for (Iterator<JvmFormalParameter> iterator = params.iterator(); iterator.hasNext();) { JvmFormalParameter p = iterator.next(); final String name = p.getName(); serialize(typeArgumentContext.resolve(p.getParameterType()), context, appendable, false, false); appendable.append(" ").append(name); if (iterator.hasNext()) appendable.append(","); } appendable.append(") {"); appendable.increaseIndentation(); if (!getTypeReferences().is(operation.getReturnType(), Void.TYPE)) appendable.newLine().append("return "); else appendable.newLine(); expression.exec(appendable); appendable.append("."); JvmOperation actualOperation = closures.findImplementingOperation(functionType, context.eResource()); appendable.append(actualOperation.getSimpleName()); appendable.append("("); for (Iterator<JvmFormalParameter> iterator = params.iterator(); iterator.hasNext();) { JvmFormalParameter p = iterator.next(); final String name = p.getName(); appendable.append(name); if (iterator.hasNext()) appendable.append(","); } appendable.append(");"); appendable.decreaseIndentation(); appendable.newLine().append("}"); appendable.decreaseIndentation().decreaseIndentation(); appendable.newLine().append("}"); }
From source file:com.google.gerrit.server.project.ProjectState.java
/** * @return true if any of the groups listed in {@code groups} was declared to * be an owner of this project, or one of its parent projects.. */// w ww.j ava2 s.co m boolean isOwner(final GroupMembership groups) { return Iterables.any(tree(), new Predicate<ProjectState>() { @Override public boolean apply(ProjectState in) { return groups.containsAnyOf(in.localOwners); } }); }
From source file:org.raml.v2.internal.impl.commons.model.type.TypeDeclaration.java
/** * True if the node is a local named type declaration as opposed to an inline/anonymous declaration. This is computed based on the parent of the current type declaration node, i.e. * if its parent is one of the local named type declaration nodes possible. * * @return <code>true</code> if the node is a local named type declaration as opposed to an inline/anonymous declaration, <code>false</code> otherwise *///w ww . j a v a 2 s .c o m private boolean isLocalNamedTypeDeclarationNode() { final Node parent = node.getParent(); // tries to get the grandparent of the current node to retrieve the same node based on the known local named declaration node names final Node baseNode = parent.getParent().getParent(); return baseNode != null && Iterables.any(LOCAL_NAMED_TYPE_DECLARATION_NODE_NAMES, new Predicate<String>() { @Override public boolean apply(final String name) { return parent == baseNode.get(name); } }); }
From source file:com.isotrol.impe3.pms.core.dao.impl.DAOImpl.java
/** * @see com.isotrol.impe3.pms.core.dao.DAO#isUsed(java.util.UUID, java.util.UUID, java.lang.Iterable) *//*from w ww . j a va 2s .c o m*/ public boolean isUsed(final UUID envId, final UUID id, Iterable<String> queries) { final Predicate<String> hasRows = new Predicate<String>() { public boolean apply(String input) { return hasRows(input, envId, id); } }; return Iterables.any(queries, hasRows); }
From source file:com.isotrol.impe3.pms.core.impl.EditionsServiceImpl.java
private boolean needs(Iterable<? extends PublishableObject> elements) { return Iterables.any(Iterables.transform(elements, PublishableObject.STATE), NEEDS_PUBLISHING); }