Example usage for com.google.common.collect Iterators concat

List of usage examples for com.google.common.collect Iterators concat

Introduction

In this page you can find the example usage for com.google.common.collect Iterators concat.

Prototype

public static <T> Iterator<T> concat(Iterator<? extends T> a, Iterator<? extends T> b) 

Source Link

Document

Combines two iterators into a single iterator.

Usage

From source file:org.eclipse.sirius.properties.core.internal.expressions.PropertiesInterpretedExpressionQuery.java

/**
 * return true if the given EObject is from PropertiesPackage or inherits
 * from one of the EClasses of PropertiesPackage.
 * /*from w  w w  .j  a v  a 2 s  .  c  o m*/
 * @param object
 *            any EObject
 * @return true if the given EObject is from PropertiesPackage or inherits
 *         from one of the EClasses of PropertiesPackage
 */
private boolean isFromOrInheritsPropertiesEPackage(EObject object) {
    boolean isPropertiesElement = false;
    Iterator<EClass> it = Iterators.concat(Iterators.singletonIterator(object.eClass()),
            object.eClass().getEAllSuperTypes().iterator());
    while (!isPropertiesElement && it.hasNext()) {
        isPropertiesElement = it.next().getEPackage() == PropertiesPackage.eINSTANCE;
    }
    return isPropertiesElement;
}

From source file:org.eclipse.xtext.validation.impl.ConcreteSyntaxConstraintProvider.java

protected boolean containsRelevantElement(AbstractElement ele) {
    Iterator<EObject> i = Iterators.concat(Collections.singleton(ele).iterator(), ele.eAllContents());
    while (i.hasNext()) {
        EObject o = i.next();//from w  w  w . j a va 2  s .c  o m
        if (o instanceof Action || o instanceof Assignment)
            return true;
        if (o instanceof RuleCall && containsRelevantElement(((RuleCall) o).getRule().getAlternatives()))
            return true;
    }
    return false;
}

