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:com.facebook.presto.metadata.FunctionRegistry.java
public boolean isAggregationFunction(QualifiedName name) { return Iterables.any(functions.get(name), function -> function.getSignature().getKind() == AGGREGATE || function.getSignature().getKind() == APPROXIMATE_AGGREGATE); }
From source file:org.jasig.ssp.service.impl.EvaluatedSuccessIndicatorServiceImpl.java
private boolean isEmptyNormalizedString(@Nullable List<String> normalizedStrings) { return normalizedStrings == null || normalizedStrings.isEmpty() || !(Iterables.any(normalizedStrings, NON_BLANK_STRING_TEST)); }
From source file:org.jclouds.compute.domain.internal.TemplateBuilderImpl.java
protected Hardware resolveHardware(Set<? extends Hardware> hardwarel, final Iterable<? extends Image> images) { Ordering<Hardware> hardwareOrdering = hardwareSorter(); Iterable<Predicate<Image>> supportsImagePredicates = Iterables.transform(hardwarel, new Function<Hardware, Predicate<Image>>() { @Override//from ww w.java 2 s. co m public Predicate<Image> apply(Hardware input) { return input.supportsImage(); } }); Predicate<Image> supportsImagePredicate = Iterables.size(supportsImagePredicates) == 1 ? Iterables.getOnlyElement(supportsImagePredicates) : Predicates.<Image>or(supportsImagePredicates); if (!Iterables.any(images, supportsImagePredicate)) { String message = format("no hardware profiles support images matching params: %s", supportsImagePredicate); throw throwNoSuchElementExceptionAfterLoggingHardwareIds(message, hardwarel); } Iterable<? extends Hardware> hardwareCompatibleWithOurImages = filter(hardwarel, supportsImagesPredicate(images)); Predicate<Hardware> hardwarePredicate = buildHardwarePredicate(); Hardware hardware; try { hardware = hardwareOrdering.max(filter(hardwareCompatibleWithOurImages, hardwarePredicate)); } catch (NoSuchElementException exception) { String message = format("no hardware profiles match params: %s", hardwarePredicate); throw throwNoSuchElementExceptionAfterLoggingHardwareIds(message, hardwareCompatibleWithOurImages); } logger.trace("<< matched hardware(%s)", hardware.getId()); return hardware; }
From source file:com.vmware.appfactory.cws.simulator.CwsSimulator.java
private boolean commandLabelContains(final String text, Collection<CommandList> commandLists) { final Predicate<Command> anyLabelInCommand = new Predicate<Command>() { @Override//from w w w.j ava2 s . c o m public boolean apply(Command command) { return command.getLabel() != null && command.getLabel().contains(text); } }; Predicate<CommandList> anyCommandInList = new Predicate<CommandList>() { @Override public boolean apply(CommandList commandList) { return Iterables.any(commandList.getCommands(), anyLabelInCommand); } }; return Iterables.any(commandLists, anyCommandInList); }
From source file:org.apache.cassandra.db.compaction.LeveledManifest.java
/** * @return highest-priority sstables to compact for the given level. * If no compactions are possible (because of concurrent compactions or because some sstables are blacklisted * for prior failure), will return an empty list. Never returns null. *//*from w w w .ja v a2s.c o m*/ private Collection<SSTableReader> getCandidatesFor(int level) { assert !getLevel(level).isEmpty(); logger.trace("Choosing candidates for L{}", level); final Set<SSTableReader> compacting = cfs.getTracker().getCompacting(); if (level == 0) { Set<SSTableReader> compactingL0 = getCompacting(0); RowPosition lastCompactingKey = null; RowPosition firstCompactingKey = null; for (SSTableReader candidate : compactingL0) { if (firstCompactingKey == null || candidate.first.compareTo(firstCompactingKey) < 0) firstCompactingKey = candidate.first; if (lastCompactingKey == null || candidate.last.compareTo(lastCompactingKey) > 0) lastCompactingKey = candidate.last; } // L0 is the dumping ground for new sstables which thus may overlap each other. // // We treat L0 compactions specially: // 1a. add sstables to the candidate set until we have at least maxSSTableSizeInMB // 1b. prefer choosing older sstables as candidates, to newer ones // 1c. any L0 sstables that overlap a candidate, will also become candidates // 2. At most MAX_COMPACTING_L0 sstables from L0 will be compacted at once // 3. If total candidate size is less than maxSSTableSizeInMB, we won't bother compacting with L1, // and the result of the compaction will stay in L0 instead of being promoted (see promote()) // // Note that we ignore suspect-ness of L1 sstables here, since if an L1 sstable is suspect we're // basically screwed, since we expect all or most L0 sstables to overlap with each L1 sstable. // So if an L1 sstable is suspect we can't do much besides try anyway and hope for the best. Set<SSTableReader> candidates = new HashSet<>(); Set<SSTableReader> remaining = new HashSet<>(); Iterables.addAll(remaining, Iterables.filter(getLevel(0), Predicates.not(suspectP))); for (SSTableReader sstable : ageSortedSSTables(remaining)) { if (candidates.contains(sstable)) continue; Sets.SetView<SSTableReader> overlappedL0 = Sets.union(Collections.singleton(sstable), overlapping(sstable, remaining)); if (!Sets.intersection(overlappedL0, compactingL0).isEmpty()) continue; for (SSTableReader newCandidate : overlappedL0) { if (firstCompactingKey == null || lastCompactingKey == null || overlapping(firstCompactingKey.getToken(), lastCompactingKey.getToken(), Arrays.asList(newCandidate)).size() == 0) candidates.add(newCandidate); remaining.remove(newCandidate); } if (candidates.size() > MAX_COMPACTING_L0) { // limit to only the MAX_COMPACTING_L0 oldest candidates candidates = new HashSet<>(ageSortedSSTables(candidates).subList(0, MAX_COMPACTING_L0)); break; } } // leave everything in L0 if we didn't end up with a full sstable's worth of data if (SSTableReader.getTotalBytes(candidates) > maxSSTableSizeInBytes) { // add sstables from L1 that overlap candidates // if the overlapping ones are already busy in a compaction, leave it out. // TODO try to find a set of L0 sstables that only overlaps with non-busy L1 sstables Set<SSTableReader> l1overlapping = overlapping(candidates, getLevel(1)); if (Sets.intersection(l1overlapping, compacting).size() > 0) return Collections.emptyList(); if (!overlapping(candidates, compactingL0).isEmpty()) return Collections.emptyList(); candidates = Sets.union(candidates, l1overlapping); } if (candidates.size() < 2) return Collections.emptyList(); else return candidates; } // for non-L0 compactions, pick up where we left off last time Collections.sort(getLevel(level), SSTableReader.sstableComparator); int start = 0; // handles case where the prior compaction touched the very last range for (int i = 0; i < getLevel(level).size(); i++) { SSTableReader sstable = getLevel(level).get(i); if (sstable.first.compareTo(lastCompactedKeys[level]) > 0) { start = i; break; } } // look for a non-suspect keyspace to compact with, starting with where we left off last time, // and wrapping back to the beginning of the generation if necessary for (int i = 0; i < getLevel(level).size(); i++) { SSTableReader sstable = getLevel(level).get((start + i) % getLevel(level).size()); Set<SSTableReader> candidates = Sets.union(Collections.singleton(sstable), overlapping(sstable, getLevel(level + 1))); if (Iterables.any(candidates, suspectP)) continue; if (Sets.intersection(candidates, compacting).isEmpty()) return candidates; } // all the sstables were suspect or overlapped with something suspect return Collections.emptyList(); }
From source file:org.eclipse.che.plugin.svn.server.SubversionApi.java
/** * Perform an "svn move" based on the request. * * @param request// w ww. j a v a2 s .co m * the request * @return the response * @throws IOException * if there is a problem executing the command * @throws SubversionException * if there is a Subversion issue */ public CLIOutputResponse move(final MoveRequest request) throws IOException, SubversionException, UnauthorizedException { Predicate<String> sourcePredicate = new Predicate<String>() { @Override public boolean apply(String input) { return input.startsWith("file://"); } }; //for security reason we should forbid file protocol if (Iterables.any(request.getSource(), sourcePredicate) || request.getDestination().startsWith("file://")) { throw new SubversionException("Url is not acceptable"); } final File projectPath = new File(request.getProjectPath()); final List<String> cliArgs = defaultArgs(); if (!isNullOrEmpty(request.getComment())) { addOption(cliArgs, "--message", "\"" + request.getComment() + "\""); } // Command Name cliArgs.add("move"); final List<String> paths = new ArrayList<>(); paths.addAll(request.getSource()); paths.add(request.getDestination()); final CommandLineResult result = runCommand(null, cliArgs, projectPath, paths, request.getUsername(), request.getPassword()); return DtoFactory.getInstance().createDto(CLIOutputResponse.class) .withCommand(result.getCommandLine().toString()).withOutput(result.getStdout()) .withErrOutput(result.getStderr()); }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.vertical.SequenceVerticalLayout.java
private int getMinY(EventEnd endBefore, EventEnd end, Collection<ISequenceEvent> commonIses, boolean pack, int currentLocation, Map<EventEnd, Integer> alreadyComputedLocations) { int genericGap = getGenericGap(endBefore, end, pack); int minGap = genericGap; if (!commonIses.isEmpty()) { int commonIseGap = getGapFromCommonSequenceEvent(end, commonIses, pack, genericGap); minGap = commonIseGap;/* w w w.j a va 2 s . c om*/ } else { boolean operands = Iterables.any(eventEndToSequenceEvents.apply(end), Predicates.instanceOf(Operand.class)); if (operands) { minGap = getGapBeforeOperandEnd(endBefore, end, currentLocation, genericGap, alreadyComputedLocations); } } return currentLocation + minGap; }
From source file:org.trancecode.xproc.step.Step.java
/** * {@code err:XS0005}./*from ww w .j a v a2s. c o m*/ */ private void checkOutputPorts() { for (int i = 0; i < getSubpipeline().size(); i++) { final Step childStep = getSubpipeline().get(i); final Port outputPort = childStep.getPrimaryOutputPort(); if (outputPort != null && outputPort.getPortBindings().isEmpty()) { final boolean explicitlyConnected = Iterables.any(getDescendantSteps(), step -> Iterables.any(step.getInputPortBindings(), PortBindingPredicates.isConnectedTo(outputPort.getPortReference()))); if (explicitlyConnected) { continue; } // The parent step has an output port // explicitly bound to this output port if (Iterables.any(getOutputPortBindings(), PortBindingPredicates.isConnectedTo(outputPort.getPortReference()))) { continue; } // Step is the latest from subpipeline and // The parent step has a primary output port // implicitly bound to this output port if (i == getSubpipeline().size() - 1 && childStep.isPrimary(outputPort) && getPrimaryOutputPort() != null && getPrimaryOutputPort().getPortBindings().isEmpty()) { continue; } // Next step has unbound primary input port if (i < getSubpipeline().size() - 1 && getSubpipeline().get(i + 1).getPrimaryInputPort() != null && getSubpipeline().get(i + 1).getPrimaryInputPort().getPortBindings().isEmpty()) { continue; } // Next step is a choose step if (i < getSubpipeline().size() - 1 && getSubpipeline().get(i + 1).getType() == XProcSteps.CHOOSE) { continue; } // TODO: xs0005 is not manage very well ! throw XProcExceptions.xs0005(childStep, outputPort.getPortName()); } } }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.vertical.SequenceVerticalLayout.java
private int getGenericGap(EventEnd endBefore, EventEnd end, boolean pack) { int beforeGap = 0; if (endBefore != null) { Collection<ISequenceEvent> endBeforeEvents = eventEndToSequenceEvents.apply(endBefore); beforeGap = pack ? LayoutConstants.MIN_INTER_SEQUENCE_EVENTS_VERTICAL_GAP : LayoutConstants.EXECUTION_CHILDREN_MARGIN; // Predecessor : Logically instantaneouse States Iterable<State> predStates = Iterables.filter(endBeforeEvents, State.class); if (EventEndHelper.PUNCTUAL_COMPOUND_EVENT_END.apply(endBefore) && endBeforeEvents.size() == 1 && Iterables.size(predStates) == 1) { State predState = Iterables.getOnlyElement(predStates); if (predState.isLogicallyInstantaneous()) { beforeGap += getAbstractNodeEventVerticalSize(endBefore, predState, endBeforeEvents, pack) / 2; }/*from www . j a v a 2s .c o m*/ } if (Iterables.any(endBeforeEvents, Predicates.instanceOf(InteractionUse.class)) && endBefore instanceof SingleEventEnd && ((SingleEventEnd) endBefore).isStart()) { beforeGap = LayoutConstants.DEFAULT_INTERACTION_USE_HEIGHT / 2; } if (Iterables.any(eventEndToSequenceEvents.apply(end), Predicates.instanceOf(InteractionUse.class)) && end instanceof SingleEventEnd && !((SingleEventEnd) end).isStart()) { beforeGap = LayoutConstants.DEFAULT_INTERACTION_USE_HEIGHT / 2; } if (creators.keySet().contains(endBefore)) { if (pack) { beforeGap += getTargetFigureMidHeight(creators.get(endBefore)) + LayoutConstants.TIME_START_OFFSET - LayoutConstants.MIN_INTER_SEQUENCE_EVENTS_VERTICAL_GAP; } else { beforeGap += getTargetFigureMidHeight(creators.get(endBefore)); } } else if (losts.containsKey(endBefore)) { beforeGap += losts.get(endBefore).getBounds().height / 2; } } else { beforeGap = pack ? LayoutConstants.TIME_START_OFFSET : LayoutConstants.TIME_START_MIN_OFFSET; } if (destructors.keySet().contains(end)) { beforeGap += getTargetFigureMidHeight(destructors.get(end)); } else if (losts.containsKey(end)) { beforeGap += losts.get(end).getBounds().height / 2; } // current event : Logically instantaneouse States Collection<ISequenceEvent> endEvents = eventEndToSequenceEvents.apply(end); Iterable<State> states = Iterables.filter(endEvents, State.class); if (EventEndHelper.PUNCTUAL_COMPOUND_EVENT_END.apply(end) && endEvents.size() == 1 && Iterables.size(states) == 1) { State state = Iterables.getOnlyElement(states); if (state.isLogicallyInstantaneous()) { beforeGap += getAbstractNodeEventVerticalSize(endBefore, state, endEvents, pack) / 2; } } return beforeGap; }
From source file:gov.nih.nci.firebird.data.InvestigatorProfile.java
/** * Checks if this profile contains an organization association of a specific type. * * @param organization check for this organization * @param type the type of association role to check for * @return true if referenced/*from w w w. j av a2 s.c o m*/ */ boolean containsAssociation(final Organization organization, OrganizationRoleType type) { Set<OrganizationAssociation> associations = getOrganizationAssociations(type); return Iterables.any(associations, new Predicate<OrganizationAssociation>() { @Override public boolean apply(OrganizationAssociation association) { return association.getOrganizationRole().getOrganization().equals(organization); } }); }