Example usage for com.google.common.collect Sets newHashSetWithExpectedSize

List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize

Introduction

In this page you can find the example usage for com.google.common.collect Sets newHashSetWithExpectedSize.

Prototype

public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize) 

Source Link

Document

Creates a HashSet instance, with a high enough initial table size that it should hold expectedSize elements without resizing.

Usage

From source file:com.android.tools.idea.navigator.nodes.NativeAndroidLibraryNode.java

@NotNull
public static Collection<AbstractTreeNode> getSourceDirectoryNodes(@NotNull Project project,
        @NotNull Collection<NativeArtifact> artifacts, @NotNull ViewSettings settings,
        @NotNull Collection<String> sourceFileExtensions) {
    TreeMap<String, RootDirectory> rootDirectories = new TreeMap<>();

    for (NativeArtifact artifact : artifacts) {
        addSourceFolders(rootDirectories, artifact);
        addSourceFiles(rootDirectories, artifact);
    }//  ww  w.j a  v  a  2s . c o m

    if (rootDirectories.size() > 1) {
        groupDirectories(rootDirectories);
    }

    if (rootDirectories.size() > 1) {
        mergeDirectories(rootDirectories);
    }

    Set<String> fileExtensions = Sets
            .newHashSetWithExpectedSize(sourceFileExtensions.size() + HEADER_FILE_EXTENSIONS.size());
    fileExtensions.addAll(sourceFileExtensions);
    // add header files extension explicitly as the model only provides the extensions of source files.
    fileExtensions.addAll(HEADER_FILE_EXTENSIONS);

    PsiManager psiManager = PsiManager.getInstance(project);
    List<AbstractTreeNode> children = Lists.newArrayList();
    for (RootDirectory rootDirectory : rootDirectories.values()) {
        PsiDirectory psiDir = psiManager.findDirectory(rootDirectory.rootDir);
        if (psiDir != null) {
            children.add(new NativeAndroidSourceDirectoryNode(project, psiDir, settings, fileExtensions,
                    rootDirectory.sourceFolders, rootDirectory.sourceFiles));
        }
    }
    return children;
}

From source file:com.android.tools.idea.uibuilder.handlers.relative.DeletionHandler.java

/**
 * Creates a new {@link DeletionHandler}
 *
 * @param deleted the deleted nodes/* w  ww . j a va2 s.  c o  m*/
 * @param moved   nodes that were moved (e.g. deleted, but also inserted elsewhere)
 * @param layout  the parent layout of the deleted nodes
 */
public DeletionHandler(@NotNull List<NlComponent> deleted, @NotNull List<NlComponent> moved,
        @NotNull NlComponent layout) {
    myDeleted = deleted;
    myChildren = Lists.newArrayList(layout.getChildren());
    myNodeMap = Maps.newHashMapWithExpectedSize(myChildren.size());
    for (NlComponent view : myChildren) {
        String id = view.getId();
        if (id != null) {
            myNodeMap.put(LintUtils.stripIdPrefix(id), view);
        }
    }

    myDeletedIds = Sets.newHashSetWithExpectedSize(myDeleted.size());
    for (NlComponent node : myDeleted) {
        String id = node.getId();
        if (id != null) {
            myDeletedIds.add(LintUtils.stripIdPrefix(id));
        }
    }

    // Any widgets that remain (e.g. typically because they were moved) should
    // keep their incoming dependencies
    for (NlComponent node : moved) {
        String id = node.getId();
        if (id != null) {
            myDeletedIds.remove(LintUtils.stripIdPrefix(id));
        }
    }
}

From source file:com.google.template.soy.shared.internal.FunctionAdapters.java

/**
 * Given the set of all Soy directive implementations and a specific Soy directive type (subtype
 * of SoyPrintDirective) to look for, finds the Soy directives that implement the specific type
 * and returns them in the form of a map from directive name to directive.
 *
 * @param <T> The specific Soy directive type to look for.
 * @param soyDirectivesSet The set of all Soy directives.
 * @param specificSoyDirectiveType The class of the specific Soy directive type to look for.
 * @return A map of the relevant specific Soy directives (name to directive).
 *//* w w w.ja va  2 s  .  co  m*/
