Example usage for com.google.common.collect Iterables all

List of usage examples for com.google.common.collect Iterables all

Introduction

In this page you can find the example usage for com.google.common.collect Iterables all.

Prototype

public static <T> boolean all(Iterable<T> iterable, Predicate<? super T> predicate) 

Source Link

Document

Returns true if every element in iterable satisfies the predicate.

Usage

From source file:org.eclipse.elk.layered.p5edges.OrthogonalEdgeRouter.java

/**
 * {@inheritDoc}//  w w  w .j a  v  a 2s .c  om
 */
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Orthogonal edge routing", 1);

    // Retrieve some generic values
    Spacings spacings = layeredGraph.getProperty(InternalProperties.SPACINGS);
    boolean debug = layeredGraph.getProperty(LayoutOptions.DEBUG_MODE);

    // Prepare for iteration!
    OrthogonalRoutingGenerator routingGenerator = new OrthogonalRoutingGenerator(
            OrthogonalRoutingGenerator.RoutingDirection.WEST_TO_EAST, spacings.edgeEdgeSpacing,
            debug ? "phase5" : null);
    float xpos = 0.0f;
    ListIterator<Layer> layerIter = layeredGraph.getLayers().listIterator();
    Layer leftLayer = null;
    Layer rightLayer = null;
    List<LNode> leftLayerNodes = null;
    List<LNode> rightLayerNodes = null;
    int leftLayerIndex = -1;
    int rightLayerIndex = -1;

    // Iterate!
    do {
        int slotsCount;

        // Fetch the next layer, if any
        rightLayer = layerIter.hasNext() ? layerIter.next() : null;
        rightLayerNodes = rightLayer == null ? null : rightLayer.getNodes();
        rightLayerIndex = layerIter.previousIndex();

        // Place the left layer's nodes, if any
        if (leftLayer != null) {
            LGraphUtil.placeNodesHorizontally(leftLayer, xpos);
            xpos += leftLayer.getSize().x;
        }

        // Route edges between the two layers
        double startPos = leftLayer == null ? xpos : xpos + spacings.edgeNodeSpacing;
        slotsCount = routingGenerator.routeEdges(layeredGraph, leftLayerNodes, leftLayerIndex, rightLayerNodes,
                startPos);

        boolean isLeftLayerExternal = leftLayer == null
                || Iterables.all(leftLayerNodes, PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);
        boolean isRightLayerExternal = rightLayer == null
                || Iterables.all(rightLayerNodes, PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);

        if (slotsCount > 0) {
            // The space between each pair of edge segments, and between nodes and edges
            double increment = spacings.edgeNodeSpacing + (slotsCount - 1) * spacings.edgeEdgeSpacing;
            if (rightLayer != null) {
                increment += spacings.edgeNodeSpacing;
            }

            // If we are between two layers, make sure their minimal spacing is preserved
            if (increment < spacings.nodeSpacing && !isLeftLayerExternal && !isRightLayerExternal) {
                increment = spacings.nodeSpacing;
            }
            xpos += increment;
        } else if (!isLeftLayerExternal && !isRightLayerExternal) {
            // If all edges are straight, use the usual spacing 
            xpos += spacings.nodeSpacing;
        }

        leftLayer = rightLayer;
        leftLayerNodes = rightLayerNodes;
        leftLayerIndex = rightLayerIndex;
    } while (rightLayer != null);

    layeredGraph.getSize().x = xpos;

    monitor.done();
}

From source file:org.eclipse.elk.alg.layered.p5edges.OrthogonalEdgeRouter.java

