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.build.gradle.internal.dsl.NdkConfigDsl.java

@NonNull
public NdkConfigDsl setAbiFilters(Collection<String> filters) {
    if (filters != null) {
        if (abiFilters == null) {
            abiFilters = Sets.newHashSetWithExpectedSize(filters.size());
        } else {// w ww.j  a v  a  2s . c  om
            abiFilters.clear();
        }
        for (String filter : filters) {
            abiFilters.add(filter);
        }
    } else {
        abiFilters = null;
    }
    return this;
}

From source file:org.n52.sos.inspire.AbstractInspireProvider.java

/**
 * Remove the default CRS from other CRS set
 * //from   ww  w  .  j  a  v a 2s  .c  om
 * @param defaultCRS
 *            Default CRS to remove
 * @param otherCRS
 *            Other CRSes
 * @return Set without default CRS
 */
protected Set<Integer> removeDefaultCRS(int defaultCRS, Set<Integer> otherCRS) {
    Set<Integer> checkSet = Sets.newHashSetWithExpectedSize(otherCRS.size());
    for (Integer integer : otherCRS) {
        if (integer != defaultCRS) {
            checkSet.add(integer);
        }

    }
    return checkSet;
}

From source file:com.textocat.textokit.postagger.opennlp.DictionaryBasedContextGenerator.java

public List<String> extract(Token focusToken, String prevTag) {
    if (!(focusToken instanceof W)) {
        return ImmutableList.of();
    }/*from ww w.ja v a 2 s  .c o  m*/
    String form = focusToken.getCoveredText();
    if (!WordUtils.isRussianWord(form)) {
        return ImmutableList.of("DL=NotRussian");
    }
    form = WordUtils.normalizeToDictionaryForm(form);
    List<Wordform> dictWfs = morphDict.getEntries(form);
    if (dictWfs == null || dictWfs.isEmpty()) {
        return ImmutableList.of("DL=Unknown");
    }
    List<BitSet> dictWfBitSets = Lists.transform(dictWfs, Wordform.allGramBitsFunction(morphDict));
    //
    Set<BitSet> tokenPossibleTags = Sets.newHashSetWithExpectedSize(dictWfBitSets.size());
    for (BitSet dictWfBits : dictWfBitSets) {
        BitSet tokenPossibleBits = (BitSet) dictWfBits.clone();
        tokenPossibleBits.and(targetCategoriesMask);
        tokenPossibleTags.add(tokenPossibleBits);
    }
    List<String> resultList = Lists.newArrayListWithExpectedSize(tokenPossibleTags.size());
    for (BitSet tokenPossibleBits : tokenPossibleTags) {
        String featValue;
        if (tokenPossibleBits.isEmpty()) {
            featValue = "NULL";
        } else {
            featValue = gramJoiner.join(gramModel.toGramSet(tokenPossibleBits));
        }
        resultList.add("DL=" + featValue);
    }
    if (prevTag != null && !PunctuationUtils.isPunctuationTag(prevTag)) {
        // add the name of a predicate if it yields true for any pair <prevTag, dictTag>, dictTag in tokenPossibleTags
        BitSet prevTagBits = toGramBits(gramModel, tagMapper.parseTag(prevTag, focusToken.getCoveredText()));
        for (Map.Entry<String, TwoTagPredicate> predEntry : namedPredicates.entrySet()) {
            for (BitSet dictTag : tokenPossibleTags) {
                if (predEntry.getValue().apply(prevTagBits, dictTag)) {
                    resultList.add(predEntry.getKey());
                    break;
                }
            }
        }
    }
    return resultList;
}

From source file:org.sosy_lab.cpachecker.pcc.strategy.parallel.PartialReachedSetPartitioningParallelStrategy.java

