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:presto.android.gui.listener.ListenerRegistration.java

public Set<SootMethod> getHandlerPrototypes() {
    Set<SootMethod> result = Sets.newHashSetWithExpectedSize(handlers.size());
    for (EventHandler h : handlers) {
        String subsig = h.subsig;
        result.add(listenerClass.getMethod(subsig));
    }/*from   w  w w. j  a v  a  2 s  .  com*/
    return result;
}

From source file:com.github.steveash.typedconfig.resolver.type.container.SetValueResolverFactory.java

@Override
protected Collection<Object> makeEmptyCollection(int size) {
    return Sets.newHashSetWithExpectedSize(size);
}

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

/**
 * Given a backend-specific Soy function type and the set of all Soy function implementations,
 * finds the Soy functions that are implemented for the specific backend and returns them in the
 * form of a map from function name to function.
 *
 * @param backendSpecificSoyFunctionType The backend-specific Soy function type to filter for.
 * @param soyFunctionsSet The set of all Soy functions.
 * @return A map of the relevant backend-specific Soy functions (name to function).
 *///from   ww w .  j a v a 2  s  . co m
public static <T extends SoyFunction> Map<String, T> buildBackendSpecificSoyFunctionsMap(
        Class<T> backendSpecificSoyFunctionType, Set<SoyFunction> soyFunctionsSet) {

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

    Set<String> seenFnNames = Sets.newHashSetWithExpectedSize(soyFunctionsSet.size());

    for (SoyFunction fn : soyFunctionsSet) {
        if (backendSpecificSoyFunctionType.isAssignableFrom(fn.getClass())) {
            String fnName = fn.getName();

            if (seenFnNames.contains(fnName) || ImpureFunction.forFunctionName(fnName) != null) {
                throw new IllegalStateException(
                        "Found two implementations of " + backendSpecificSoyFunctionType.getSimpleName()
                                + " with the same function name '" + fnName + "'.");
            }
            seenFnNames.add(fnName);

            mapBuilder.put(fnName, backendSpecificSoyFunctionType.cast(fn));
        }
    }

    return mapBuilder.build();
}

From source file:com.google.gerrit.server.git.DestinationList.java

protected static Set<Branch.NameKey> toSet(List<Row> destRows) {
    Set<Branch.NameKey> dests = Sets.newHashSetWithExpectedSize(destRows.size());
    for (Row row : destRows) {
        dests.add(new Branch.NameKey(new Project.NameKey(row.right), row.left));
    }//from w w w. j  a v a 2  s  . c  om
    return dests;
}

From source file:org.terasology.reflection.copy.strategy.SetCopyStrategy.java

@Override
public Set<T> copy(Set<T> value) {
    if (value != null) {
        Set<T> result = Sets.newHashSetWithExpectedSize(value.size());
        for (T item : value) {
            result.add(contentStrategy.copy(item));
        }/* w  ww. j  a v  a2 s .c o m*/
        return result;
    }
    return null;
}

From source file:org.graylog2.grok.GrokPatterns.java

public static Set<GrokPattern> fromSummarySet(Collection<GrokPatternSummary> grokPatternSummaries) {
    final Set<GrokPattern> result = Sets.newHashSetWithExpectedSize(grokPatternSummaries.size());
    for (GrokPatternSummary summary : grokPatternSummaries) {
        result.add(fromSummary(summary));
    }/*from   w  ww.  ja  v a  2  s.  c o  m*/

    return result;
}

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

/**
 * Given the set of all Soy function implementations and a specific Soy function type (subtype
 * of SoyFunction) to look for, finds the Soy functions that implement the specific type
 * and returns them in the form of a map from function name to function.
 *
 * @param <T> The specific Soy function type to look for.
 * @param soyFunctionsSet The set of all Soy functions.
 * @param specificSoyFunctionType The class of the specific Soy function type to look for.
 * @return A map of the relevant specific Soy functions (name to function).
 *//*from  ww w .j  a v  a2  s.  co  m*/