/**
 * {@inheritDoc}/*from   w ww .j a  v  a2  s  . c om*/
 */
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Orthogonal edge routing", 1);

    // Retrieve some generic values
    Spacings spacings = layeredGraph.getProperty(InternalProperties.SPACINGS);
    boolean debug = layeredGraph.getProperty(LayeredOptions.DEBUG_MODE);

    // Prepare for iteration!
    OrthogonalRoutingGenerator routingGenerator = new OrthogonalRoutingGenerator(
            OrthogonalRoutingGenerator.RoutingDirection.WEST_TO_EAST, spacings.edgeEdgeSpacing,
            debug ? "phase5" : null);
    float xpos = 0.0f;
    ListIterator<Layer> layerIter = layeredGraph.getLayers().listIterator();
    Layer leftLayer = null;
    Layer rightLayer = null;
    List<LNode> leftLayerNodes = null;
    List<LNode> rightLayerNodes = null;
    int leftLayerIndex = -1;
    int rightLayerIndex = -1;

    // Iterate!
    do {
        int slotsCount;

        // Fetch the next layer, if any
        rightLayer = layerIter.hasNext() ? layerIter.next() : null;
        rightLayerNodes = rightLayer == null ? null : rightLayer.getNodes();
        rightLayerIndex = layerIter.previousIndex();

        // Place the left layer's nodes, if any
        if (leftLayer != null) {
            LGraphUtil.placeNodesHorizontally(leftLayer, xpos);
            xpos += leftLayer.getSize().x;
        }

        // Route edges between the two layers
        double startPos = leftLayer == null ? xpos : xpos + spacings.edgeNodeSpacing;
        slotsCount = routingGenerator.routeEdges(layeredGraph, leftLayerNodes, leftLayerIndex, rightLayerNodes,
                startPos);

        boolean isLeftLayerExternal = leftLayer == null
                || Iterables.all(leftLayerNodes, PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);
        boolean isRightLayerExternal = rightLayer == null
                || Iterables.all(rightLayerNodes, PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);

        if (slotsCount > 0) {
            // The space between each pair of edge segments, and between nodes and edges
            double increment = spacings.edgeNodeSpacing + (slotsCount - 1) * spacings.edgeEdgeSpacing;
            if (rightLayer != null) {
                increment += spacings.edgeNodeSpacing;
            }

            // If we are between two layers, make sure their minimal spacing is preserved
            if (increment < spacings.nodeSpacing && !isLeftLayerExternal && !isRightLayerExternal) {
                increment = spacings.nodeSpacing;
            }
            xpos += increment;
        } else if (!isLeftLayerExternal && !isRightLayerExternal) {
            // If all edges are straight, use the usual spacing 
            xpos += spacings.nodeSpacing;
        }

        leftLayer = rightLayer;
        leftLayerNodes = rightLayerNodes;
        leftLayerIndex = rightLayerIndex;
    } while (rightLayer != null);

    layeredGraph.getSize().x = xpos;

    monitor.done();
}

From source file:com.qcadoo.mes.productionPerShift.util.ProgressPerShiftViewSaver.java

private List<Entity> validateAndSaveProgresses(final List<Entity> progressForDays,
        final Long technologyOperationId, final boolean hasCorrections) {
    List<Entity> progressWithValidatedDailyProgresses = validateDailyProgresses(progressForDays,
            technologyOperationId, hasCorrections);
    if (Iterables.all(progressWithValidatedDailyProgresses, IS_VALID)) {
        return FluentIterable.from(progressWithValidatedDailyProgresses).transform(SAVE).toList();
    }//from w  w w. j  a va2 s  . co  m
    return progressWithValidatedDailyProgresses;
}

From source file:io.prestosql.sql.planner.EqualityInference.java

private static Predicate<Expression> symbolToExpressionPredicate(final Predicate<Symbol> symbolScope) {
    return expression -> Iterables.all(SymbolsExtractor.extractUnique(expression), symbolScope);
}

From source file:de.cau.cs.kieler.klay.layered.p5edges.splines.SplineEdgeRouter.java

/**
 * {@inheritDoc}//  w w  w.j  a va  2  s . co  m
 */
