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:dagger.internal.codegen.SourceFiles.java

private static String fieldNameForDependency(ImmutableSet<DependencyRequest> dependencyRequests) {
    // collect together all of the names that we would want to call the provider
    ImmutableSet<String> dependencyNames = FluentIterable.from(dependencyRequests)
            .transform(new DependencyVariableNamer()).toSet();

    if (dependencyNames.size() == 1) {
        // if there's only one name, great! use it!
        return Iterables.getOnlyElement(dependencyNames);
    } else {/*from   www  . j a  va  2 s.  c  o  m*/
        // in the event that a field is being used for a bunch of deps with different names,
        // add all the names together with "And"s in the middle. E.g.: stringAndS
        Iterator<String> namesIterator = dependencyNames.iterator();
        String first = namesIterator.next();
        StringBuilder compositeNameBuilder = new StringBuilder(first);
        while (namesIterator.hasNext()) {
            compositeNameBuilder.append("And")
                    .append(CaseFormat.LOWER_CAMEL.to(UPPER_CAMEL, namesIterator.next()));
        }
        return compositeNameBuilder.toString();
    }
}

From source file:com.facebook.buck.android.NativeLibraryMergeEnhancer.java

/**
 * Topo-sort the constituents objects so we can process deps first.
 *//*from ww w  .  ja  v  a 2 s .com*/
private static Iterable<MergedNativeLibraryConstituents> getOrderedMergedConstituents(
        BuildRuleParams buildRuleParams,
        final Map<NativeLinkable, MergedNativeLibraryConstituents> linkableMembership) {
    MutableDirectedGraph<MergedNativeLibraryConstituents> graph = new MutableDirectedGraph<>();
    for (MergedNativeLibraryConstituents constituents : linkableMembership.values()) {
        graph.addNode(constituents);
        for (NativeLinkable constituentLinkable : constituents.getLinkables()) {
            // For each dep of each constituent of each merged lib...
            for (NativeLinkable dep : Iterables.concat(constituentLinkable.getNativeLinkableDeps(),
                    constituentLinkable.getNativeLinkableExportedDeps())) {
                // If that dep is in a different merged lib, add a dependency.
                MergedNativeLibraryConstituents mergedDep = Preconditions
                        .checkNotNull(linkableMembership.get(dep));
                if (mergedDep != constituents) {
                    graph.addEdge(constituents, mergedDep);
                }
            }
        }
    }

    // Check for cycles in the merged dependency graph.
    // If any are found, spent a lot of effort building an error message
    // that actually shows the dependency cycle.
    for (ImmutableSet<MergedNativeLibraryConstituents> fullCycle : graph.findCycles()) {
        HashSet<MergedNativeLibraryConstituents> partialCycle = new LinkedHashSet<>();
        MergedNativeLibraryConstituents item = fullCycle.iterator().next();
        while (true) {
            if (partialCycle.contains(item)) {
                break;
            }
            partialCycle.add(item);
            item = Sets.intersection(ImmutableSet.copyOf(graph.getOutgoingNodesFor(item)), fullCycle).iterator()
                    .next();
        }

        StringBuilder cycleString = new StringBuilder().append("[ ");
        boolean foundStart = false;
        for (MergedNativeLibraryConstituents member : partialCycle) {
            if (member == item) {
                foundStart = true;
            }
            if (foundStart) {
                cycleString.append(member);
                cycleString.append(" -> ");
            }
        }
        cycleString.append(item);
        cycleString.append(" ]");
        throw new RuntimeException("Dependency cycle detected when merging native libs for "
                + buildRuleParams.getBuildTarget() + ": " + cycleString);
    }

    return TopologicalSort.sort(graph);
}

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

/**
 * This method generates names and keys for the framework classes necessary for all of the
 * bindings. It is responsible for the following:
 * <ul>//ww  w.  ja  v a2  s. c o m
 * <li>Choosing a name that associates the binding with all of the dependency requests for this
 * type.
 * <li>Choosing a name that is <i>probably</i> associated with the type being bound.
 * <li>Ensuring that no two bindings end up with the same name.
 * </ul>
 *
 * @return Returns the mapping from {@link BindingKey} to field, sorted by the name of the field.
 */
static ImmutableMap<BindingKey, FrameworkField> generateBindingFieldsForDependencies(
        DependencyRequestMapper dependencyRequestMapper, Iterable<? extends DependencyRequest> dependencies) {
    ImmutableSetMultimap<BindingKey, DependencyRequest> dependenciesByKey = indexDependenciesByKey(
            dependencies);
    Map<BindingKey, Collection<DependencyRequest>> dependenciesByKeyMap = dependenciesByKey.asMap();
    ImmutableMap.Builder<BindingKey, FrameworkField> bindingFields = ImmutableMap.builder();
    for (Entry<BindingKey, Collection<DependencyRequest>> entry : dependenciesByKeyMap.entrySet()) {
        BindingKey bindingKey = entry.getKey();
        Collection<DependencyRequest> requests = entry.getValue();
        Class<?> frameworkClass = dependencyRequestMapper.getFrameworkClass(requests.iterator().next());
        // collect together all of the names that we would want to call the provider
        ImmutableSet<String> dependencyNames = FluentIterable.from(requests)
                .transform(new DependencyVariableNamer()).toSet();

        if (dependencyNames.size() == 1) {
            // if there's only one name, great! use it!
            String name = Iterables.getOnlyElement(dependencyNames);
            bindingFields.put(bindingKey,
                    FrameworkField.createWithTypeFromKey(frameworkClass, bindingKey, name));
        } else {
            // in the event that a field is being used for a bunch of deps with different names,
            // add all the names together with "And"s in the middle. E.g.: stringAndS
            Iterator<String> namesIterator = dependencyNames.iterator();
            String first = namesIterator.next();
            StringBuilder compositeNameBuilder = new StringBuilder(first);
            while (namesIterator.hasNext()) {
                compositeNameBuilder.append("And")
                        .append(CaseFormat.LOWER_CAMEL.to(UPPER_CAMEL, namesIterator.next()));
            }
            bindingFields.put(bindingKey, FrameworkField.createWithTypeFromKey(frameworkClass, bindingKey,
                    compositeNameBuilder.toString()));
        }
    }
    return bindingFields.build();
}