public static <T extends SoyPrintDirective> ImmutableMap<String, T> buildSpecificSoyDirectivesMap(
        Set<SoyPrintDirective> soyDirectivesSet, Class<T> specificSoyDirectiveType) {

    ImmutableMap.Builder<String, T> mapBuilder = ImmutableMap.builder();

    Set<String> seenDirectiveNames = Sets.newHashSetWithExpectedSize(soyDirectivesSet.size());

    for (SoyPrintDirective directive : soyDirectivesSet) {
        if (specificSoyDirectiveType.isAssignableFrom(directive.getClass())) {
            String directiveName = directive.getName();

            if (seenDirectiveNames.contains(directiveName)) {
                throw new IllegalStateException(
                        "Found two implementations of " + specificSoyDirectiveType.getSimpleName()
                                + " with the same directive name '" + directiveName + "'.");
            }
            seenDirectiveNames.add(directiveName);

            mapBuilder.put(directiveName, specificSoyDirectiveType.cast(directive));
        }
    }

    return mapBuilder.build();
}

From source file:com.opengamma.integration.viewer.status.impl.SimpleViewStatusModel.java

@Override
public Set<String> getCurrencies() {
    Set<String> result = Sets.newHashSetWithExpectedSize(_viewStatusResult.size());
    for (ViewStatusKey key : _viewStatusResult.keySet()) {
        result.add(key.getCurrency());/*from www .ja v  a 2s  .  c o  m*/
    }
    return result;
}

From source file:net.automatalib.util.automata.ads.LeeYannakakis.java

private static <S, I, O> SplitTreeResult<S, I, O> computeSplitTree(final MealyMachine<S, I, ?, O> automaton,
        final Alphabet<I> input) {

    final SplitTree<S, I, O> st = new SplitTree<>(new HashSet<>(automaton.getStates()));
    final Set<SplitTree<S, I, O>> leaves = Sets.newHashSetWithExpectedSize(automaton.size());
    leaves.add(st);//from   w ww  . j a  v  a  2 s  .c  o m

    while (leaves.stream().anyMatch(LeeYannakakis::needsRefinement)) {

        final int maxCardinality = leaves.stream().mapToInt(x -> x.getPartition().size()).max().getAsInt();
        final Set<SplitTree<S, I, O>> R = leaves.stream().filter(x -> x.getPartition().size() == maxCardinality)
                .collect(Collectors.toSet());

        final Map<Validity, Set<Pair<Word<I>, SplitTree<S, I, O>>>> validitySetMap = computeValidities(
                automaton, input, R, leaves);

        if (!validitySetMap.get(Validity.INVALID).isEmpty()) {
            final Set<Pair<Word<I>, SplitTree<S, I, O>>> set = validitySetMap.get(Validity.INVALID);

            final Set<S> indistinguishableStates = new HashSet<>();

            for (final Pair<Word<I>, SplitTree<S, I, O>> pair : set) {
                indistinguishableStates.addAll(pair.getSecond().getPartition());
            }

            return new SplitTreeResult<>(indistinguishableStates);
        }

        // a-valid partitions
        for (final Pair<Word<I>, SplitTree<S, I, O>> aPartition : validitySetMap.get(Validity.A_VALID)) {

            assert aPartition.getFirst().size() == 1 : "a-valid inputs should always contain exactly 1 symbol";

            final I aValidInput = aPartition.getFirst().firstSymbol();
            final SplitTree<S, I, O> nodeToRefine = aPartition.getSecond();
            final Map<O, Set<S>> successorMap = nodeToRefine.getPartition().stream().collect(
                    Collectors.groupingBy(s -> automaton.getOutput(s, aValidInput), Collectors.toSet()));

            nodeToRefine.setSequence(Word.fromSymbols(aValidInput));
            leaves.remove(nodeToRefine);

            for (Map.Entry<O, Set<S>> entry : successorMap.entrySet()) {
                final SplitTree<S, I, O> child = new SplitTree<>(entry.getValue());
                nodeToRefine.getSuccessors().put(entry.getKey(), child);
                leaves.add(child);
            }
            for (final S s : nodeToRefine.getPartition()) {
                nodeToRefine.getMapping().put(s, automaton.getSuccessor(s, aValidInput));
            }
        }

        // b-valid partitions
        for (final Pair<Word<I>, SplitTree<S, I, O>> bPartition : validitySetMap.get(Validity.B_VALID)) {

            assert bPartition.getFirst().size() == 1 : "b-valid inputs should always contain exactly 1 symbol";

            final I bValidInput = bPartition.getFirst().firstSymbol();
            final SplitTree<S, I, O> nodeToRefine = bPartition.getSecond();
            final Map<S, S> successorsToNodes = nodeToRefine.getPartition().stream().collect(
                    Collectors.toMap(x -> automaton.getSuccessor(x, bValidInput), Function.identity()));
            final SplitTree<S, I, O> v = st.findLowestSubsetNode(successorsToNodes.keySet())
                    .orElseThrow(IllegalStateException::new);

            nodeToRefine.setSequence(v.getSequence().prepend(bValidInput));
            leaves.remove(nodeToRefine);

            for (final Map.Entry<O, SplitTree<S, I, O>> entry : v.getSuccessors().entrySet()) {

                final Set<S> wSet = entry.getValue().getPartition();
                final Set<S> intersection = new HashSet<>(successorsToNodes.keySet());
                intersection.retainAll(wSet);

                if (!intersection.isEmpty()) {
                    final Set<S> indistinguishableNodes = intersection.stream().map(successorsToNodes::get)
                            .collect(Collectors.toSet());
                    final SplitTree<S, I, O> newChild = new SplitTree<>(indistinguishableNodes);
                    nodeToRefine.getSuccessors().put(entry.getKey(), newChild);
                    leaves.add(newChild);
                }
            }
            for (final S s : nodeToRefine.getPartition()) {
                nodeToRefine.getMapping().put(s, v.getMapping().get(automaton.getSuccessor(s, bValidInput)));
            }
        }

        // c-valid partitions
        for (final Pair<Word<I>, SplitTree<S, I, O>> cPartition : validitySetMap.get(Validity.C_VALID)) {
            final Word<I> cValidInput = cPartition.getFirst();
            final SplitTree<S, I, O> nodeToRefine = cPartition.getSecond();
            final Map<S, S> successorsToNodes = nodeToRefine.getPartition().stream().collect(
                    Collectors.toMap(x -> automaton.getSuccessor(x, cValidInput), Function.identity()));
            final SplitTree<S, I, O> C = st.findLowestSubsetNode(successorsToNodes.keySet())
                    .orElseThrow(IllegalStateException::new);

            nodeToRefine.setSequence(cValidInput.concat(C.getSequence()));
            leaves.remove(nodeToRefine);

            for (final Map.Entry<O, SplitTree<S, I, O>> entry : C.getSuccessors().entrySet()) {

                final Set<S> wSet = entry.getValue().getPartition();
                final Set<S> intersection = new HashSet<>(successorsToNodes.keySet());
                intersection.retainAll(wSet);

                if (!intersection.isEmpty()) {
                    final Set<S> indistinguishableNodes = intersection.stream().map(successorsToNodes::get)
                            .collect(Collectors.toSet());
                    final SplitTree<S, I, O> newChild = new SplitTree<>(indistinguishableNodes);
                    nodeToRefine.getSuccessors().put(entry.getKey(), newChild);
                    leaves.add(newChild);
                }
            }
            for (final S s : nodeToRefine.getPartition()) {
                nodeToRefine.getMapping().put(s, C.getMapping().get(automaton.getSuccessor(s, cValidInput)));
            }
        }
    }

    return new SplitTreeResult<>(st);
}