public void process(final LGraph layeredGraph, final IKielerProgressMonitor monitor) {
    monitor.begin("Spline edge routing", 1);
    // Retrieve some generic values
    final float nodeSpacing = layeredGraph.getProperty(InternalProperties.SPACING);
    edgeSpacing = nodeSpacing * layeredGraph.getProperty(Properties.EDGE_SPACING_FACTOR);
    double xpos = 0.0;

    final Iterator<Layer> layerIterator = layeredGraph.iterator();
    Layer leftLayer = null;
    Layer rightLayer;

    // A mapping pointing from an edge to it's succeeding edge, together with their connected 
    // friends, they form a long-edge.
    final Map<LEdge, LEdge> successingEdge = Maps.newHashMap();

    // a collection of all edges that have a normal node as their source
    final List<LEdge> startEdges = Lists.newArrayList();

    boolean externalLeftLayer = true;
    boolean externalRightLayer = true;

    do {
        rightLayer = layerIterator.hasNext() ? layerIterator.next() : null;

        /////////////////////////////////////
        // Creation of the SplineHyperEdges//
        // some variables we need
        final List<SplineHyperEdge> hyperEdges = Lists.newArrayList();
        final List<LEdge> edgesRemaining = Lists.newArrayList();
        final Set<LPort> leftPorts = Sets.newLinkedHashSet();
        final Set<LPort> rightPorts = Sets.newLinkedHashSet();
        final Set<LEdge> selfLoops = Sets.newLinkedHashSet();

        // fill edgesRemaining and PortToEdgesPairs
        fillMappings(Pair.of(leftLayer, rightLayer), Pair.of(leftPorts, rightPorts), edgesRemaining,
                successingEdge, startEdges, selfLoops);

        // create the hyperEdges having their start port on the left side.
        createHyperEdges(leftPorts, rightPorts, SideToProcess.LEFT, true, edgesRemaining, hyperEdges);
        createHyperEdges(leftPorts, rightPorts, SideToProcess.LEFT, false, edgesRemaining, hyperEdges);

        // create the hyperEdges having their start port on the right side.
        createHyperEdges(leftPorts, rightPorts, SideToProcess.RIGHT, true, edgesRemaining, hyperEdges);
        createHyperEdges(leftPorts, rightPorts, SideToProcess.RIGHT, false, edgesRemaining, hyperEdges);

        // remaining edges are single edges that cannot be combined with others to a hyper-edge
        createHyperEdges(edgesRemaining, leftPorts, rightPorts, hyperEdges);

        ////////////////////////////////////
        // Creation of the dependencies of the SplineHyperEdges
        final ListIterator<SplineHyperEdge> sourceIter = hyperEdges.listIterator();
        while (sourceIter.hasNext()) {
            final SplineHyperEdge hyperEdge1 = sourceIter.next();
            final ListIterator<SplineHyperEdge> targetIter = hyperEdges.listIterator(sourceIter.nextIndex());
            while (targetIter.hasNext()) {
                final SplineHyperEdge hyperEdge2 = targetIter.next();
                createDependency(hyperEdge1, hyperEdge2);
            }
        }

        ////////////////////////////////////
        // Apply the topological numbering//
        // break cycles
        breakCycles(hyperEdges, layeredGraph.getProperty(InternalProperties.RANDOM));

        // assign ranks to the hyper-nodes
        topologicalNumbering(hyperEdges);

        ////////////////////////////////////
        // Place right layers's nodes. This needs to be done before calculating the bendPoints.
        double rightLayersPosition = xpos + NODE_TO_VERTICAL_SEGMENT_GAP;
        if (rightLayer != null) {
            externalRightLayer = rightLayer == null
                    || Iterables.all(rightLayer.getNodes(), PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);

            int maxRank = -1;
            for (final SplineHyperEdge edge : hyperEdges) {
                maxRank = Math.max(maxRank, edge.rank);
            }
            maxRank++;

            if (maxRank > 0) {
                // The space between each pair of edge segments, and between nodes and edges
                double increment = (maxRank + 1) * edgeSpacing;

                // If we are between two layers, make sure their minimal spacing is preserved
                if (increment < nodeSpacing && !externalLeftLayer && !externalRightLayer) {
                    increment = nodeSpacing;
                }
                rightLayersPosition += increment;
            } else if (!(externalLeftLayer || externalRightLayer || layerOnlyContainsDummies(leftLayer)
                    || layerOnlyContainsDummies(rightLayer))) {
                // If all edges are straight, use the usual spacing 
                //   (except when we are between two layers where both only contains dummy nodes)
                rightLayersPosition += nodeSpacing;
            }

            LGraphUtil.placeNodes(rightLayer, rightLayersPosition);
        }

        ////////////////////////////////////
        // Self loops are already calculated. All we have to do is add the node offset
        // to the bend points and the edge labels.
        for (final LEdge selfLoop : selfLoops) {
            final KVector offset = selfLoop.getSource().getNode().getPosition();

            selfLoop.getBendPoints().offset(offset);

            for (final LLabel label : selfLoop.getLabels()) {
                label.getPosition().add(offset);
            }
        }

        ////////////////////////////////////
        // Calculate the NubSpline control points.
        for (final SplineHyperEdge edge : hyperEdges) {
            // SplineHyperEdges that are just straight lines don't need any control-points
            if (edge.isStraight) {
                calculateNUBSBendPointStraight(edge, xpos);
            } else {
                calculateNUBSBendPoints(edge, xpos);
            }
        }

        ////////////////////////////////////
        // proceed to next layer
        if (rightLayer != null) {
            xpos = rightLayersPosition + rightLayer.getSize().x + NODE_TO_VERTICAL_SEGMENT_GAP;
        }
        leftLayer = rightLayer;
        externalLeftLayer = externalRightLayer;

    } while (rightLayer != null);

    ////////////////////////////////////
    // all layers are processed, now we can calculate the bezier bend-points for all edges
    for (final LEdge edge : startEdges) {
        calculateBezierBendPoints(edge, successingEdge);
    }

    layeredGraph.getSize().x = xpos;
    monitor.done();
}

