Example usage for com.google.common.collect UnmodifiableIterator next

List of usage examples for com.google.common.collect UnmodifiableIterator next

Introduction

In this page you can find the example usage for com.google.common.collect UnmodifiableIterator next.

Prototype

E next();

Source Link

Document

Returns the next element in the iteration.

Usage

From source file:org.eclipse.sirius.diagram.ui.tools.internal.actions.pinning.AbstractPinUnpinElementsEclipseAction.java

/**
 * Get current selected diagram elements.
 * //from ww  w  .  ja v  a 2s. c om
 * @param selection
 *            Selection
 * @return Selected elements.
 */
private Collection<DDiagramElement> getSelectedDiagramElements(final ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        final UnmodifiableIterator<IGraphicalEditPart> iter = Iterators
                .filter(((IStructuredSelection) selection).iterator(), IGraphicalEditPart.class);
        final Collection<DDiagramElement> elements = Lists.newArrayList();
        while (iter.hasNext()) {
            final IGraphicalEditPart part = iter.next();

            if (keepElement(part)) {
                final EObject semanticElement = part.resolveSemanticElement();
                if (semanticElement instanceof DDiagramElement) {
                    elements.add((DDiagramElement) semanticElement);
                }
            }
        }
        return elements;
    }
    return Collections.emptyList();
}

From source file:org.obeonetwork.dsl.uml2.design.internal.triggers.AutosizeTrigger.java

public Option<Command> localChangesAboutToCommit(Collection<Notification> notifications) {
    final Collection<Node> toMakeAutosize = Sets.newLinkedHashSet();
    for (final Notification notif : notifications) {
        final Node nd = (Node) notif.getNewValue();
        if (nd.getElement() instanceof DSemanticDecorator) {
            final EObject semanticObject = ((DSemanticDecorator) nd.getElement()).getTarget();
            final UnmodifiableIterator<Adapter> filter = Iterators.filter(semanticObject.eAdapters().iterator(),
                    new Predicate<Adapter>() {
                        public boolean apply(Adapter input) {
                            return input == AUTO_SIZE_MARKER;
                        }/*  ww  w .  j av  a 2s .co  m*/
                    });

            if (filter.hasNext()) {
                semanticObject.eAdapters().remove(filter.next());
                toMakeAutosize.add(nd);
            }

        }
    }
    if (toMakeAutosize.size() > 0) {
        final Command result = new RecordingCommand(domain) {

            @Override
            protected void doExecute() {
                for (final Node node : toMakeAutosize) {
                    if (node.getLayoutConstraint() instanceof Bounds) {
                        ((Bounds) node.getLayoutConstraint()).setWidth(-1);
                        ((Bounds) node.getLayoutConstraint()).setHeight(-1);
                    }
                }
            }
        };
        return Options.newSome(result);
    }
    return Options.newNone();
}

From source file:org.elasticsearch.action.bench.BenchmarkExecutor.java

/**
 * Reports status of all active benchmarks
 *
 * @return  Benchmark status response/*from  ww w. ja  v  a2  s .  co  m*/
 */
public BenchmarkStatusNodeResponse benchmarkStatus() {

    BenchmarkStatusNodeResponse response = new BenchmarkStatusNodeResponse();
    final ImmutableOpenMap<String, BenchmarkState> activeBenchmarks = this.activeBenchmarks;
    UnmodifiableIterator<String> iter = activeBenchmarks.keysIt();
    while (iter.hasNext()) {
        String id = iter.next();
        BenchmarkState state = activeBenchmarks.get(id);
        response.addBenchResponse(state.response);
    }

    logger.debug("Reporting [{}] active benchmarks on [{}]", response.activeBenchmarks(), nodeName());
    return response;
}

From source file:org.eclipse.emf.ecoretools.design.service.AutosizeTrigger.java