From source file:com.intellij.android.designer.model.layout.relative.DeletionHandler.java

/**
 * Creates a new {@link DeletionHandler}
 *
 * @param deleted the deleted nodes/*from  www  . j ava 2  s. c  o m*/
 * @param moved   nodes that were moved (e.g. deleted, but also inserted elsewhere)
 * @param layout  the parent layout of the deleted nodes
 */
public DeletionHandler(@NotNull List<RadViewComponent> deleted, @NotNull List<RadViewComponent> moved,
        @NotNull RadViewComponent layout) {
    myDeleted = deleted;
    myChildren = layout.getChildren();
    myNodeMap = Maps.newHashMapWithExpectedSize(myChildren.size());
    for (RadViewComponent view : RadViewComponent.getViewComponents(myChildren)) {
        String id = view.getId();
        if (id != null) {
            myNodeMap.put(LintUtils.stripIdPrefix(id), view);
        }
    }

    myDeletedIds = Sets.newHashSetWithExpectedSize(myDeleted.size());
    for (RadViewComponent node : myDeleted) {
        String id = node.getId();
        if (id != null) {
            myDeletedIds.add(LintUtils.stripIdPrefix(id));
        }
    }

    // Any widgets that remain (e.g. typically because they were moved) should
    // keep their incoming dependencies
    for (RadViewComponent node : moved) {
        String id = node.getId();
        if (id != null) {
            myDeletedIds.remove(LintUtils.stripIdPrefix(id));
        }
    }
}

From source file:concretisations.checkers.pieces.CheckerPiece.java