@Override
public boolean checkCertificate(ReachedSet pReachedSet) throws CPAException, InterruptedException {
    AtomicBoolean checkResult = new AtomicBoolean(true);
    AtomicInteger availablePartitions = new AtomicInteger(0);
    AtomicInteger nextId = new AtomicInteger(0);
    Semaphore partitionChecked = new Semaphore(0);
    Semaphore readButUnprocessed = new Semaphore(ioHelper.getNumPartitions());
    Lock lock = new ReentrantLock();

    Collection<AbstractState> certificate = Sets.newHashSetWithExpectedSize(ioHelper.getNumPartitions());
    Multimap<CFANode, AbstractState> partitionNodes = HashMultimap.create();
    Collection<AbstractState> inOtherPartition = new ArrayList<>();
    AbstractState initialState = pReachedSet.popFromWaitlist();
    Precision initPrec = pReachedSet.getPrecision(initialState);

    logger.log(Level.INFO, "Create and start threads");
    ExecutorService executor = Executors.newFixedThreadPool(numThreads);
    try {//w  w  w.java 2 s  .c  om
        for (int i = 0; i < numThreads; i++) {
            executor.execute(new ParallelPartitionChecker(availablePartitions, nextId, checkResult,
                    readButUnprocessed, partitionChecked, lock, ioHelper, partitionNodes, certificate,
                    inOtherPartition, initPrec, cpa.getStopOperator(), cpa.getTransferRelation(),
                    shutdownNotifier, logger));
        }

        partitionChecked.acquire(ioHelper.getNumPartitions());

        if (!checkResult.get()) {
            return false;
        }

        logger.log(Level.INFO,
                "Add initial state to elements for which it will be checked if they are covered by partition nodes of certificate.");
        inOtherPartition.add(initialState);

        logger.log(Level.INFO,
                "Check if initial state and all nodes which should be contained in different partition are covered by certificate (partition node).");
        if (!PartitionChecker.areElementsCoveredByPartitionElement(inOtherPartition, partitionNodes,
                cpa.getStopOperator(), initPrec)) {
            logger.log(Level.SEVERE,
                    "Initial state or a state which should be in other partition is not covered by certificate.");
            return false;
        }

        logger.log(Level.INFO, "Check property.");
        stats.getPropertyCheckingTimer().start();
        try {
            if (!cpa.getPropChecker().satisfiesProperty(certificate)) {
                logger.log(Level.SEVERE, "Property violated");
                return false;
            }
        } finally {
            stats.getPropertyCheckingTimer().stop();
        }

        return true;
    } finally {
        executor.shutdown();
    }
}

From source file:com.edmunds.etm.runtime.api.ApplicationSeries.java

/**
 * Gets the inactive application versions in this series.
 *
 * @return a collection of the inactive applications
 *///  www. j  a  v a2  s. c  o  m
public Set<Application> getInactiveVersions() {
    Set<Application> applications = Sets.newHashSetWithExpectedSize(applicationsByVersion.size());
    for (Application app : applicationsByVersion.values()) {
        if (!app.isActive()) {
            applications.add(app);
        }
    }
    return applications;
}

From source file:org.apache.pig.impl.util.avro.AvroMapWrapper.java

@Override
public Set<java.util.Map.Entry<CharSequence, Object>> entrySet() {
    Set<java.util.Map.Entry<CharSequence, Object>> theSet = Sets.newHashSetWithExpectedSize(innerMap.size());
    for (java.util.Map.Entry<CharSequence, Object> e : innerMap.entrySet()) {
        CharSequence k = e.getKey();
        final Object v = AvroTupleWrapper.getPigObject(e.getValue());
        if (k instanceof Utf8) {
            k = k.toString();/*  w  w w. j  a  v a 2 s.c  om*/
        }
        theSet.add(new AbstractMap.SimpleEntry<CharSequence, Object>(k, v));
    }
    return theSet;
}

From source file:com.opengamma.financial.analytics.model.equity.option.EquityOptionBlackFundingCurveSensitivitiesFunction.java