From source file:jenkins.plugins.office365connector.Office365ConnectorWebhookNotifier.java

private void addScmDetails() {
    Set<User> users;//from ww w  .j a v  a2s  .c om
    List<ChangeLogSet<ChangeLogSet.Entry>> sets;

    try {
        users = (Set<User>) run.getClass().getMethod("getCulprits").invoke(run);
        sets = (List<ChangeLogSet<ChangeLogSet.Entry>>) run.getClass().getMethod("getChangeSets").invoke(run);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        users = Collections.emptySet();
        sets = Collections.emptyList();
    }

    factsBuilder.addCulprits(users);

    if (!sets.isEmpty()) {
        Set<User> authors = new HashSet<>();
        int filesCounter = 0;
        if (Iterables.all(sets, Predicates.instanceOf(ChangeLogSet.class))) {
            for (ChangeLogSet<ChangeLogSet.Entry> set : sets) {
                for (ChangeLogSet.Entry entry : set) {
                    authors.add(entry.getAuthor());
                    filesCounter += getAffectedFiles(entry).size();
                }
            }
        }
        factsBuilder.addDevelopers(authors);
        factsBuilder.addNumberOfFilesChanged(filesCounter);
    }
}

From source file:org.eclipse.elk.layered.p5edges.splines.SplineEdgeRouter.java

