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:com.threerings.media.MetaMediaManager.java

public Iterator<AbstractMedia> iterator() {
    return Iterators.concat(_spritemgr.enumerateSprites(), _animmgr.iterator());
}

From source file:org.eclipse.emf.compare.match.update.Updater.java

private Iterable<EObject> allContentsOf(final EObject root) {
    return new Iterable<EObject>() {
        public Iterator<EObject> iterator() {
            final Iterator<EObject> contentsIterator;
            if (root == null) {
                contentsIterator = Iterators.<EObject>emptyIterator();
            } else {
                contentsIterator = root.eAllContents();
            }//from w w  w  . j  a  v  a2s .c o  m
            return Iterators.concat(Iterators.singletonIterator(root), contentsIterator);
        }
    };
}

From source file:com.tinspx.util.collect.CollectUtils.java

/**
 * appends {@code value} to the <i>end</i> of {@code iter}
 *//*from w  w w. j av  a2  s.  c  o  m*/
public static <T> Iterator<T> concat(Iterator<? extends T> iter, T value) {
    return Iterators.concat(iter, iterator(value));
}

From source file:com.tinspx.util.collect.CollectUtils.java

/**
 * prepends {@code value} to the <i>beginning</i> of {@code iter}
 *//* w w  w  .  j a v a2  s .  c o  m*/
public static <T> Iterator<T> concat(T value, Iterator<? extends T> iter) {
    return Iterators.concat(iterator(value), iter);
}

From source file:org.pshdl.model.impl.AbstractHDLManip.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 v a  2s .c  o  m
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if (target != null) {
                        current = Iterators.concat(Iterators.forArray(target), target.deepIterator());
                    }
                    break;
                case 1:
                    if (castTo != null) {
                        current = Iterators.concat(Iterators.forArray(castTo), castTo.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:org.eclipse.xtext.builder.impl.QueuedBuildData.java

public Queue<URI> getQueue(String projectName) {
    final LinkedList<URI> list = projectNameToChangedResource.get(projectName);
    if (list == null)
        return uris;
    return new AbstractQueue<URI>() {

        @Override//from w ww. j a v a 2s.com
        public boolean offer(URI o) {
            return list.offer(o);
        }

        @Override
        public URI poll() {
            if (uris.isEmpty())
                return list.poll();
            return uris.poll();
        }

        @Override
        public URI peek() {
            if (uris.isEmpty())
                return list.peek();
            return uris.peek();
        }

        @Override
        public Iterator<URI> iterator() {
            return Iterators.concat(uris.iterator(), list.iterator());
        }

        @Override
        public int size() {
            return uris.size() + list.size();
        }
    };
}

From source file:org.eclipse.sirius.diagram.business.internal.metamodel.helper.DiagramElementMappingHelper.java

private static Iterator<EObject> extEAllContents(final EObject eObj) {
    Iterator<EObject> it = null;
    final ModelAccessor accessor = SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(eObj);
    final Session session = SessionManager.INSTANCE.getSession(eObj);
    for (final Resource resource : session.getSemanticResources()) {
        for (final EObject root : resource.getContents()) {
            if (it == null) {
                it = accessor.eAllContents(root);
            } else {
                Iterators.concat(it, accessor.eAllContents(root));
            }//from  w  ww.j a  va  2s . c  o m
        }
    }
    return it;
}

From source file:alluxio.master.block.DefaultBlockMaster.java

@Override
public Iterator<JournalEntry> getJournalEntryIterator() {
    final Iterator<MasterBlockInfo> it = mBlocks.values().iterator();
    Iterator<JournalEntry> blockIterator = new Iterator<JournalEntry>() {
        @Override//from   w w  w . j  av  a  2 s  .c om
        public boolean hasNext() {
            return it.hasNext();
        }

        @Override
        public JournalEntry next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            MasterBlockInfo info = it.next();
            BlockInfoEntry blockInfoEntry = BlockInfoEntry.newBuilder().setBlockId(info.getBlockId())
                    .setLength(info.getLength()).build();
            return JournalEntry.newBuilder().setBlockInfo(blockInfoEntry).build();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("BlockMaster#Iterator#remove is not supported.");
        }
    };

    return Iterators.concat(CommonUtils.singleElementIterator(getContainerIdJournalEntry()), blockIterator);
}

From source file:org.pshdl.model.impl.AbstractHDLTernary.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 va2s  . c  o  m
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if (ifExpr != null) {
                        current = Iterators.concat(Iterators.forArray(ifExpr), ifExpr.deepIterator());
                    }
                    break;
                case 1:
                    if (thenExpr != null) {
                        current = Iterators.concat(Iterators.forArray(thenExpr), thenExpr.deepIterator());
                    }
                    break;
                case 2:
                    if (elseExpr != null) {
                        current = Iterators.concat(Iterators.forArray(elseExpr), elseExpr.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:org.eclipse.emf.ecoretools.design.service.DesignServices.java

public Collection<EModelElement> getDisplayedEModelElements(DSemanticDiagram diagram) {
    Set<EModelElement> modelelements = Sets.newLinkedHashSet();
    Iterator<DSemanticDecorator> it = Iterators.filter(
            Iterators.concat(Iterators.singletonIterator(diagram), diagram.eAllContents()),
            DSemanticDecorator.class);
    while (it.hasNext()) {
        DSemanticDecorator dec = it.next();
        if (dec.getTarget() instanceof EModelElement)
            modelelements.add((EModelElement) dec.getTarget());
    }/*from   www . ja v a2s  .  co m*/
    return modelelements;
}