From source file:org.pshdl.model.impl.AbstractHDLSwitchCaseStatement.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override/*from w w w . j a v a  2 s  .c  o m*/
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if (label != null) {
                        current = Iterators.concat(Iterators.forArray(label), label.deepIterator());
                    }
                    break;
                case 1:
                    if ((dos != null) && (dos.size() != 0)) {
                        final List<Iterator<? extends IHDLObject>> iters = Lists
                                .newArrayListWithCapacity(dos.size());
                        for (final HDLStatement o : dos) {
                            iters.add(Iterators.forArray(o));
                            iters.add(o.deepIterator());
                        }
                        current = Iterators.concat(iters.iterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:org.pshdl.model.impl.AbstractHDLRange.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override/*w  w w. j  a va2s . c  om*/
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if (from != null) {
                        current = Iterators.concat(Iterators.forArray(from), from.deepIterator());
                    }
                    break;
                case 1:
                    if (inc != null) {
                        current = Iterators.concat(Iterators.forArray(inc), inc.deepIterator());
                    }
                    break;
                case 2:
                    if (dec != null) {
                        current = Iterators.concat(Iterators.forArray(dec), dec.deepIterator());
                    }
                    break;
                case 3:
                    if (to != null) {
                        current = Iterators.concat(Iterators.forArray(to), to.deepIterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:com.twitter.common.args.apt.Configuration.java

private static ConfigurationResources getAllResources() throws IOException {
    int maxResourceIndex = 0;
    Iterator<URL> allResources = getResources(0); // Try for a main
    // Probe for resource files with index up to 10 (or more, while resources at the
    // given index can be found)
    for (int nextResourceIndex = 1; nextResourceIndex <= maxResourceIndex + 10; nextResourceIndex++) {
        Iterator<URL> resources = getResources(nextResourceIndex);
        if (resources.hasNext()) {
            allResources = Iterators.concat(allResources, resources);
            maxResourceIndex = nextResourceIndex;
        }//from www  .j a v a2  s  .com
    }
    return new ConfigurationResources(maxResourceIndex + 1, allResources);
}

From source file:org.pshdl.model.impl.AbstractHDLSwitchStatement.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override/*from  w  ww. j a  va2  s  .  c o  m*/
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if (caseExp != null) {
                        current = Iterators.concat(Iterators.forArray(caseExp), caseExp.deepIterator());
                    }
                    break;
                case 1:
                    if ((cases != null) && (cases.size() != 0)) {
                        final List<Iterator<? extends IHDLObject>> iters = Lists
                                .newArrayListWithCapacity(cases.size());
                        for (final HDLSwitchCaseStatement o : cases) {
                            iters.add(Iterators.forArray(o));
                            iters.add(o.deepIterator());
                        }
                        current = Iterators.concat(iters.iterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:com.dangdang.ddframe.rdb.sharding.jdbc.ShardingStatement.java

@Override
public Collection<? extends Statement> getRoutedStatements() {
    return Lists.newArrayList(Iterators.concat(
            Iterators.transform(cachedRoutedStatements.getFirst().iterator(), TRANSFORM_FUNCTION),
            Iterators.transform(cachedRoutedStatements.getLast().iterator(), TRANSFORM_FUNCTION)));
}

From source file:org.locationtech.geogig.storage.postgresql.PGObjectStore.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/*www .j  a  v a 2  s.c  o m*/
public <T extends RevObject> Iterator<T> getAll(Iterable<ObjectId> ids, BulkOpListener listener,
        Class<T> type) {

    checkNotNull(ids, "ids is null");
    checkNotNull(listener, "listener is null");
    checkNotNull(type, "type is null");
    checkState(isOpen(), "Database is closed");
    config.checkRepositoryExists();

    final Set<ObjectId> queryIds = ids instanceof Set ? (Set<ObjectId>) ids : Sets.newHashSet(ids);

    ImmutableMap<ObjectId, byte[]> cached = byteCache.getAllPresent(queryIds);

    Iterator<T> hits = Collections.emptyIterator();
    Iterator<T> stream = Collections.emptyIterator();

    if (!cached.isEmpty()) {

        Map<ObjectId, T> cachedObjects = Maps.transformEntries(cached, (id, bytes) -> {
            RevObject o = encoder.decode(id, bytes);
            if (type.isAssignableFrom(o.getClass())) {
                listener.found(id, Integer.valueOf(bytes.length));
                return type.cast(o);
            }
            listener.notFound(id);
            return null;
        });

        hits = Iterators.filter(cachedObjects.values().iterator(), Predicates.notNull());
    }
    if (queryIds.size() > cached.size()) {
        Set<ObjectId> misses = Sets.difference(queryIds, cached.keySet());
        stream = new GetAllIterator(dataSource, misses.iterator(), type, listener, this);
    }

    return Iterators.concat(hits, stream);
}

From source file:org.fcrepo.kernel.modeshape.FedoraResourceImpl.java

@Override
public void delete() {
    try {// w w w.  j a  va  2 s .  co  m
        final Iterator<Property> references = node.getReferences();
        final Iterator<Property> weakReferences = node.getWeakReferences();
        final Iterator<Property> inboundProperties = Iterators.concat(references, weakReferences);

        while (inboundProperties.hasNext()) {
            final Property prop = inboundProperties.next();
            final List<Value> newVals = property2values.apply(prop)
                    .filter(UncheckedPredicate.uncheck(
                            value -> !node.equals(getSession().getNodeByIdentifier(value.getString()))))
                    .collect(toList());

            if (newVals.size() == 0) {
                prop.remove();
            } else {
                prop.setValue(newVals.toArray(new Value[newVals.size()]));
            }
        }

        final Node parent;

        if (getNode().getDepth() > 0) {
            parent = getNode().getParent();
        } else {
            parent = null;
        }
        final String name = getNode().getName();

        node.remove();

        if (parent != null) {
            createTombstone(parent, name);
        }

    } catch (final RepositoryException e) {
        throw new RepositoryRuntimeException(e);
    }
}

From source file:org.eclipse.sirius.ecore.extender.business.internal.accessor.ecore.EcoreIntrinsicExtender.java

private Iterator<EClass> getEClassesFromName(final String name) {
    return Iterators.concat(viewpointIndex.get(name).iterator(),
            platformIndex.getEClassesFromName(name).iterator());
}