public Option<Command> localChangesAboutToCommit(Collection<Notification> notifications) {
    final Collection<Node> toMakeAutosize = Sets.newLinkedHashSet();
    for (Notification notif : notifications) {
        Node nd = (Node) notif.getNewValue();
        if (nd.getElement() instanceof DSemanticDecorator) {
            EObject semanticObject = ((DSemanticDecorator) nd.getElement()).getTarget();
            if (semanticObject instanceof EObject) {
                UnmodifiableIterator<Adapter> filter = Iterators.filter(semanticObject.eAdapters().iterator(),
                        new Predicate<Adapter>() {
                            public boolean apply(Adapter input) {
                                return input == AUTO_SIZE_MARKER;
                            }/*from www  .j a va 2s  . c  o m*/
                        });

                if (filter.hasNext()) {
                    semanticObject.eAdapters().remove(filter.next());
                    toMakeAutosize.add(nd);
                }
            }
        }
    }
    if (toMakeAutosize.size() > 0) {
        Command result = new RecordingCommand(domain) {

            @Override
            protected void doExecute() {
                for (Node node : toMakeAutosize) {
                    if (node.getLayoutConstraint() instanceof Bounds) {
                        ((Bounds) node.getLayoutConstraint()).setWidth(-1);
                        ((Bounds) node.getLayoutConstraint()).setHeight(-1);
                    }
                }
            }
        };
        return Options.newSome(result);
    }
    return Options.newNone();
}

From source file:org.voltdb.ElasticHashinator.java

/**
 * Find the predecessors of the given partition on the ring. This method runs in linear time,
 * use with caution when the set of partitions is large.
 * @param partition//from www. jav  a2  s.c o  m
 * @return The map of tokens to partitions that are the predecessors of the given partition.
 * If the given partition doesn't exist or it's the only partition on the ring, the
 * map will be empty.
 */
@Override
protected Map<Long, Integer> pPredecessors(int partition) {
    Map<Long, Integer> predecessors = new TreeMap<Long, Integer>();
    UnmodifiableIterator<Map.Entry<Long, Integer>> iter = tokens.entrySet().iterator();
    Set<Long> pTokens = new HashSet<Long>();
    while (iter.hasNext()) {
        Map.Entry<Long, Integer> next = iter.next();
        if (next.getValue() == partition) {
            pTokens.add(next.getKey());
        }
    }

    for (Long token : pTokens) {
        Map.Entry<Long, Integer> predecessor = null;
        if (token != null) {
            predecessor = tokens.headMap(token).lastEntry();
            // If null, it means partition is the first one on the ring, so predecessor
            // should be the last entry on the ring because it wraps around.
            if (predecessor == null) {
                predecessor = tokens.lastEntry();
            }
        }

        if (predecessor != null && predecessor.getValue() != partition) {
            predecessors.put(predecessor.getKey(), predecessor.getValue());
        }
    }

    return predecessors;
}

From source file:com.modusoperandi.dragonfly.server.elasticsearch.interfaces.RestEndpoint.java

private String getIndexMapping(String indexName) {

    try {// ww w  .  j  a v  a 2 s  . co  m

        final StringWriter output = new StringWriter();
        try (JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output)) {
            jsonGenerator.setPrettyPrinter(new DefaultPrettyPrinter());

            jsonGenerator.writeStartObject();

            final ImmutableOpenMap<String, MappingMetaData> typeMappings = esGetMappings(indexName);

            final UnmodifiableIterator<MappingMetaData> it = typeMappings.valuesIt();
            while (it.hasNext()) {
                final MappingMetaData mapping = it.next();

                jsonGenerator.writeObjectFieldStart(mapping.type());
                jsonGenerator.writeObjectFieldStart("properties");

                @SuppressWarnings("unchecked")
                final Map<String, Object> fields = ((Map<String, Object>) mapping.getSourceAsMap()
                        .get("properties"));

                for (Map.Entry<String, Object> field : fields.entrySet()) {

                    jsonGenerator.writeObjectFieldStart(field.getKey());

                    @SuppressWarnings("unchecked")
                    Map<String, Object> fieldInfoMap = (Map<String, Object>) field.getValue();
                    for (Map.Entry<String, Object> fieldInfo : fieldInfoMap.entrySet()) {
                        jsonGenerator.writeStringField(fieldInfo.getKey(), fieldInfo.getValue().toString());
                    }

                    jsonGenerator.writeEndObject();
                }

                jsonGenerator.writeEndObject();
            }

            jsonGenerator.writeEndObject();
            jsonGenerator.writeEndObject();

            jsonGenerator.flush();
        }

        return output.toString();

    } catch (IOException ex) {
        LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
    }

    return "[]";
}

From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.design.nodes.controllers.DefaultNodesController.java