/**
 * {@inheritDoc}/*from   w ww.j  ava2  s  .  c  o m*/
 */
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Spline edge routing", 1);
    // Retrieve some generic values
    final float nodeSpacing = layeredGraph.getProperty(InternalProperties.SPACING);
    edgeSpacing = nodeSpacing * layeredGraph.getProperty(Properties.EDGE_SPACING_FACTOR);
    double xpos = 0.0;

    final Iterator<Layer> layerIterator = layeredGraph.iterator();
    Layer leftLayer = null;
    Layer rightLayer;

    // A mapping pointing from an edge to it's succeeding edge, together with their connected 
    // friends, they form a long-edge.
    final Map<LEdge, LEdge> successingEdge = Maps.newHashMap();

    // a collection of all edges that have a normal node as their source
    final List<LEdge> startEdges = Lists.newArrayList();

    boolean externalLeftLayer = true;
    boolean externalRightLayer = true;

    do {
        rightLayer = layerIterator.hasNext() ? layerIterator.next() : null;

        /////////////////////////////////////
        // Creation of the SplineHyperEdges//
        // some variables we need
        final List<SplineHyperEdge> hyperEdges = Lists.newArrayList();
        final List<LEdge> edgesRemaining = Lists.newArrayList();
        final Set<LPort> leftPorts = Sets.newLinkedHashSet();
        final Set<LPort> rightPorts = Sets.newLinkedHashSet();
        final Set<LEdge> selfLoops = Sets.newLinkedHashSet();

        // fill edgesRemaining and PortToEdgesPairs
        fillMappings(Pair.of(leftLayer, rightLayer), Pair.of(leftPorts, rightPorts), edgesRemaining,
                successingEdge, startEdges, selfLoops);

        // create the hyperEdges having their start port on the left side.
        createHyperEdges(leftPorts, rightPorts, SideToProcess.LEFT, true, edgesRemaining, hyperEdges);
        createHyperEdges(leftPorts, rightPorts, SideToProcess.LEFT, false, edgesRemaining, hyperEdges);

        // create the hyperEdges having their start port on the right side.
        createHyperEdges(leftPorts, rightPorts, SideToProcess.RIGHT, true, edgesRemaining, hyperEdges);
        createHyperEdges(leftPorts, rightPorts, SideToProcess.RIGHT, false, edgesRemaining, hyperEdges);

        // remaining edges are single edges that cannot be combined with others to a hyper-edge
        createHyperEdges(edgesRemaining, leftPorts, rightPorts, hyperEdges);

        ////////////////////////////////////
        // Creation of the dependencies of the SplineHyperEdges
        final ListIterator<SplineHyperEdge> sourceIter = hyperEdges.listIterator();
        while (sourceIter.hasNext()) {
            final SplineHyperEdge hyperEdge1 = sourceIter.next();
            final ListIterator<SplineHyperEdge> targetIter = hyperEdges.listIterator(sourceIter.nextIndex());
            while (targetIter.hasNext()) {
                final SplineHyperEdge hyperEdge2 = targetIter.next();
                createDependency(hyperEdge1, hyperEdge2);
            }
        }

        ////////////////////////////////////
        // Apply the topological numbering//
        // break cycles
        breakCycles(hyperEdges, layeredGraph.getProperty(InternalProperties.RANDOM));

        // assign ranks to the hyper-nodes
        topologicalNumbering(hyperEdges);

        ////////////////////////////////////
        // Place right layers's nodes. This needs to be done before calculating the bendPoints.
        double rightLayersPosition = xpos + NODE_TO_VERTICAL_SEGMENT_GAP;
        if (rightLayer != null) {
            externalRightLayer = rightLayer == null
                    || Iterables.all(rightLayer.getNodes(), PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);

            int maxRank = -1;
            for (final SplineHyperEdge edge : hyperEdges) {
                maxRank = Math.max(maxRank, edge.rank);
            }
            maxRank++;

            if (maxRank > 0) {
                // The space between each pair of edge segments, and between nodes and edges
                double increment = (maxRank + 1) * edgeSpacing;

                // If we are between two layers, make sure their minimal spacing is preserved
                if (increment < nodeSpacing && !externalLeftLayer && !externalRightLayer) {
                    increment = nodeSpacing;
                }
                rightLayersPosition += increment;
            } else if (!(externalLeftLayer || externalRightLayer || layerOnlyContainsDummies(leftLayer)
                    || layerOnlyContainsDummies(rightLayer))) {
                // If all edges are straight, use the usual spacing 
                //   (except when we are between two layers where both only contains dummy nodes)
                rightLayersPosition += nodeSpacing;
            }

            LGraphUtil.placeNodesHorizontally(rightLayer, rightLayersPosition);
        }

        ////////////////////////////////////
        // Self loops are already calculated. All we have to do is add the node offset
        // to the bend points and the edge labels.
        for (final LEdge selfLoop : selfLoops) {
            final KVector offset = selfLoop.getSource().getNode().getPosition();

            selfLoop.getBendPoints().offset(offset);

            for (final LLabel label : selfLoop.getLabels()) {
                label.getPosition().add(offset);
            }
        }

        ////////////////////////////////////
        // Calculate the NubSpline control points.
        for (final SplineHyperEdge edge : hyperEdges) {
            // SplineHyperEdges that are just straight lines don't need any control-points
            if (edge.isStraight) {
                calculateNUBSBendPointStraight(edge, xpos);
            } else {
                calculateNUBSBendPoints(edge, xpos, rightLayersPosition);
            }
        }

        ////////////////////////////////////
        // proceed to next layer
        if (rightLayer != null) {
            xpos = rightLayersPosition + rightLayer.getSize().x + NODE_TO_VERTICAL_SEGMENT_GAP;
        } else {
            // When handling the last layer
            // add spacing for the last routing area after the node
            // Calculation taken from inter layer spacing calculation
            int maxRank = -1;
            for (final SplineHyperEdge edge : hyperEdges) {
                maxRank = Math.max(maxRank, edge.rank);
            }
            if (maxRank >= 0) {
                xpos += (maxRank + 2) * edgeSpacing;
            }
        }
        leftLayer = rightLayer;
        externalLeftLayer = externalRightLayer;

    } while (rightLayer != null);

    ////////////////////////////////////
    // all layers are processed, now we can calculate the bezier bend-points for all edges
    for (final LEdge edge : startEdges) {
        calculateBezierBendPoints(edge, successingEdge);
    }

    layeredGraph.getSize().x = xpos;
    monitor.done();
}