public static <T extends SoyFunction> ImmutableMap<String, T> buildSpecificSoyFunctionsMap(
        Set<SoyFunction> soyFunctionsSet, Class<T> specificSoyFunctionType) {

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

    Set<String> seenFnNames = Sets.newHashSetWithExpectedSize(soyFunctionsSet.size());

    for (SoyFunction fn : soyFunctionsSet) {
        if (specificSoyFunctionType.isAssignableFrom(fn.getClass())) {
            String fnName = fn.getName();

            if (seenFnNames.contains(fnName) || NonpluginFunction.forFunctionName(fnName) != null) {
                throw new IllegalStateException(
                        "Found two implementations of " + specificSoyFunctionType.getSimpleName()
                                + " with the same function name '" + fnName + "'.");
            }
            seenFnNames.add(fnName);

            mapBuilder.put(fnName, specificSoyFunctionType.cast(fn));
        }
    }

    return mapBuilder.build();
}

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

/**
 * Given the set of all Soy function implementations and a specific Soy function type (subtype
 * of SoyFunction) to look for, finds the Soy functions that implement the specific type
 * and returns them in the form of a map from function name to function.
 *
 * @param <T> The specific Soy function type to look for.
 * @param soyFunctionsSet The set of all Soy functions.
 * @param specificSoyFunctionType The class of the specific Soy function type to look for.
 * @return A map of the relevant specific Soy functions (name to function).
 *///from ww w  . j  av  a 2  s.  co  m
public static <T extends SoyFunction> ImmutableMap<String, T> buildSpecificSoyFunctionsMap(
        Set<SoyFunction> soyFunctionsSet, Class<T> specificSoyFunctionType) {

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

    Set<String> seenFnNames = Sets.newHashSetWithExpectedSize(soyFunctionsSet.size());

    for (SoyFunction fn : soyFunctionsSet) {
        if (specificSoyFunctionType.isAssignableFrom(fn.getClass())) {
            String fnName = fn.getName();

            if (seenFnNames.contains(fnName) || BuiltinFunction.forFunctionName(fnName) != null) {
                throw new IllegalStateException(
                        "Found two implementations of " + specificSoyFunctionType.getSimpleName()
                                + " with the same function name '" + fnName + "'.");
            }
            seenFnNames.add(fnName);

            mapBuilder.put(fnName, specificSoyFunctionType.cast(fn));
        }
    }

    return mapBuilder.build();
}

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

private static Set<NonAndroidSourceType> getNonEmptySourceTypes(Module module) {
    ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    Set<NonAndroidSourceType> sourceTypes = Sets
            .newHashSetWithExpectedSize(NonAndroidSourceType.values().length);

    ContentEntry[] contentEntries = rootManager.getContentEntries();
    for (ContentEntry entry : contentEntries) {
        for (NonAndroidSourceType type : NonAndroidSourceType.values()) {
            for (SourceFolder sourceFolder : entry.getSourceFolders(type.rootType)) {
                if (sourceFolder.getFile() != null) {
                    sourceTypes.add(type);
                    break;
                }//  w w  w  .  jav  a  2 s.c  om
            }
        }
    }

    return sourceTypes;
}

From source file:defrac.intellij.project.DefracProjectUtil.java

@NotNull
public static Module[] findModulesForPlatform(@Nullable final Project project,
        @NotNull final DefracPlatform platform, @Nullable final Condition<Module> condition) {
    if (project == null) {
        return Module.EMPTY_ARRAY;
    }//from w w w.j av  a  2  s  .c  o  m

    final Module[] modules = ModuleManager.getInstance(project).getModules();
    final Set<Module> platformModules = Sets
            .newHashSetWithExpectedSize(modules.length / (DefracPlatform.values().length));

    for (final Module module : modules) {
        final DefracFacet facet = DefracFacet.getInstance(module);

        if (facet == null || facet.getPlatform() != platform) {
            continue;
        }

        if (condition != null && !condition.value(module)) {
            continue;
        }

        platformModules.add(module);
    }

    return platformModules.toArray(new Module[platformModules.size()]);
}