private void toggleNodeType(final NormalWord name,
        final Iterable<? extends Class<? extends FunctionalNode>> types) {
    final Node node = this.system.getNode(name);

    final UnmodifiableIterator<? extends Class<? extends FunctionalNode>> cyclicUnmodifiableIterator = Iterators
            .unmodifiableIterator(types.iterator());
    Optional<?> visited = Optional.absent();
    while (cyclicUnmodifiableIterator.hasNext()) {
        final Class<? extends Node> type = cyclicUnmodifiableIterator.next();
        if (type.isAssignableFrom(node.getClass())) {
            this.system.changeNode(name, cyclicUnmodifiableIterator.next());
            return;
        }//from   w w  w. ja  va2s.co m

        if (visited.isPresent()) {
            return;
        } else {
            visited = Optional.of(type);
        }
    }
}

From source file:edu.umn.msi.tropix.proteomics.conversion.impl.MzXMLToMGFConverterStreamingImpl.java

private void write(UnmodifiableIterator<Scan> scans, final OutputStream stream,
        final MgfConversionOptions options, boolean writeHeader) {
    final MgfScanWriter scanWriter = MgfScanWriterFactory.get(stream, options);
    if (writeHeader) {
        final Formatter formatter = new Formatter(stream);
        formatter.format("COM=Conversion to mascot generic%s", NEWLINE);
        formatter.format("CHARGE=2+ and 3+%s", NEWLINE);
        formatter.flush();//from   ww w .  j  a v  a2  s. c  om
    }
    while (scans.hasNext()) {
        final Scan scan = scans.next();
        checkNotNull(scan.getNumber(), "Scan number not found for a scan");
        scanWriter.writeScan(scan);
    }
}

From source file:org.comtel2000.opcua.client.service.OpcUaClientConnector.java

public CompletableFuture<Void> unsubscribeAll() {
    OpcUaClient c = client.get();//w ww .  j  a  v  a 2  s  .  c  o m
    if (c == null) {
        return buildCompleteExceptionally(Void.class, new IOException("not connected"));
    }

    UnmodifiableIterator<UaSubscription> it = c.getSubscriptionManager().getSubscriptions().iterator();
    List<CompletableFuture<UaSubscription>> futures = new ArrayList<>();
    while (it.hasNext()) {
        futures.add(unsubscribe(it.next()));
    }

    return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));

}

From source file:net.sf.e4ftrace.ui.model.TraceModelImplFactory.java

public TraceImpl[] createFTraces(TraceService traceService, URI uri) throws ExecutionException {

    ImmutableTable<Integer, Short, ITrace> data = traceService.fetch(uri, 0);

    UnmodifiableIterator<Integer> it = data.rowKeySet().iterator();

    ArrayList<TraceImpl> rList = Lists.<TraceImpl>newArrayList();

    Random random = new Random();

    /* While Tasks */
    while (it.hasNext()) {

        int atomId = it.next();

        String name = TraceBiMap.getStringValue(atomId);

        ImmutableMap<Short, ITrace> traces = data.row(atomId);

        UnmodifiableIterator<Short> ck = traces.keySet().iterator();

        /* While Cores */
        while (ck.hasNext()) {

            short cpuid = ck.next();
            ITrace trace = traces.get(cpuid);

            TraceImpl traceImpl = new TraceImpl(name, name);

            Iterator<IEvent> ei = trace.getEventsIterator();

            long prevStamp = 0;
            EventImpl prevEventImpl = null;
            TreeSet<Long> tsSet = Sets.<Long>newTreeSet();

            /* While Events */
            while (ei.hasNext()) {

                IEvent event = ei.next();

                long timestamp = event.getTime();

                tsSet.add(timestamp);/* w w  w.  j av  a2 s. co m*/

                int type = random.nextInt(8) % 7;

                EventImpl eventImpl = new EventImpl(timestamp, traceImpl, getEventType(type));

                if (prevStamp != 0) {

                    long duration = timestamp - prevStamp;

                    prevEventImpl.setDuration(duration);

                    traceImpl.addTraceEvent(prevEventImpl);
                }

                prevStamp = timestamp;
                prevEventImpl = eventImpl;

            }

            long timeStart = tsSet.first();
            long timeEnd = tsSet.last();
            traceImpl.setStartTime(timeStart);
            traceImpl.setStopTime(timeEnd);

            rList.add(traceImpl);
        }
    }

    TraceImpl[] ra = rList.toArray(new TraceImpl[rList.size()]);

    return ra;

}