@SuppressWarnings("unchecked")
private Set<DirectionInterface> compileLegalRelativePositions(
        final Set<? extends DirectionInterface> directions) {
    final Set<DirectionInterface> legalRelativePositions = Sets
            .newHashSetWithExpectedSize(CheckerPiece.PATHS.size() * directions.size());

    for (final List<? extends DirectionInterface> list : Sets.cartesianProduct(CheckerPiece.PATHS,
            directions)) {//from  ww w. jav a  2  s  . c o  m
        int rowDelta = 0;
        int columnDelta = 0;
        for (final DirectionInterface namedDirection : list) {
            rowDelta += namedDirection.getRowDelta();
            columnDelta += namedDirection.getColumnDelta();
        }
        legalRelativePositions.add(new Direction(rowDelta, columnDelta)); // NOPMD
    }

    return legalRelativePositions;
}

From source file:org.spongepowered.common.data.builder.manipulator.mutable.item.PlaceableDataBuilder.java

@Override
public Optional<PlaceableData> createFrom(DataHolder dataHolder) {
    if (dataHolder instanceof ItemStack) {
        NBTTagCompound tag = ((ItemStack) dataHolder).getTagCompound();
        if (tag == null) {
            return Optional.of(new SpongePlaceableData());
        }/*from   ww  w .java 2s  .c o m*/
        NBTTagList blockIds = tag.getTagList(NbtDataUtil.ITEM_PLACEABLE_BLOCKS, NbtDataUtil.TAG_STRING);
        if (blockIds.hasNoTags()) {
            return Optional.of(new SpongePlaceableData());
        }
        Set<BlockType> blockTypes = Sets.newHashSetWithExpectedSize(blockIds.tagCount());
        for (int i = 0; i < blockIds.tagCount(); i++) {
            Optional<BlockType> blockType = Sponge.getGame().getRegistry().getType(BlockType.class,
                    blockIds.getStringTagAt(i));
            if (blockType.isPresent()) {
                blockTypes.add(blockType.get());
            }
        }
        return Optional.of(new SpongePlaceableData(blockTypes));
    }
    return Optional.empty();
}

From source file:org.spongepowered.common.data.builder.manipulator.mutable.item.BreakableDataBuilder.java

@Override
public Optional<BreakableData> createFrom(DataHolder dataHolder) {
    if (dataHolder instanceof ItemStack) {
        NBTTagCompound tag = ((ItemStack) dataHolder).getTagCompound();
        if (tag == null) {
            return Optional.of(new SpongeBreakableData());
        }//from  w  ww.j a v  a 2  s.c  o  m
        NBTTagList blockIds = tag.getTagList(NbtDataUtil.ITEM_BREAKABLE_BLOCKS, NbtDataUtil.TAG_STRING);
        if (blockIds.hasNoTags()) {
            return Optional.of(new SpongeBreakableData());
        }
        Set<BlockType> blockTypes = Sets.newHashSetWithExpectedSize(blockIds.tagCount());
        for (int i = 0; i < blockIds.tagCount(); i++) {
            Optional<BlockType> blockType = Sponge.getGame().getRegistry().getType(BlockType.class,
                    blockIds.getStringTagAt(i));
            if (blockType.isPresent()) {
                blockTypes.add(blockType.get());
            }
        }
        return Optional.of(new SpongeBreakableData(blockTypes));
    }
    return Optional.empty();
}

From source file:org.gradle.internal.locking.DefaultDependencyLockingProvider.java

@Override
public DependencyLockingState loadLockState(String configurationName) {
    if (!writeLocks || partialUpdate) {
        List<String> lockedModules = lockFileReaderWriter.readLockFile(configurationName);
        if (lockedModules != null) {
            Set<ModuleComponentIdentifier> results = Sets.newHashSetWithExpectedSize(lockedModules.size());
            for (String module : lockedModules) {
                ModuleComponentIdentifier lockedIdentifier = parseLockNotation(configurationName, module);
                if (!lockEntryFilter.isSatisfiedBy(lockedIdentifier)) {
                    results.add(lockedIdentifier);
                }//from  ww  w.  jav  a2  s .  c o m
            }
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Loaded lock state for configuration '{}', state is: {}",
                        context.identityPath(configurationName), lockedModules);
            } else {
                LOGGER.info("Loaded lock state for configuration '{}'",
                        context.identityPath(configurationName));
            }
            return new DefaultDependencyLockingState(partialUpdate, results);
        }
    }
    return DefaultDependencyLockingState.EMPTY_LOCK_CONSTRAINT;
}