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:forge.quest.BoosterUtils.java
/** * Gets the quest starter deck.//from ww w . ja v a 2s . co m * * @param filter * the filter * @param numCommons * the num common * @param numUncommons * the num uncommon * @param numRares * the num rare * @param userPrefs * the starting pool preferences * @return the quest starter deck */ public static List<PaperCard> getQuestStarterDeck(final Predicate<PaperCard> filter, final int numCommons, final int numUncommons, final int numRares, final StartingPoolPreferences userPrefs) { if (possibleColors.isEmpty()) { possibleColors.add(MagicColor.BLACK); possibleColors.add(MagicColor.BLUE); possibleColors.add(MagicColor.GREEN); possibleColors.add(MagicColor.RED); possibleColors.add(MagicColor.WHITE); possibleColors.add(MagicColor.COLORLESS); } final List<PaperCard> cardPool = Lists .newArrayList(Iterables.filter(FModel.getMagicDb().getCommonCards().getAllCards(), filter)); final List<PaperCard> cards = new ArrayList<>(); if (userPrefs != null && userPrefs.grantCompleteSet()) { for (PaperCard card : cardPool) { cards.add(card); cards.add(card); cards.add(card); cards.add(card); } return cards; } final boolean allowDuplicates = userPrefs != null && userPrefs.allowDuplicates(); final boolean mythicsAvailable = Iterables.any(cardPool, Presets.IS_MYTHIC_RARE); final int numMythics = mythicsAvailable ? numRares / RARES_PER_MYTHIC : 0; final int adjustedRares = numRares - numMythics; final List<Predicate<CardRules>> colorFilters = getColorFilters(userPrefs, cardPool); cards.addAll( BoosterUtils.generateCards(cardPool, Presets.IS_COMMON, numCommons, colorFilters, allowDuplicates)); cards.addAll(BoosterUtils.generateCards(cardPool, Presets.IS_UNCOMMON, numUncommons, colorFilters, allowDuplicates)); cards.addAll(BoosterUtils.generateCards(cardPool, Presets.IS_RARE, adjustedRares, colorFilters, allowDuplicates)); if (numMythics > 0) { cards.addAll(BoosterUtils.generateCards(cardPool, Presets.IS_MYTHIC_RARE, numMythics, colorFilters, allowDuplicates)); } return cards; }
From source file:org.pentaho.di.trans.dataservice.serialization.ServiceTrans.java
public static Predicate<ServiceTrans> isReferenceTo(final TransMeta transMeta) { return new Predicate<ServiceTrans>() { final Set<Reference> references = ImmutableSet.copyOf(references(transMeta)); @Override/*w w w . j av a2 s .c o m*/ public boolean apply(ServiceTrans serviceTrans) { return Iterables.any(serviceTrans.getReferences(), Predicates.in(references)); } }; }
From source file:com.marvelution.bamboo.plugins.sonar.tasks.upgrade.EncryptUnencryptedTaskPasswordsUpgradeTask.java
/** * {@inheritDoc}/*from w w w .j a v a2s. c o m*/ */ @Override public Collection<Message> doUpgrade() throws Exception { for (Plan buildable : planManager.getAllPlansUnrestricted()) { if (Iterables.any(buildable.getBuildDefinition().getTaskDefinitions(), SonarPredicates.isSonarTask())) { logger.info("Check Sonar Tasks for " + buildable.getBuildKey()); for (TaskDefinition taskDefinition : Iterables.filter( buildable.getBuildDefinition().getTaskDefinitions(), SonarPredicates.isSonarTask())) { TaskDefinition newTaskDefinition = getTaskConfigurationService().editTask( buildable.getPlanKey(), taskDefinition.getId(), taskDefinition.getUserDescription(), getTaskConfigurationMap(taskDefinition), taskDefinition.getRootDirectorySelector()); logger.info("Encrypted task passwords of task [" + newTaskDefinition.getId() + "] of type [" + newTaskDefinition.getPluginKey() + "]"); } } else { logger.info(buildable.getBuildKey() + " has no Sonar Tasks to check"); } } return null; }
From source file:com.google.api.server.spi.config.ApiConfigLoader.java
/** * Creates a {@link ApiConfigLoader}.//from ww w .j av a2 s .co m * * @param configFactory Factory class in charge of creating {@link ApiConfig}s. * @param typeLoader Utility class for dealing with types in endpoint config generation. * @param annotationSource Config source which reads annotations in endpoint classes. * @param apiConfigSources Additional config sources, if any, to operate on endpoints. * @throws IllegalArgumentException if {@code apiConfigSources} includes another instance * of ApiConfigAnnotationReader. */ public ApiConfigLoader(ApiConfig.Factory configFactory, TypeLoader typeLoader, ApiConfigAnnotationReader annotationSource, ApiConfigSource... apiConfigSources) { this.configFactory = Preconditions.checkNotNull(configFactory); this.typeLoader = Preconditions.checkNotNull(typeLoader); this.annotationSource = Preconditions.checkNotNull(annotationSource); this.apiConfigSources = ImmutableList.copyOf(apiConfigSources); Preconditions.checkArgument( !Iterables.any(this.apiConfigSources, Predicates.instanceOf(ApiConfigAnnotationReader.class)), "Multiple instances of the of ApiConfigAnnotationReader were passed in"); }
From source file:com.eucalyptus.ws.server.SoapPipeline.java
@Override public boolean checkAccepts(final HttpRequest message) { final boolean usesServicePath = Iterables.any(servicePaths, Strings.isSuffixOf(message.getUri())); final boolean noPath = message.getUri().isEmpty() || message.getUri().equals("/") || message.getUri().startsWith("/?"); return message.getHeaderNames().contains("SOAPAction") && (usesServicePath || (noPath && resolvesByHost(message.getHeader(HttpHeaders.Names.HOST)))); }
From source file:org.eclipse.emf.compare.command.impl.CopyCommand.java
/** * {@inheritDoc}//from w ww. java 2 s. co m * * @see org.eclipse.emf.common.command.AbstractCommand#canExecute() */ @Override public boolean canExecute() { return super.canExecute() && Iterables.any(differences, hasState(DifferenceState.UNRESOLVED)); }
From source file:eu.numberfour.n4js.ui.workingsets.DefaultWorkingSetImpl.java
@Override public IAdaptable[] getElements() { final IProject[] projects = getAllProjects(); if (OTHERS_WORKING_SET_ID.equals(getId())) { // No other working sets are available at all. final WorkingSet[] allWorkingSets = getWorkingSetManager().getAllWorkingSets(); if (allWorkingSets.length == 1) { return projects; } else {/*from w w w .j a v a 2s. c om*/ // We have to exclude all those projects that are associatedwith at least one other working set. final FluentIterable<WorkingSet> others = from(asList(allWorkingSets)) .filter(ws -> !OTHERS_WORKING_SET_ID.equals(ws.getId())); // Mapping between non-built-in working sets and their elements. final Map<WorkingSet, Collection<IAdaptable>> elementMapping = Maps.toMap(others, ws -> newHashSet(ws.getElements())); final IProject[] elements = new IProject[projects.length]; int elementCount = 0; for (int i = 0, size = projects.length; i < size; i++) { final IProject project = projects[i]; // If the project is not assigned to any other working set, then assign it to the built-in one. if (!Iterables.any(others, ws -> elementMapping.get(ws).contains(project))) { elements[elementCount++] = project; } } return Arrays.copyOfRange(elements, 0, elementCount); } } else { final IProject[] elements = new IProject[projects.length]; int elementCount = 0; for (int i = 0, size = projects.length; i < size; i++) { final IProject project = projects[i]; if (apply(project)) { elements[elementCount++] = project; } } return Arrays.copyOfRange(elements, 0, elementCount); } }
From source file:xml.entity.mutableelement.Elements.java
/** * Create a predicate that matches if the node has an child that matches the * given predicate./*from w ww.j a v a2s . c o m*/ * * @param matching * This predicate will be applied the the children of the node. * @return true if any child matches. */ public static Predicate<Element> hasChild(final Predicate<Element> matching) { return new Predicate<Element>() { @Override public boolean apply(@Nullable final Element input) { return Iterables.any(input.children(), matching); } @Override public String toString() { return matching.toString(); } }; }
From source file:ratpack.render.RendererSupport.java
protected RendererSupport() { TypeToken<T> typeToken = new TypeToken<T>(getClass()) { };//from w w w. ja va 2 s.c o m Type type = typeToken.getType(); if (type instanceof Class) { @SuppressWarnings("unchecked") Class<T> rawType = (Class<T>) typeToken.getRawType(); this.type = rawType; } else if (type instanceof ParameterizedType) { Iterable<Type> typeArgs = Arrays.asList(((ParameterizedType) type).getActualTypeArguments()); if (Iterables.any(typeArgs, Predicates.not((t) -> t.getTypeName().equals("?")))) { throw new IllegalArgumentException("Invalid renderable type " + type + ": due to type erasure, type parameter T of RendererSupport must be a Class or a parameterized type with '?' for all type variables (e.g. List<?>)"); } this.type = Types.cast(typeToken.getRawType()); } else { throw new InternalRatpackError("Unhandled type for renderer support: " + type.getClass()); } }
From source file:de.cau.cs.kieler.klay.layered.intermediate.LabelDummyInserter.java
/** * {@inheritDoc}/*from w w w . j a v a 2s. c o m*/ */ public void process(final LGraph layeredGraph, final IKielerProgressMonitor monitor) { monitor.begin("Label dummy insertions", 1); List<LNode> newDummyNodes = Lists.newArrayList(); double labelSpacing = layeredGraph.getProperty(LayoutOptions.LABEL_SPACING).doubleValue(); for (LNode node : layeredGraph.getLayerlessNodes()) { for (LPort port : node.getPorts()) { for (LEdge edge : port.getOutgoingEdges()) { // Ignore self-loops for the moment (see KIPRA-1073) if (edge.getSource().getNode() != edge.getTarget().getNode() && Iterables.any(edge.getLabels(), CENTER_LABEL)) { // Remember the list of edge labels represented by the dummy node List<LLabel> representedLabels = Lists.newArrayListWithCapacity(edge.getLabels().size()); // Create dummy node LNode dummyNode = new LNode(layeredGraph); dummyNode.setNodeType(NodeType.LABEL); dummyNode.setProperty(InternalProperties.ORIGIN, edge); dummyNode.setProperty(InternalProperties.REPRESENTED_LABELS, representedLabels); dummyNode.setProperty(LayoutOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS); dummyNode.setProperty(InternalProperties.LONG_EDGE_SOURCE, edge.getSource()); dummyNode.setProperty(InternalProperties.LONG_EDGE_TARGET, edge.getTarget()); newDummyNodes.add(dummyNode); // Actually split the edge LongEdgeSplitter.splitEdge(edge, dummyNode); // Set thickness of the edge float thickness = edge.getProperty(LayoutOptions.THICKNESS); if (thickness < 0) { thickness = 0; edge.setProperty(LayoutOptions.THICKNESS, thickness); } KVector dummySize = dummyNode.getSize(); dummySize.y = thickness; double portPos = Math.floor(thickness / 2); // Apply port positions for (LPort dummyPort : dummyNode.getPorts()) { dummyPort.getPosition().y = portPos; } // Determine label size ListIterator<LLabel> iterator = edge.getLabels().listIterator(); while (iterator.hasNext()) { LLabel label = iterator.next(); if (label .getProperty(LayoutOptions.EDGE_LABEL_PLACEMENT) == EdgeLabelPlacement.CENTER) { dummySize.x = Math.max(dummySize.x, label.getSize().x); dummySize.y += label.getSize().y + labelSpacing; // Move the label over to the dummy node's REPRESENTED_LABELS property representedLabels.add(label); iterator.remove(); } } } } } } // Add created dummies to graph layeredGraph.getLayerlessNodes().addAll(newDummyNodes); monitor.done(); }