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

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

Introduction

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

Prototype

public static <T> UnmodifiableIterator<T> singletonIterator(@Nullable final T value) 

Source Link

Document

Returns an iterator containing only value .

Usage

From source file:us.askplatyp.kb.lucene.lucene.sparql.LuceneTripleSource.java

private CloseableIteration<Statement, QueryEvaluationException> getStatementsForPredicateObject(IRI pred,
        Value obj) throws IOException {
    return new QueryIteration(index.getReader(), new TermQuery(termForPredicateObject(pred, obj)), //TODO: better query?
            document -> Iterators
                    .singletonIterator(VALUE_FACTORY.createStatement(getIRIFromDocument(document), pred, obj)),
            Collections.singleton("@id"));
}

From source file:org.ow2.authzforce.core.pdp.impl.policy.FlattenedPolicyTree.java

/**
 * The first element is the root policy in the tree, then, if any (e.g. the root policy is a XACML PolicySet enclosing Policy(Set)IdReferences), come the policies referenced from it. (This assumes
 * that all policy references, e.g. Policy(Set)IdReferences, have been statically resolved.)
 *//* w  w w . j a v a2  s.com*/
@Override
public Iterator<PrimaryPolicyMetadata> iterator() {
    final Iterator<PrimaryPolicyMetadata> rootPolicyIterator = Iterators
            .singletonIterator(this.immutableRootPolicyMetadata);
    return immutableRootPolicyRefsMetadata.isPresent()
            ? Iterators.concat(rootPolicyIterator,
                    this.immutableRootPolicyRefsMetadata.get().getRefPolicies().iterator())
            : rootPolicyIterator;
}

From source file:org.apache.jackrabbit.oak.security.user.UserPrincipalProvider.java

@Nonnull
@Override/*from   www .  j a v  a2 s  . c o m*/
public Iterator<? extends Principal> findPrincipals(final String nameHint, final int searchType) {
    try {
        AuthorizableType type = AuthorizableType.getType(searchType);
        StringBuilder statement = new StringBuilder()
                .append(QueryUtil.getSearchRoot(type, config.getParameters())).append("//element(*,")
                .append(QueryUtil.getNodeTypeName(type)).append(')').append("[jcr:like(@rep:principalName,'")
                .append(buildSearchPattern(nameHint)).append("')]");

        Result result = root.getQueryEngine().executeQuery(statement.toString(), javax.jcr.query.Query.XPATH,
                NO_BINDINGS, namePathMapper.getSessionLocalMappings());

        Iterator<Principal> principals = Iterators.filter(
                Iterators.transform(result.getRows().iterator(), new ResultRowToPrincipal()),
                Predicates.notNull());

        if (matchesEveryone(nameHint, searchType)) {
            principals = Iterators.concat(principals,
                    Iterators.singletonIterator(EveryonePrincipal.getInstance()));
            return Iterators.filter(principals, new EveryonePredicate());
        } else {
            return principals;
        }
    } catch (ParseException e) {
        log.debug(e.getMessage());
        return Iterators.emptyIterator();
    }
}

From source file:org.geogit.api.plumbing.diff.TreeDiffEntryIterator.java

private Iterator<DiffEntry> addRemoveAll(@Nullable final NodeRef treeRef, final RevTree tree,
        final ChangeType changeType) {
    DepthTreeIterator treeIterator;/*from  w ww . j  ava  2  s .co  m*/

    final String path = treeRef == null ? "" : treeRef.path();
    final ObjectId metadataId = treeRef == null ? ObjectId.NULL : treeRef.getMetadataId();

    treeIterator = new DepthTreeIterator(path, metadataId, tree, objectDb, strategy);

    Iterator<DiffEntry> iterator;

    iterator = Iterators.transform(treeIterator, new RefToDiffEntry(changeType));

    if (reportTrees && !NodeRef.ROOT.equals(path)) {
        NodeRef oldTreeRef = ChangeType.ADDED.equals(changeType) ? null : treeRef;
        NodeRef newTreeRef = ChangeType.ADDED.equals(changeType) ? treeRef : null;
        DiffEntry treeEntry = new DiffEntry(oldTreeRef, newTreeRef);
        iterator = Iterators.concat(Iterators.singletonIterator(treeEntry), iterator);
    }
    return iterator;
}

From source file:mvm.rya.accumulo.AccumuloRyaDAO.java

@Override
public void add(RyaStatement statement) throws RyaDAOException {
    commit(Iterators.singletonIterator(statement));
}

From source file:com.indeed.lsmtree.recordcache.StandalonePersistentRecordCache.java

public Iterator<Either<Exception, P2<K, V>>> getStreaming(Iterator<K> keys, AtomicInteger progress,
        AtomicInteger skipped) {//w w  w .  ja  va2 s . co  m
    log.info("starting store lookups");
    final List<Either<Exception, P2<K, V>>> ret = Lists.newArrayList();
    int notFound = 0;
    while (keys.hasNext()) {
        final K key = keys.next();
        final V value;
        try {
            value = index.get(key);
        } catch (IOException e) {
            log.error("error", e);
            return Iterators.singletonIterator(Left.<Exception, P2<K, V>>of(new IndexReadException(e)));
        }
        if (value != null) {
            ret.add(Right.<Exception, P2<K, V>>of(P.p(key, value)));
        } else {
            notFound++;
        }
    }
    if (progress != null)
        progress.addAndGet(notFound);
    if (skipped != null)
        skipped.addAndGet(notFound);
    log.info("store lookups complete");

    return ret.iterator();
}

From source file:org.apache.rya.accumulo.AccumuloRyaDAO.java

@Override
public void add(final RyaStatement statement) throws RyaDAOException {
    commit(Iterators.singletonIterator(statement));
}

From source file:org.obm.push.calendar.CalendarBackend.java

@Override
public BackendFolders getBackendFolders(final UserDataRequest udr) {
    return new BackendFolders() {

        @Override/*  ww  w. j  a  v a 2 s .  c o m*/
        public Iterator<BackendFolder> iterator() {
            return Iterators.singletonIterator(defaultCalendar(udr));
        }
    };
}

From source file:mvm.rya.accumulo.AccumuloRyaDAO.java

@Override
public void delete(RyaStatement stmt, AccumuloRdfConfiguration aconf) throws RyaDAOException {
    this.delete(Iterators.singletonIterator(stmt), aconf);
}

From source file:org.apache.rya.accumulo.AccumuloRyaDAO.java

@Override
public void delete(final RyaStatement stmt, final AccumuloRdfConfiguration aconf) throws RyaDAOException {
    this.delete(Iterators.singletonIterator(stmt), aconf);
}