Example usage for com.google.common.collect ImmutableSet iterator

List of usage examples for com.google.common.collect ImmutableSet iterator

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:eu.eubrazilcc.lvl.storage.mongodb.MongoDBHelper.java

public static BasicDBObject toProjection(final @Nullable ImmutableMap<String, Boolean> projection) {
    BasicDBObject obj = null;/*w ww. j a  va2s  .com*/
    if (projection != null && !projection.isEmpty()) {
        obj = new BasicDBObject();
        final ImmutableSet<Entry<String, Boolean>> entrySet = projection.entrySet();
        final boolean action = entrySet.iterator().next().getValue();
        for (final Entry<String, Boolean> entry : entrySet) {
            String field = null;
            checkState(action == entry.getValue(),
                    "A projection cannot contain both include and exclude specifications");
            checkState(isNotBlank(field = trimToNull(entry.getKey())), "Uninitialized field");
            obj.append(field, action ? 1 : 0);
        }
    }
    return obj;
}

From source file:dagger2.internal.codegen.InjectionAnnotations.java

static Optional<AnnotationMirror> getScopeAnnotation(Element e) {
    checkNotNull(e);/*from ww w . j  a  v a2 s. co  m*/
    ImmutableSet<? extends AnnotationMirror> scopeAnnotations = getScopes(e);
    switch (scopeAnnotations.size()) {
    case 0:
        return Optional.absent();
    case 1:
        return Optional.<AnnotationMirror>of(scopeAnnotations.iterator().next());
    default:
        throw new IllegalArgumentException(e + " was annotated with more than one @Scope annotation");
    }
}

From source file:dagger.internal.codegen.InjectionAnnotations.java

static Optional<AnnotationMirror> getQualifier(Element e) {
    checkNotNull(e);//  w ww  . j a v a 2s  . c  o m
    ImmutableSet<? extends AnnotationMirror> qualifierAnnotations = getQualifiers(e);
    switch (qualifierAnnotations.size()) {
    case 0:
        return Optional.empty();
    case 1:
        return Optional.<AnnotationMirror>of(qualifierAnnotations.iterator().next());
    default:
        throw new IllegalArgumentException(e + " was annotated with more than one @Qualifier annotation");
    }
}

From source file:dagger2.internal.codegen.InjectionAnnotations.java

static Optional<AnnotationMirror> getQualifier(Element e) {
    checkNotNull(e);/*from   ww  w.j a va  2s  .c o m*/
    ImmutableSet<? extends AnnotationMirror> qualifierAnnotations = getQualifiers(e);
    switch (qualifierAnnotations.size()) {
    case 0:
        return Optional.absent();
    case 1:
        return Optional.<AnnotationMirror>of(qualifierAnnotations.iterator().next());
    default:
        throw new IllegalArgumentException(e + " was annotated with more than one @Qualifier annotation");
    }
}

From source file:ai.grakn.graql.Autocomplete.java

/**
 * @param types the graph to find types in
 * @param query a graql query/*from  ww  w . ja  v  a 2 s  .c om*/
 * @param optToken the token the cursor is on in the query
 * @return a set of potential autocomplete words
 */
private static ImmutableSet<String> findCandidates(Set<String> types, String query,
        Optional<? extends Token> optToken) {
    ImmutableSet<String> allCandidates = Stream.of(GRAQL_KEYWORDS.stream(), types.stream(), getVariables(query))
            .flatMap(Function.identity()).collect(toImmutableSet());

    return optToken.map(token -> {
        ImmutableSet<String> candidates = allCandidates.stream()
                .filter(candidate -> candidate.startsWith(token.getText())).collect(toImmutableSet());

        if (candidates.size() == 1 && candidates.iterator().next().equals(token.getText())) {
            return ImmutableSet.of(" ");
        } else {
            return candidates;
        }
    }).orElse(allCandidates);
}

From source file:dagger2.internal.codegen.Binding.java

static Optional<String> bindingPackageFor(Iterable<? extends Binding> bindings) {
    ImmutableSet.Builder<String> bindingPackagesBuilder = ImmutableSet.builder();
    for (Binding binding : bindings) {
        bindingPackagesBuilder.addAll(binding.bindingPackage().asSet());
    }//  w  ww  . j a v a 2s. c o  m
    ImmutableSet<String> bindingPackages = bindingPackagesBuilder.build();
    switch (bindingPackages.size()) {
    case 0:
        return Optional.absent();
    case 1:
        return Optional.of(bindingPackages.iterator().next());
    default:
        throw new IllegalArgumentException();
    }
}