@Override
public Set<ValueSpecification> getResults(final FunctionCompilationContext context,
        final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) {
    final Set<ValueSpecification> results = super.getResults(context, target, inputs);
    final Set<ValueSpecification> resultsWithCurve = Sets.newHashSetWithExpectedSize(results.size());
    for (final ValueSpecification spec : results) {
        final String name = spec.getValueName();
        final ComputationTargetSpecification targetSpec = spec.getTargetSpecification();
        final ValueProperties properties = spec.getProperties().copy().withAny(ValuePropertyNames.CURVE).get();
        resultsWithCurve.add(new ValueSpecification(name, targetSpec, properties));
    }/*from  ww  w.  j a v a2s.  c o  m*/
    return results;
}

From source file:com.google.javascript.jscomp.DefaultNameGenerator.java

public DefaultNameGenerator() {
    buildPriorityLookupMap();
    Set<String> reservedNames = Sets.newHashSetWithExpectedSize(0);
    reset(reservedNames, "", null);
}

From source file:com.palantir.atlasdb.keyvalue.impl.TableRemappingKeyValueService.java

@Override
public void dropTables(Set<TableReference> tableRefs) {
    Set<String> tableNames = Sets.newHashSetWithExpectedSize(tableRefs.size());
    for (TableReference tableRef : tableRefs) {
        tableNames.add(tableMapper.getShortTableName(tableRef));
        delegate().dropTables(tableNames);
    }// w  ww .  ja v  a  2s .c  o m
    delegate().dropTables(tableNames);

    // We're purposely updating the table mappings after all drops are complete
    for (TableReference tableRef : tableRefs) {
        // Handles the edge case of deleting _namespace when clearing the kvs
        if (tableRef.getNamespace().equals(Namespace.EMPTY_NAMESPACE)
                && tableRef.getTablename().equals(AtlasDbConstants.NAMESPACE_TABLE)) {
            break;
        }
        tableMapper.removeTable(tableRef);
    }
}

From source file:org.gradoop.flink.algorithms.fsm.dimspan.functions.conversion.DFSCodeToEPGMGraphTransaction.java

@Override
public GraphTransaction map(WithCount<int[]> patternWithCount) throws Exception {

    int[] pattern = patternWithCount.getObject();

    if (uncompressPatterns) {
        pattern = Simple16Compressor.uncompress(pattern);
    }/*w  w  w.  j a v  a  2s.c  om*/

    long frequency = patternWithCount.getCount();

    // GRAPH HEAD
    GraphHead graphHead = new GraphHead(GradoopId.get(), "", null);
    graphHead.setLabel(DIMSpanConstants.FREQUENT_PATTERN_LABEL);
    graphHead.setProperty(DIMSpanConstants.SUPPORT_KEY, (float) frequency / graphCount);

    GradoopIdSet graphIds = GradoopIdSet.fromExisting(graphHead.getId());

    // VERTICES
    int[] vertexLabels = graphUtils.getVertexLabels(pattern);

    GradoopId[] vertexIds = new GradoopId[vertexLabels.length];

    Set<Vertex> vertices = Sets.newHashSetWithExpectedSize(vertexLabels.length);

    int intId = 0;
    for (int intLabel : vertexLabels) {
        String label = vertexDictionary[intLabel];

        GradoopId gradoopId = GradoopId.get();
        vertices.add(new Vertex(gradoopId, label, null, graphIds));

        vertexIds[intId] = gradoopId;
        intId++;
    }

    // EDGES
    Set<Edge> edges = Sets.newHashSet();

    for (int edgeId = 0; edgeId < graphUtils.getEdgeCount(pattern); edgeId++) {
        String label = edgeDictionary[graphUtils.getEdgeLabel(pattern, edgeId)];

        GradoopId sourceId;
        GradoopId targetId;

        if (graphUtils.isOutgoing(pattern, edgeId)) {
            sourceId = vertexIds[graphUtils.getFromId(pattern, edgeId)];
            targetId = vertexIds[graphUtils.getToId(pattern, edgeId)];
        } else {
            sourceId = vertexIds[graphUtils.getToId(pattern, edgeId)];
            targetId = vertexIds[graphUtils.getFromId(pattern, edgeId)];
        }

        edges.add(new Edge(GradoopId.get(), label, sourceId, targetId, null, graphIds));
    }

    return new GraphTransaction(graphHead, vertices, edges);
}