From source file:com.eucalyptus.blockstorage.SnapshotManager.java

public DeleteSnapshotResponseType delete(final DeleteSnapshotType request) throws EucalyptusCloudException {
    final DeleteSnapshotResponseType reply = (DeleteSnapshotResponseType) request.getReply();
    final Context ctx = Contexts.lookup();
    final String snapshotId = normalizeSnapshotIdentifier(request.getSnapshotId());
    Predicate<Snapshot> deleteSnapshot = new Predicate<Snapshot>() {

        @Override//  ww w.j  a  v  a2s.c o m
        public boolean apply(Snapshot snap) {
            if (!State.EXTANT.equals(snap.getState()) && !State.FAIL.equals(snap.getState())) {
                return false;
            } else if (!RestrictedTypes.filterPrivileged().apply(snap)) {
                throw Exceptions.toUndeclared(new EucalyptusCloudException("Not authorized to delete snapshot "
                        + request.getSnapshotId() + " by " + ctx.getUser().getName()));
            } else if (isReservedSnapshot(snapshotId)) {
                throw Exceptions.toUndeclared(new EucalyptusCloudException(
                        "Snapshot " + request.getSnapshotId() + " is in use, deletion not permitted"));
            } else {
                fireUsageEvent(snap, SnapShotEvent.forSnapShotDelete());
                final String partition = snap.getPartition();
                final String snapshotId = snap.getDisplayName();
                Callable<Boolean> deleteBroadcast = new Callable<Boolean>() {
                    public Boolean call() {
                        final DeleteStorageSnapshotType deleteMsg = new DeleteStorageSnapshotType(snapshotId);
                        return Iterables.all(Topology.enabledServices(Storage.class),
                                new Predicate<ServiceConfiguration>() {

                                    @Override
                                    public boolean apply(ServiceConfiguration arg0) {
                                        if (!arg0.getPartition().equals(partition)) {
                                            try {
                                                AsyncRequests.sendSync(arg0, deleteMsg);
                                            } catch (Exception ex) {
                                                LOG.error(ex);
                                                Logs.extreme().error(ex, ex);
                                            }
                                        }
                                        return true;
                                    }
                                });
                    }
                };

                ServiceConfiguration sc = null;
                try {
                    sc = Topology.lookup(Storage.class, Partitions.lookupByName(snap.getPartition()));
                } catch (final Exception ex) {
                    sc = null;
                }
                if (sc != null) {
                    try {
                        DeleteStorageSnapshotResponseType scReply = AsyncRequests.sendSync(sc,
                                new DeleteStorageSnapshotType(snap.getDisplayName()));
                        if (scReply.get_return()) {
                            Threads.enqueue(Eucalyptus.class, Snapshots.class, deleteBroadcast);
                        } else {
                            throw Exceptions.toUndeclared(
                                    new EucalyptusCloudException("Unable to delete snapshot: " + snap));
                        }
                    } catch (Exception ex1) {
                        throw Exceptions.toUndeclared(ex1.getMessage(), ex1);
                    }
                } else {
                    Threads.enqueue(Eucalyptus.class, Snapshots.class, deleteBroadcast);
                }
                return true;
            }
        }
    };
    boolean result = false;
    try {
        result = Transactions.delete(Snapshot.named(ctx.getUserFullName().asAccountFullName(), snapshotId),
                deleteSnapshot);
    } catch (NoSuchElementException ex2) {
        try {
            result = Transactions.delete(Snapshot.named(null, snapshotId), deleteSnapshot);
        } catch (ExecutionException ex3) {
            throw new EucalyptusCloudException(ex3.getCause());
        } catch (NoSuchElementException ex4) {
            throw new ClientComputeException("InvalidSnapshot.NotFound",
                    "The snapshot '" + request.getSnapshotId() + "' does not exist.");
        }
    } catch (ExecutionException ex1) {
        throw new EucalyptusCloudException(ex1.getCause());
    }
    reply.set_return(result);
    return reply;
}

