List of usage examples for com.google.common.collect Iterators concat
public static <T> Iterator<T> concat(Iterator<? extends T> a, Iterator<? extends T> b)
From source file:org.opendaylight.controller.sample.toaster.it.NodeBuilderElement.java
@SuppressWarnings("unchecked") @Override/*from w w w.jav a 2 s. c o m*/ public Node getFirstChild() { if (!isFirstInit) { if (node instanceof org.opendaylight.yangtools.yang.data.api.schema.LeafNode || node instanceof org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) { // System.out.println("The node is "+ this.getNodeName()); // System.out.println("The above node is either leaf node or leafsetentry node"); firstChild = new NodeBuilderText(node.getValue().toString(), this, null); } else if (node instanceof org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) { // handle list here .. // System.out.println("The node is "+ this.getNodeName()); Iterable<DataContainerChild<? extends PathArgument, ?>> list = ((Iterable<DataContainerChild<? extends PathArgument, ?>>) node .getValue()); Iterator<DataContainerChild<? extends PathArgument, ?>> listiter = list.iterator(); DataContainerNode<?> dataContainerNode = (DataContainerNode<?>) listiter.next(); Iterator<DataContainerChild<? extends PathArgument, ?>> Childiterator = dataContainerNode.getValue() .iterator(); firstChild = new NodeBuilderElement((NormalizedNode<?, ?>) iterator.next(), this, Childiterator); this.iterator = Iterators.concat(listiter, this.iterator); // System.out.println("its first child is "+ firstChild.getNodeName()); } else if (node instanceof org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) { // handle list here .. // System.out.println("The node is "+ this.getNodeName()); Iterable<NormalizedNode<?, ?>> list = ((Iterable<NormalizedNode<?, ?>>) node.getValue()); Iterator<NormalizedNode<?, ?>> listiter = list.iterator(); firstChild = new NodeBuilderText(listiter.next().getValue().toString(), this, null); //TypeConflict here this.iterator = Iterators.concat(listiter, this.iterator); // System.out.println("its first child is "+ firstChild.getNodeName()); } // get iterator on children, get first child from iterator else { // System.out.println("The node is "+ this.getNodeName()); DataContainerNode<?> dataContainerNode = (DataContainerNode<?>) node; Iterator<DataContainerChild<? extends PathArgument, ?>> dataiterator = dataContainerNode.getValue() .iterator(); DataContainerChild<? extends PathArgument, ?> something = dataiterator.next(); if (something instanceof org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) { Iterable<NormalizedNode<?, ?>> containerlist = (Iterable<NormalizedNode<?, ?>>) something .getValue(); Iterator<NormalizedNode<?, ?>> containerListIterator = containerlist.iterator(); NormalizedNode<?, ?> someNode = containerListIterator.next(); firstChild = new NodeBuilderElement(someNode, this, containerListIterator); } else { firstChild = new NodeBuilderElement(something, this, iterator); } } // construct a NodeBuilderElement, passing in the new node, the same // parent, and the iterator // cache the node builder element to first child isFirstInit = true; } return firstChild; }
From source file:org.optaplanner.core.impl.heuristic.selector.move.composite.UnionMoveSelector.java
public Iterator<Move> iterator() { if (!randomSelection) { Iterator<Move> iterator = Iterators.emptyIterator(); for (MoveSelector moveSelector : childMoveSelectorList) { iterator = Iterators.concat(iterator, moveSelector.iterator()); }//from w w w .j a v a 2 s. com return iterator; } else { return new RandomUnionMoveIterator(); } }
From source file:org.fcrepo.kernel.utils.iterators.RdfStream.java
/** * @param newTriple Triples to add.//www . j av a2s .c o m * @return This object for continued use. */ public <T extends Triple> RdfStream concat(final T newTriple) { triples = Iterators.concat(singletonIterator(newTriple), triples); return this; }
From source file:org.apache.james.transport.mailets.LocalDelivery.java
/** * @see org.apache.mailet.base.GenericMailet#init() *//*from w ww .j a v a2 s . co m*/ public void init() throws MessagingException { super.init(); recipientRewriteTable = new RecipientRewriteTable(); recipientRewriteTable.setDomainList(domainList); recipientRewriteTable.setRecipientRewriteTable(rrt); recipientRewriteTable.init(getMailetConfig()); sieveMailet = new SieveMailet(usersRepository, mailboxManager, ResourceLocatorImpl.instanciate(usersRepository, sieveRepository), "INBOX"); sieveMailet.init(new MailetConfig() { public String getInitParameter(String name) { if ("addDeliveryHeader".equals(name)) { return "Delivered-To"; } else if ("resetReturnPath".equals(name)) { return "true"; } else { return getMailetConfig().getInitParameter(name); } } public Iterator<String> getInitParameterNames() { return Iterators.concat(getMailetConfig().getInitParameterNames(), Lists.newArrayList("addDeliveryHeader", "resetReturnPath").iterator()); } public MailetContext getMailetContext() { return getMailetConfig().getMailetContext(); } public String getMailetName() { return getMailetConfig().getMailetName(); } }); // Override the default value of "quiet" sieveMailet.setQuiet(getInitParameter("quiet", true)); }
From source file:org.opencms.i18n.CmsVfsResourceBundle.java
/** * @see java.util.ResourceBundle#getKeys() */// ww w.j a va 2 s . c o m @Override public Enumeration<String> getKeys() { Iterator<String> myKeyIter = handleKeySet().iterator(); Iterator<String> result = myKeyIter; if (parent != null) { Iterator<String> parentKeyIter = Iterators.forEnumeration(parent.getKeys()); result = Iterators.concat(myKeyIter, parentKeyIter); } return Iterators.asEnumeration(result); }
From source file:org.locationtech.geogig.storage.postgresql.v9.PGObjectStoreObjectIterator.java
private @Nullable ObjectInfo<T> computeNext() { if (nextBatch != null && nextBatch.hasNext()) { return nextBatch.next(); }/*w ww.j a v a2 s . c om*/ if (!nodes.hasNext()) { return null; } { ObjectInfo<T> obj = tryNextCached(); if (obj != null) { return obj; } } final int queryBatchSize = store.getAllBatchSize; final int superPartitionBatchSize = 10 * queryBatchSize; List<ObjectInfo<T>> hits = new LinkedList<>(); List<NodeRef> cacheMisses = new ArrayList<>(superPartitionBatchSize); for (int i = 0; i < superPartitionBatchSize && nodes.hasNext(); i++) { NodeRef node = nodes.next(); ObjectId id = node.getObjectId(); RevObject cached = cache.getIfPresent(id); if (cached == null) { cacheMisses.add(node); } else { T obj = cacheHit(id, cached); if (obj != null) { hits.add(new ObjectInfo<T>(node, obj)); } } } List<List<NodeRef>> partitions = Lists.partition(cacheMisses, queryBatchSize); List<Future<List<ObjectInfo<T>>>> futures = new ArrayList<>(partitions.size()); for (List<NodeRef> partition : partitions) { Future<List<ObjectInfo<T>>> dbBatch; dbBatch = store.getObjects(partition, listener, type); futures.add(dbBatch); } final Function<Future<List<ObjectInfo<T>>>, List<ObjectInfo<T>>> futureGetter = (objs) -> { try { return objs.get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }; Iterable<List<ObjectInfo<T>>> lists = Iterables.transform(futures, futureGetter); Iterable<ObjectInfo<T>> concat = Iterables.concat(lists); Iterator<ObjectInfo<T>> iterator = concat.iterator(); nextBatch = Iterators.concat(hits.iterator(), iterator); return computeNext(); }
From source file:com.yahoo.yqlplus.api.types.Annotations.java
@Override public Iterator<Map.Entry<String, Object>> iterator() { // we don't expect much use of this final Set<String> seen = Sets.newTreeSet(); return Iterators.filter(Iterators.concat(annotations.entrySet().iterator(), parent.iterator()), new Predicate<Map.Entry<String, Object>>() { @Override/*from w w w.j a v a 2 s . co m*/ public boolean apply(Map.Entry<String, Object> input) { return seen.add(input.getKey()); } }); }
From source file:org.apache.jackrabbit.oak.security.principal.PrincipalProviderImpl.java
@Nonnull @Override//from w w w . ja va2s. c om public Iterator<? extends Principal> findPrincipals(@Nullable final String nameHint, final int searchType) { try { Iterator<Authorizable> authorizables = findAuthorizables(nameHint, searchType); Iterator<Principal> principals = Iterators.transform( Iterators.filter(authorizables, Predicates.notNull()), new AuthorizableToPrincipal()); if (matchesEveryone(nameHint, searchType)) { principals = Iterators.concat(principals, Iterators.singletonIterator(EveryonePrincipal.getInstance())); return Iterators.filter(principals, new EveryonePredicate()); } else { return principals; } } catch (RepositoryException e) { log.debug(e.getMessage()); return Iterators.emptyIterator(); } }
From source file:es.usc.citius.composit.wsc08.data.WSCLazyServiceProvider.java
@Override public Iterable<Operation<Concept>> getOperationsWithOutput(final Concept output) { final Set<Instance> instances = kb.getInstances(output); return new Iterable<Operation<Concept>>() { @Override/*w ww . java 2 s .c o m*/ public Iterator<Operation<Concept>> iterator() { Iterator<Operation<String>> iteratorResult = Iterators.emptyIterator(); for (Instance instance : instances) { iteratorResult = Iterators.concat(iteratorResult, delegatedProvider.getOperationsWithOutput(instance.getID()).iterator()); } return Iterators.transform(iteratorResult, new Function<Operation<String>, Operation<Concept>>() { @Override public Operation<Concept> apply(Operation<String> op) { return translate(op); } }); } }; }
From source file:org.apache.giraph.counters.GiraphTimers.java
@Override public Iterator<GiraphHadoopCounter> iterator() { return Iterators.concat(jobCounters().iterator(), superstepCounters().values().iterator()); }