From source file:org.sosy_lab.cpachecker.util.expressions.And.java

public static <LeafType> ExpressionTree<LeafType> of(Iterable<ExpressionTree<LeafType>> pOperands) {
    // If one of the operands is false, return false
    if (Iterables.contains(pOperands, ExpressionTrees.getFalse())) {
        return ExpressionTrees.getFalse();
    }//from   ww w .java  2 s  . c  om
    // Filter out trivial operands and flatten the hierarchy
    ImmutableSet<ExpressionTree<LeafType>> operands = FluentIterable.from(pOperands)
            .filter(Predicates.not(Predicates.equalTo(ExpressionTrees.<LeafType>getTrue())))
            .transformAndConcat(new Function<ExpressionTree<LeafType>, Iterable<ExpressionTree<LeafType>>>() {

                @Override
                public Iterable<ExpressionTree<LeafType>> apply(ExpressionTree<LeafType> pOperand) {
                    if (pOperand instanceof And) {
                        return (And<LeafType>) pOperand;
                    }
                    return Collections.singleton(pOperand);
                }
            }).toSet();
    // If there are no operands, return the neutral element
    if (operands.isEmpty()) {
        return ExpressionTrees.getTrue();
    }
    // If there is only one operand, return it
    if (operands.size() == 1) {
        return operands.iterator().next();
    }
    return new And<>(operands);
}

From source file:org.jetbrains.android.dom.AbstractMultiRootFileDescription.java

public AbstractMultiRootFileDescription(@NotNull Class<T> aClass,
        @NotNull ResourceFolderType resourceFolderType, @NotNull ImmutableSet<String> tagNames) {
    super(aClass, tagNames.iterator().next(), resourceFolderType);
    myTagNames = tagNames;/*from  ww w .jav  a  2 s .c o m*/
}

From source file:org.androidtransfuse.TransfuseAnalysisException.java

public TransfuseAnalysisException(String message, ImmutableSet<Exception> errors) {
    //todo: print out all errors
    super(message, errors.isEmpty() ? null : errors.iterator().next());
}

From source file:shadowmage.ancient_warfare.common.block.TEBuilder.java

public void setTicket(Ticket tk) {
    this.releaseTicket();
    this.tk = tk;
    if (this.tk != null) {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setCompoundTag("pos", new BlockPosition(xCoord, yCoord, zCoord).writeToNBT(new NBTTagCompound()));
        tk.getModData().setCompoundTag("buildTE", tag);
        ImmutableSet tkCk = tk.getChunkList();
        Iterator<ChunkCoordIntPair> it = tkCk.iterator();
        while (it.hasNext()) {
            ChunkCoordIntPair ccip = it.next();
            ForgeChunkManager.forceChunk(tk, ccip);
        }//from  w  w w.ja v a  2 s .c  om
    }
}

From source file:paperparcel.Utils.java

private static Optional<AnnotationMirror> findOptionsMirror(TypeElement element) {
    Optional<AnnotationMirror> result = MoreElements.getAnnotationMirror(element, PaperParcel.Options.class);
    if (!result.isPresent()) {
        ImmutableSet<? extends AnnotationMirror> annotatedAnnotations = AnnotationMirrors
                .getAnnotatedAnnotations(element, PaperParcel.Options.class);
        if (annotatedAnnotations.size() > 1) {
            throw new IllegalStateException("PaperParcel options applied twice.");
        } else if (annotatedAnnotations.size() == 1) {
            AnnotationMirror annotatedAnnotation = annotatedAnnotations.iterator().next();
            result = MoreElements.getAnnotationMirror(annotatedAnnotation.getAnnotationType().asElement(),
                    PaperParcel.Options.class);
        } else {//from   ww w .  j ava  2  s .  c o  m
            TypeMirror superType = element.getSuperclass();
            if (superType.getKind() != TypeKind.NONE) {
                TypeElement superElement = asType(asDeclared(superType).asElement());
                result = findOptionsMirror(superElement);
            }
        }
    }
    return result;
}

From source file:org.springframework.ide.eclipse.boot.dash.views.OpenNgrokAdminUi.java

private NGROKClient getClient(BootDashElement bde) {
    if (isLocalApp(bde)) {
        ImmutableSet<ILaunchConfiguration> launchConfigs = bde.getLaunchConfigs();
        if (launchConfigs.size() == 1) {
            return NGROKLaunchTracker.get(launchConfigs.iterator().next().getName());
        }//from www.j  a  va 2s  . com
    }
    return null;
}

From source file:org.geogit.api.plumbing.ResolveBranchId.java

@Override
public Optional<Ref> call() {
    Preconditions.checkState(id != null, "id has not been set.");
    Predicate<Ref> filter = new Predicate<Ref>() {
        @Override/*from  w w  w . j  a  v a 2 s .  c om*/
        public boolean apply(@Nullable Ref ref) {
            return ref.getObjectId().equals(id);
        }
    };
    ImmutableSet<Ref> refs = command(ForEachRef.class).setFilter(filter).call();
    if (refs.isEmpty()) {
        return Optional.absent();
    } else {
        return Optional.of(refs.iterator().next());
    }
}