From source file:org.eclipse.che.ide.actions.DeleteItemAction.java

/** {@inheritDoc} */
@Override//from   w  ww  .  j  a  va  2  s  . c  om
public void updateInPerspective(@NotNull ActionEvent event) {
    event.getPresentation().setVisible(true);

    final Selection<?> selection = selectionAgent.getSelection();

    if (selection == null || selection.isEmpty()) {
        event.getPresentation().setEnabled(false);
        return;
    }

    boolean enable = Iterables.all(selection.getAllElements(), isResourceBasedNode());

    event.getPresentation().setEnabled(enable && appContext.getCurrentUser().isUserPermanent());
}

From source file:org.eclipse.elk.alg.layered.p5edges.splines.SplineEdgeRouter.java

/**
 * {@inheritDoc}/*from  w w  w .  ja  va  2s  .c om*/
 */
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Spline edge routing", 1);
    // Retrieve some generic values
    final float nodeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_NODE);
    edgeSpacing = nodeSpacing * layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_SPACING_FACTOR);
    double xpos = 0.0;

    final Iterator<Layer> layerIterator = layeredGraph.iterator();
    Layer leftLayer = null;
    Layer rightLayer;

    // A mapping pointing from an edge to it's succeeding edge, together with their connected 
    // friends, they form a long-edge.
    final Map<LEdge, LEdge> successingEdge = Maps.newHashMap();

    // a collection of all edges that have a normal node as their source
    final List<LEdge> startEdges = Lists.newArrayList();

    boolean externalLeftLayer = true;
    boolean externalRightLayer = true;

    do {
        rightLayer = layerIterator.hasNext() ? layerIterator.next() : null;

        /////////////////////////////////////
        // Creation of the SplineHyperEdges//
        // some variables we need
        final List<SplineHyperEdge> hyperEdges = Lists.newArrayList();
        final List<LEdge> edgesRemaining = Lists.newArrayList();
        final Set<LPort> leftPorts = Sets.newLinkedHashSet();
        final Set<LPort> rightPorts = Sets.newLinkedHashSet();
        final Set<LEdge> selfLoops = Sets.newLinkedHashSet();

        // fill edgesRemaining and PortToEdgesPairs
        fillMappings(Pair.of(leftLayer, rightLayer), Pair.of(leftPorts, rightPorts), edgesRemaining,
                successingEdge, startEdges, selfLoops);

        // create the hyperEdges having their start port on the left side.
        createHyperEdges(leftPorts, rightPorts, SideToProcess.LEFT, true, edgesRemaining, hyperEdges);
        createHyperEdges(leftPorts, rightPorts, SideToProcess.LEFT, false, edgesRemaining, hyperEdges);

        // create the hyperEdges having their start port on the right side.
        createHyperEdges(leftPorts, rightPorts, SideToProcess.RIGHT, true, edgesRemaining, hyperEdges);
        createHyperEdges(leftPorts, rightPorts, SideToProcess.RIGHT, false, edgesRemaining, hyperEdges);

        // remaining edges are single edges that cannot be combined with others to a hyper-edge
        createHyperEdges(edgesRemaining, leftPorts, rightPorts, hyperEdges);

        ////////////////////////////////////
        // Creation of the dependencies of the SplineHyperEdges
        final ListIterator<SplineHyperEdge> sourceIter = hyperEdges.listIterator();
        while (sourceIter.hasNext()) {
            final SplineHyperEdge hyperEdge1 = sourceIter.next();
            final ListIterator<SplineHyperEdge> targetIter = hyperEdges.listIterator(sourceIter.nextIndex());
            while (targetIter.hasNext()) {
                final SplineHyperEdge hyperEdge2 = targetIter.next();
                createDependency(hyperEdge1, hyperEdge2);
            }
        }

        ////////////////////////////////////
        // Apply the topological numbering//
        // break cycles
        breakCycles(hyperEdges, layeredGraph.getProperty(InternalProperties.RANDOM));

        // assign ranks to the hyper-nodes
        topologicalNumbering(hyperEdges);

        ////////////////////////////////////
        // Place right layers's nodes. This needs to be done before calculating the bendPoints.
        double rightLayersPosition = xpos + NODE_TO_VERTICAL_SEGMENT_GAP;
        if (rightLayer != null) {
            externalRightLayer = rightLayer == null
                    || Iterables.all(rightLayer.getNodes(), PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);

            int maxRank = -1;
            for (final SplineHyperEdge edge : hyperEdges) {
                maxRank = Math.max(maxRank, edge.rank);
            }
            maxRank++;

            if (maxRank > 0) {
                // The space between each pair of edge segments, and between nodes and edges
                double increment = (maxRank + 1) * edgeSpacing;

                // If we are between two layers, make sure their minimal spacing is preserved
                if (increment < nodeSpacing && !externalLeftLayer && !externalRightLayer) {
                    increment = nodeSpacing;
                }
                rightLayersPosition += increment;
            } else if (!(externalLeftLayer || externalRightLayer || layerOnlyContainsDummies(leftLayer)
                    || layerOnlyContainsDummies(rightLayer))) {
                // If all edges are straight, use the usual spacing 
                //   (except when we are between two layers where both only contains dummy nodes)
                rightLayersPosition += nodeSpacing;
            }

            LGraphUtil.placeNodesHorizontally(rightLayer, rightLayersPosition);
        }

        ////////////////////////////////////
        // Self loops are already calculated. All we have to do is add the node offset
        // to the bend points and the edge labels.
        for (final LEdge selfLoop : selfLoops) {
            final KVector offset = selfLoop.getSource().getNode().getPosition();

            selfLoop.getBendPoints().offset(offset);

            for (final LLabel label : selfLoop.getLabels()) {
                label.getPosition().add(offset);
            }
        }

        ////////////////////////////////////
        // Calculate the NubSpline control points.
        for (final SplineHyperEdge edge : hyperEdges) {
            // SplineHyperEdges that are just straight lines don't need any control-points
            if (edge.isStraight) {
                calculateNUBSBendPointStraight(edge, xpos);
            } else {
                calculateNUBSBendPoints(edge, xpos, rightLayersPosition);
            }
        }

        ////////////////////////////////////
        // proceed to next layer
        if (rightLayer != null) {
            xpos = rightLayersPosition + rightLayer.getSize().x + NODE_TO_VERTICAL_SEGMENT_GAP;
        } else {
            // When handling the last layer
            // add spacing for the last routing area after the node
            // Calculation taken from inter layer spacing calculation
            int maxRank = -1;
            for (final SplineHyperEdge edge : hyperEdges) {
                maxRank = Math.max(maxRank, edge.rank);
            }
            if (maxRank >= 0) {
                xpos += (maxRank + 2) * edgeSpacing;
            }
        }
        leftLayer = rightLayer;
        externalLeftLayer = externalRightLayer;

    } while (rightLayer != null);

    ////////////////////////////////////
    // all layers are processed, now we can calculate the bezier bend-points for all edges
    for (final LEdge edge : startEdges) {
        calculateBezierBendPoints(edge, successingEdge);
    }

    layeredGraph.getSize().x = xpos;
    monitor.done();
}