From source file:org.gradle.internal.ImmutableActionSet.java

private static <T> ImmutableActionSet<T> fromActions(ImmutableSet<Action<? super T>> set) {
    if (set.isEmpty()) {
        return empty();
    }//from w w  w. j a  v a 2 s.co  m
    if (set.size() == 1) {
        return new SingletonSet<T>(set.iterator().next());
    }
    if (set.size() <= FEW_VALUES) {
        return new SetWithFewActions<T>(set);
    }
    return new SetWithManyActions<T>(set);
}

From source file:edu.mit.streamjit.util.bytecode.DeadCodeElimination.java

public static boolean eliminateUselessPhis(BasicBlock block) {
    boolean changed = false, makingProgress;
    do {//from w  ww.  j  a v  a 2 s  .  c  o  m
        makingProgress = false;
        for (Instruction i : ImmutableList.copyOf(block.instructions())) {
            if (!(i instanceof PhiInst))
                continue;
            PhiInst pi = (PhiInst) i;

            if (Iterables.size(pi.incomingValues()) == 1) {
                pi.replaceInstWithValue(Iterables.getOnlyElement(pi.incomingValues()));
                makingProgress = true;
                continue;
            }

            ImmutableSet<Value> phiSources = phiSources(pi);
            if (phiSources.size() == 1) {
                pi.replaceInstWithValue(phiSources.iterator().next());
                makingProgress = true;
                continue;
            }
        }
        changed |= makingProgress;
    } while (makingProgress);
    return changed;
}

From source file:ai.grakn.graql.internal.reasoner.query.QueryAnswerStream.java

/**
 * lazy stream join with fast lookup from inverse answer map
 * @param stream left stream operand//  w w w.j av  a2  s.  co m
 * @param stream2 right stream operand
 * @param stream2InverseMap inverse map of right operand from cache
 * @param joinVars intersection on variables of two streams
 * @return joined stream
 */
public static Stream<Answer> joinWithInverse(Stream<Answer> stream, Stream<Answer> stream2,
        Map<Pair<Var, Concept>, Set<Answer>> stream2InverseMap, ImmutableSet<Var> joinVars,
        boolean explanation) {
    if (joinVars.isEmpty()) {
        LazyAnswerIterator l2 = new LazyAnswerIterator(stream2);
        return stream.flatMap(a1 -> l2.stream().map(a -> a.merge(a1, explanation)));
    }
    return stream.flatMap(a1 -> {
        Iterator<Var> vit = joinVars.iterator();
        Set<Answer> matchAnswers = findMatchingAnswers(a1, stream2InverseMap, vit.next());
        while (vit.hasNext()) {
            matchAnswers = Sets.intersection(matchAnswers,
                    findMatchingAnswers(a1, stream2InverseMap, vit.next()));
        }
        return matchAnswers.stream().map(a -> a.merge(a1, explanation));
    });
}

From source file:eu.eidas.auth.engine.xml.opensaml.AssertionUtil.java

private static String getUniquenessIdentifier(@Nonnull ImmutableAttributeMap attributeMap)
        throws EIDASSAMLEngineException {
    for (final Map.Entry<AttributeDefinition<?>, ImmutableSet<? extends AttributeValue<?>>> entry : attributeMap
            .getAttributeMap().entrySet()) {
        AttributeDefinition<?> attributeDefinition = entry.getKey();
        ImmutableSet<? extends AttributeValue<?>> values = entry.getValue();
        if (attributeDefinition.isUniqueIdentifier() && !values.isEmpty()) {
            AttributeValueMarshaller<?> attributeValueMarshaller = attributeDefinition
                    .getAttributeValueMarshaller();
            try {
                return attributeValueMarshaller.marshal((AttributeValue) values.iterator().next());
            } catch (AttributeValueMarshallingException e) {
                LOG.error("BUSINESS EXCEPTION : Invalid Attribute Value " + e, e);
                throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(),
                        EidasErrorKey.INTERNAL_ERROR.errorCode(), e);
            }/*from   ww  w  .  ja  v  a 2 s . c  o  m*/
        }
    }
    String message = "Unique Identifier not found: " + attributeMap;
    LOG.info("BUSINESS EXCEPTION : " + message);
    throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(),
            EidasErrorKey.INTERNAL_ERROR.errorCode(), message);
}