List of usage examples for com.google.common.collect Iterables all
public static <T> boolean all(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.eclipse.elk.alg.layered.p5edges.PolylineEdgeRouter.java
/** * {@inheritDoc}/*w w w .j av a 2s . co m*/ */ public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) { monitor.begin("Polyline edge routing", 1); final float nodeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_NODE); final float edgeSpaceFac = layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_SPACING_FACTOR); double xpos = 0.0; double layerSpacing = 0.0; // Determine the horizontal spacing required to route west-side in-layer edges of the first layer if (!layeredGraph.getLayers().isEmpty()) { double yDiff = calculateWestInLayerEdgeYDiff(layeredGraph.getLayers().get(0)); xpos = LAYER_SPACE_FAC * edgeSpaceFac * yDiff; } // Iterate over the layers ListIterator<Layer> layerIter = layeredGraph.getLayers().listIterator(); while (layerIter.hasNext()) { Layer layer = layerIter.next(); boolean externalLayer = Iterables.all(layer, PRED_EXTERNAL_WEST_OR_EAST_PORT); // The rightmost layer is not given any node spacing if it's an external port layer if (externalLayer && xpos > 0) { xpos -= nodeSpacing; } // Set horizontal coordinates for all nodes of the layer LGraphUtil.placeNodesHorizontally(layer, xpos); // While routing edges, we remember the maximum vertical span of any edge between this and // the next layer to insert enough space between the layers to keep the edge slopes from // becoming too steep double maxVertDiff = 0.0; // Iterate over the layer's nodes for (LNode node : layer) { // Calculate the maximal vertical span of output edges. In-layer edges will also be // routed at this point double maxCurrOutputYDiff = 0.0; for (LEdge outgoingEdge : node.getOutgoingEdges()) { double sourcePos = outgoingEdge.getSource().getAbsoluteAnchor().y; double targetPos = outgoingEdge.getTarget().getAbsoluteAnchor().y; if (layer == outgoingEdge.getTarget().getNode().getLayer()) { // In-layer edges require an extra bend point to make them look nice processInLayerEdge(outgoingEdge, xpos, LAYER_SPACE_FAC * edgeSpaceFac * Math.abs(sourcePos - targetPos)); if (outgoingEdge.getSource().getSide() == PortSide.WEST) { // The spacing required for routing in-layer edges on the west side doesn't // contribute anything to the spacing required between this and the next // layer and was already taken into account previously sourcePos = 0; targetPos = 0; } } maxCurrOutputYDiff = Math.max(maxCurrOutputYDiff, Math.abs(targetPos - sourcePos)); } // We currently only handle certain node types. This might change in the future switch (node.getType()) { case NORMAL: case LABEL: case LONG_EDGE: case NORTH_SOUTH_PORT: processNode(node, xpos); break; } maxVertDiff = Math.max(maxVertDiff, maxCurrOutputYDiff); } // Consider the span of west-side in-layer edges of the next layer to be sure to reserve // enough space for routing them during the next iteration if (layerIter.hasNext()) { double yDiff = calculateWestInLayerEdgeYDiff(layerIter.next()); maxVertDiff = Math.max(maxVertDiff, yDiff); layerIter.previous(); } // Determine where next layer should start based on the maximal vertical span of edges // between the two layers layerSpacing = LAYER_SPACE_FAC * edgeSpaceFac * maxVertDiff; if (!externalLayer && layerIter.hasNext()) { layerSpacing += nodeSpacing; } xpos += layer.getSize().x + layerSpacing; } createdJunctionPoints.clear(); // Set the graph's horizontal size layeredGraph.getSize().x = xpos; monitor.done(); }
From source file:org.eclipse.elk.layered.p5edges.PolylineEdgeRouter.java
/** * {@inheritDoc}//w ww. j a v a 2 s .c om */ public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) { monitor.begin("Polyline edge routing", 1); final float nodeSpacing = layeredGraph.getProperty(InternalProperties.SPACING); final float edgeSpaceFac = layeredGraph.getProperty(Properties.EDGE_SPACING_FACTOR); double xpos = 0.0; double layerSpacing = 0.0; // Determine the horizontal spacing required to route west-side in-layer edges of the first layer if (!layeredGraph.getLayers().isEmpty()) { double yDiff = calculateWestInLayerEdgeYDiff(layeredGraph.getLayers().get(0)); xpos = LAYER_SPACE_FAC * edgeSpaceFac * yDiff; } // Iterate over the layers ListIterator<Layer> layerIter = layeredGraph.getLayers().listIterator(); while (layerIter.hasNext()) { Layer layer = layerIter.next(); boolean externalLayer = Iterables.all(layer, PRED_EXTERNAL_WEST_OR_EAST_PORT); // The rightmost layer is not given any node spacing if it's an external port layer if (externalLayer && xpos > 0) { xpos -= nodeSpacing; } // Set horizontal coordinates for all nodes of the layer LGraphUtil.placeNodesHorizontally(layer, xpos); // While routing edges, we remember the maximum vertical span of any edge between this and // the next layer to insert enough space between the layers to keep the edge slopes from // becoming too steep double maxVertDiff = 0.0; // Iterate over the layer's nodes for (LNode node : layer) { // Calculate the maximal vertical span of output edges. In-layer edges will also be // routed at this point double maxCurrOutputYDiff = 0.0; for (LEdge outgoingEdge : node.getOutgoingEdges()) { double sourcePos = outgoingEdge.getSource().getAbsoluteAnchor().y; double targetPos = outgoingEdge.getTarget().getAbsoluteAnchor().y; if (layer == outgoingEdge.getTarget().getNode().getLayer()) { // In-layer edges require an extra bend point to make them look nice processInLayerEdge(outgoingEdge, xpos, LAYER_SPACE_FAC * edgeSpaceFac * Math.abs(sourcePos - targetPos)); if (outgoingEdge.getSource().getSide() == PortSide.WEST) { // The spacing required for routing in-layer edges on the west side doesn't // contribute anything to the spacing required between this and the next // layer and was already taken into account previously sourcePos = 0; targetPos = 0; } } maxCurrOutputYDiff = Math.max(maxCurrOutputYDiff, Math.abs(targetPos - sourcePos)); } // We currently only handle certain node types. This might change in the future switch (node.getType()) { case NORMAL: case LABEL: case LONG_EDGE: case NORTH_SOUTH_PORT: processNode(node, xpos); break; } maxVertDiff = Math.max(maxVertDiff, maxCurrOutputYDiff); } // Consider the span of west-side in-layer edges of the next layer to be sure to reserve // enough space for routing them during the next iteration if (layerIter.hasNext()) { double yDiff = calculateWestInLayerEdgeYDiff(layerIter.next()); maxVertDiff = Math.max(maxVertDiff, yDiff); layerIter.previous(); } // Determine where next layer should start based on the maximal vertical span of edges // between the two layers layerSpacing = LAYER_SPACE_FAC * edgeSpaceFac * maxVertDiff; if (!externalLayer && layerIter.hasNext()) { layerSpacing += nodeSpacing; } xpos += layer.getSize().x + layerSpacing; } createdJunctionPoints.clear(); // Set the graph's horizontal size layeredGraph.getSize().x = xpos; monitor.done(); }
From source file:com.github.scr.hashmap.sets.BufferCharSequenceSet.java
@Override public boolean containsAll(@NotNull Collection<?> c) { return Iterables.all(c, this::contains); }
From source file:kr.debop4j.core.parallelism.AsyncTool.java
/** * {@link java.util.concurrent.FutureTask}? {@link java.util.concurrent.Future#isDone()} * ? {@link java.util.concurrent.Future#isCancelled()} ? . * * @param futureTasks futures/*w w w . j a va 2s. com*/ */ public static <T> void waitAllTasks(final Iterable<? extends Future<T>> futureTasks) throws InterruptedException { boolean allCompleted = false; while (!allCompleted) { allCompleted = Iterables.all(futureTasks, new Predicate<Future<T>>() { @Override public boolean apply(Future<T> input) { assert input != null; return (input.isDone() || input.isCancelled()); } }); if (!allCompleted) Thread.sleep(1); } }
From source file:org.eclipse.sirius.diagram.ui.graphical.edit.policies.SpecificBorderItemSelectionEditPolicy.java
/** * Return the list of existing feedback figures containing in the request. * If the request does not contains feedback figures, an empty list is * returned./* w w w . j ava 2 s. co m*/ * * @param request * The request containing the extended data. * @return the list of existing feedback figures contained in the request. */ @SuppressWarnings("unchecked") private List<IFigure> getBorderNodeFeedbacks(Request request) { Object result = request.getExtendedData().get(BORDER_NODE_FEEDBACKS_KEY); if (result instanceof List<?> && Iterables.all((List<?>) result, Predicates.instanceOf(IFigure.class))) { return (List<IFigure>) result; } else { return new ArrayList<IFigure>(); } }
From source file:kr.debop4j.timeperiod.calendars.CalendarPeriodCollector.java
@Override protected boolean onVisitMonth(MonthRange month, final CalendarPeriodCollectorContext context) { if (isTraceEnabled) log.trace("visit month... month=[{}]", month); if (context.getScope() != CalendarPeriodCollectorContext.CollectKind.Day) return true; if (getFilter().getCollectingDays().size() == 0) { for (DayRange day : month.getDays()) { if (isMatchingDay(day, context) && checkLimits(day)) { periods.add(day);//w w w . j a v a2 s . c om } } } else { for (DayRangeInMonth day : getFilter().getCollectingDays()) { if (day.isSingleDay()) { DayRange dayRange = new DayRange(month.getYear(), month.getMonthOfYear(), day.getStartDayOfMonth(), month.getTimeCalendar()); if (isMatchingDay(dayRange, context) && checkLimits(dayRange)) { periods.add(dayRange); } } else { DayRangeCollection days = new DayRangeCollection(month.getYear(), month.getMonthOfYear(), day.getStartDayOfMonth(), day.getEndDayOfMonth() - day.getStartDayOfMonth(), month.getTimeCalendar()); boolean isMatching = Iterables.all(days.getDays(), new Predicate<DayRange>() { @Override public boolean apply(@Nullable DayRange input) { return isMatchingDay(input, context); } }); if (isMatching && checkLimits(days)) periods.addAll(days.getDays()); } } } return false; }
From source file:org.apache.flex.compiler.internal.abc.ScopedDefinitionTraitsVisitor.java
private static boolean legalDefinitionNsset(Nsset nsSet) { if (nsSet == null) return false; if (nsSet.length() == 1) return true; return Iterables.all(nsSet, new Predicate<Namespace>() { @Override// w w w . j a va 2s . co m public boolean apply(Namespace ns) { return ns.getApiVersion() != ABCConstants.NO_API_VERSION; } }); }
From source file:com.qcadoo.mes.productionPerShift.util.ProgressPerShiftViewSaver.java
private boolean trySaveCorrectionCauses(final ViewDefinitionState view, final Entity ppsEntity) { List<Entity> savedCorrectionCauses = FluentIterable .from(ppsEntity.getHasManyField(ProductionPerShiftFields.PLANNED_PROGRESS_CORRECTION_TYPES)) .transform(SAVE).toList();/* www . j av a 2 s .com*/ ppsEntity.setField(ProductionPerShiftFields.PLANNED_PROGRESS_CORRECTION_TYPES, savedCorrectionCauses); if (Iterables.all(savedCorrectionCauses, IS_VALID)) { return true; } setCorrectionCauses(view, savedCorrectionCauses); showValidationErrors(view, Collections.<ErrorMessage>emptyList()); return false; }
From source file:com.android.tools.idea.avdmanager.HaxmAlert.java
private static HaxmState computeHaxmState() { boolean found = false; try {/*from w w w . j a v a2 s. com*/ if (SystemInfo.isMac) { @SuppressWarnings("SpellCheckingInspection") String output = ExecUtil.execAndReadLine("/usr/sbin/kextstat", "-l", "-b", "com.intel.kext.intelhaxm"); if (output != null && !output.isEmpty()) { Pattern pattern = Pattern.compile("com\\.intel\\.kext\\.intelhaxm( \\((.+)\\))?"); Matcher matcher = pattern.matcher(output); if (matcher.find()) { found = true; } } } else if (SystemInfo.isWindows) { @SuppressWarnings("SpellCheckingInspection") ProcessOutput processOutput = ExecUtil .execAndGetOutput(ImmutableList.of("sc", "query", "intelhaxm"), null); found = Iterables.all(processOutput.getStdoutLines(), new Predicate<String>() { @Override public boolean apply(String input) { return input == null || !input.contains("does not exist"); } }); } else if (SystemInfo.isUnix) { File kvm = new File("/dev/kvm"); return kvm.exists() ? HaxmState.INSTALLED : HaxmState.NOT_INSTALLED; } else { assert !SystemInfo.isLinux; // should be covered by SystemInfo.isUnix return HaxmState.NOT_INSTALLED; } } catch (ExecutionException e) { return HaxmState.NOT_INSTALLED; } if (found) { try { FullRevision revision = Haxm .getInstalledVersion(AndroidSdkUtils.tryToChooseAndroidSdk().getLocation()); FullRevision current = new FullRevision(1, 1, 1); if (revision.compareTo(current) < 0) { // We have the new version number, as well as the currently installed // version number here, which we could use to make a better error message. // However, these versions do not correspond to the version number we show // in the SDK manager (e.g. in the SDK version manager we show "5" // and the corresponding kernel stat version number is 1.1.1. return HaxmState.NOT_LATEST; } } catch (WizardException e) { return HaxmState.NOT_INSTALLED; } return HaxmState.INSTALLED; } return HaxmState.NOT_INSTALLED; }
From source file:org.eclipse.sirius.diagram.ui.internal.refresh.listeners.EdgeLayoutUpdaterModelChangeTrigger.java
/** * Test whether the other notifications are consequences of the given one. * For instance, in case of a manual modification of the Sirius routing * style (from Style tab of Properties view), we also update the GMF style * and we add the routing style within the custom features. This method aims * to check whether we are in the case of an individual modification or a * global one.//from ww w . j ava 2 s.c o m * * @param notification * the notification for which we are notified. * @param gmfEdge * the GMF edge associated to the <code>notification</code> * @param notifications * the whole notification list. * @return true if the notifications list contains only notifications * induced by the first one. */ public boolean otherNotificationsAreConsequences(final Notification notification, final Edge gmfEdge, Collection<Notification> notifications) { boolean otherNotificationsAreIndirectlyConcerned = false; if (notifications.size() == 1 && REFRESH_FEATURES.contains(notifications.iterator().next().getFeature())) { otherNotificationsAreIndirectlyConcerned = true; } else if (REFRESH_FEATURES_WITH_CONSEQUENCE.contains(notification.getFeature())) { otherNotificationsAreIndirectlyConcerned = Iterables.all(notifications, new Predicate<Notification>() { @Override public boolean apply(Notification currentNotification) { boolean considerAsConsequence = false; if (currentNotification == notification) { considerAsConsequence = true; } else { Option<Edge> optionalEdge = getCorrespondingEdge(currentNotification); if (optionalEdge.some()) { considerAsConsequence = optionalEdge.get().equals(gmfEdge) && CONSEQUENCE_FEATURES.contains(currentNotification.getFeature()); } } return considerAsConsequence; } }); } return otherNotificationsAreIndirectlyConcerned; }