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.opengamma.bbg.livedata.AbstractBloombergLiveDataServer.java

@Override
public Map<String, FudgeMsg> doSnapshot(Collection<String> uniqueIds) {
    ArgumentChecker.notNull(uniqueIds, "Unique IDs");
    if (uniqueIds.isEmpty()) {
        return Collections.emptyMap();
    }//from   w ww. j a v a  2 s .  co  m

    Set<String> buids = Sets.newHashSetWithExpectedSize(uniqueIds.size());
    for (String uniqueId : uniqueIds) {
        String buid = getBloombergSubscriptionPathPrefix() + uniqueId;
        buids.add(buid);
    }

    // caching ref data provider must not be used here
    Map<String, FudgeMsg> snapshotValues = getReferenceDataProvider().getReferenceDataIgnoreCache(buids,
            BloombergDataUtils.STANDARD_FIELDS_SET);
    Map<String, FudgeMsg> returnValue = Maps.newHashMap();
    for (String buid : buids) {
        FudgeMsg fieldData = snapshotValues.get(buid);
        if (fieldData == null) {
            Exception e = new Exception("Stack Trace");
            e.fillInStackTrace();
            s_logger.error("Could not find result for {} in data snapshot, skipping", buid, e);
            //throw new OpenGammaRuntimeException("Result for " + buid + " was not found");
        } else {
            String securityUniqueId = buid.substring(getBloombergSubscriptionPathPrefix().length());
            returnValue.put(securityUniqueId, fieldData);
        }
    }
    return returnValue;
}

From source file:net.automatalib.util.automata.cover.IncrementalTransitionCoverIterator.java

@Override
protected Word<I> computeNext() {
    // first invocation
    if (inputIterator == null) {
        initialize();/*  w w w  .  j  av a2s . co m*/

        curr = bfsQueue.poll();
        inputIterator = inputs.iterator();
    }

    while (curr != null) {
        while (inputIterator.hasNext()) {
            final I in = inputIterator.next();

            if (curr.coveredInputs.add(in)) {
                final S succ = automaton.getSuccessor(curr.state, in);

                if (succ != null) {
                    final Word<I> succAs = curr.accessSequence.append(in);

                    if (reach.get(succ) == null) {
                        final Record<S, I> succRec = new Record<>(succ, succAs,
                                Sets.newHashSetWithExpectedSize(inputs.size()));
                        reach.put(succ, succRec);
                        bfsQueue.add(succRec);
                    }

                    return succAs;
                }
            }
        }

        curr = bfsQueue.poll();
        inputIterator = inputs.iterator();
    }

    return endOfData();
}

From source file:com.android.build.gradle.internal.dsl.NdkOptions.java

@NonNull
public NdkOptions abiFilter(String filter) {
    if (abiFilters == null) {
        abiFilters = Sets.newHashSetWithExpectedSize(2);
    }//from   ww w  .  j a v  a 2  s .c  o  m
    abiFilters.add(filter);
    return this;
}

From source file:com.android.build.gradle.internal.dsl.NdkConfigDsl.java

@NonNull
public NdkConfigDsl abiFilter(String filter) {
    if (abiFilters == null) {
        abiFilters = Sets.newHashSetWithExpectedSize(2);
    }//  w w w. j  a va  2s.  co m
    abiFilters.add(filter);
    return this;
}

From source file:defrac.intellij.ui.DefracPlatformChooser.java

public Set<DefracPlatform> getPlatforms() {
    final Set<DefracPlatform> set = Sets.newHashSetWithExpectedSize(4);
    if (getAndroid())
        set.add(DefracPlatform.ANDROID);
    if (getIOS())
        set.add(DefracPlatform.IOS);/*  ww w  .  j a va2s  .  com*/
    if (getJVM())
        set.add(DefracPlatform.JVM);
    if (getWeb())
        set.add(DefracPlatform.WEB);
    return set;
}

From source file:org.sosy_lab.cpachecker.pcc.strategy.PartitionedReachedSetStrategy.java

@Override
public boolean checkCertificate(ReachedSet pReachedSet) throws CPAException, InterruptedException {
    final AtomicBoolean checkResult = new AtomicBoolean(true);

    Multimap<CFANode, AbstractState> partitionNodes = HashMultimap.create();
    Collection<AbstractState> inOtherPartition = new HashSet<>();
    Collection<AbstractState> certificate = Sets.newHashSetWithExpectedSize(ioHelper.getSavedReachedSetSize());

    AbstractState initialState = pReachedSet.popFromWaitlist();
    Precision initPrec = pReachedSet.getPrecision(initialState);

    PartitioningCheckingHelper checkInfo = new PartitioningCheckingHelper() {

        @Override/*  w  w w. j  av  a 2s  .c  om*/
        public int getCurrentCertificateSize() {
            return 0;
        }

        @Override
        public void abortCheckingPreparation() {
            checkResult.set(false);
        }
    };
    PartitionChecker checker = new PartitionChecker(initPrec, cpa.getStopOperator(), cpa.getTransferRelation(),
            ioHelper, checkInfo, shutdownNotifier, logger);

    for (int i = 0; i < ioHelper.getNumPartitions() && checkResult.get(); i++) {
        checker.checkPartition(i);
        checker.addCertificatePartsToCertificate(certificate);
        checker.clearPartitionElementsSavedForInspection();
    }

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

    checker.addPartitionElements(partitionNodes);
    checker.addElementsCheckedInOtherPartitions(inOtherPartition);

    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 (!PartitioningUtils.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;
}

From source file:org.apache.mahout.cf.taste.example.kddcup.track2.Track2Callable.java

@Override
public UserResult call() throws TasteException {

    int testSize = userTest.length();
    if (testSize != 6) {
        throw new IllegalArgumentException("Expecting 6 items for user but got " + userTest);
    }//from w w w  .j  a va2  s . c o  m
    long userID = userTest.get(0).getUserID();
    TreeMap<Double, Long> estimateToItemID = new TreeMap<Double, Long>(Collections.reverseOrder());

    for (int i = 0; i < testSize; i++) {
        long itemID = userTest.getItemID(i);
        double estimate;
        try {
            estimate = recommender.estimatePreference(userID, itemID);
        } catch (NoSuchItemException nsie) {
            // OK in the sample data provided before the contest, should never happen otherwise
            log.warn("Unknown item {}; OK unless this is the real contest data", itemID);
            continue;
        }

        if (!Double.isNaN(estimate)) {
            estimateToItemID.put(estimate, itemID);
        }
    }

    Collection<Long> itemIDs = estimateToItemID.values();
    List<Long> topThree = Lists.newArrayList(itemIDs);
    if (topThree.size() > 3) {
        topThree = topThree.subList(0, 3);
    } else if (topThree.size() < 3) {
        log.warn("Unable to recommend three items for {}", userID);
        // Some NaNs - just guess at the rest then
        Collection<Long> newItemIDs = Sets.newHashSetWithExpectedSize(3);
        newItemIDs.addAll(itemIDs);
        int i = 0;
        while (i < testSize && newItemIDs.size() < 3) {
            newItemIDs.add(userTest.getItemID(i));
            i++;
        }
        topThree = Lists.newArrayList(newItemIDs);
    }
    if (topThree.size() != 3) {
        throw new IllegalStateException();
    }

    boolean[] result = new boolean[testSize];
    for (int i = 0; i < testSize; i++) {
        result[i] = topThree.contains(userTest.getItemID(i));
    }

    if (COUNT.incrementAndGet() % 1000 == 0) {
        log.info("Completed {} users", COUNT.get());
    }

    return new UserResult(userID, result);
}

From source file:org.gradoop.flink.algorithms.fsm.functions.SubgraphDecoder.java

@Override
public GraphTransaction map(Subgraph value) throws Exception {

    // GRAPH HEAD

    PropertyList properties = new PropertyList();

    properties.set(FREQUENCY_KEY, value.getCount());
    properties.set(CANONICAL_LABEL_KEY, value.getSubgraph());

    GraphHead epgmGraphHead = graphHeadFactory.createGraphHead(SUBGRAPH_LABEL, properties);

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

    // VERTICES//w w w .j a  va2s  .c  o m

    Map<Integer, String> vertices = value.getEmbedding().getVertices();
    Set<Vertex> epgmVertices = Sets.newHashSetWithExpectedSize(vertices.size());
    Map<Integer, GradoopId> vertexIdMap = Maps.newHashMapWithExpectedSize(vertices.size());

    for (Map.Entry<Integer, String> vertex : vertices.entrySet()) {
        Vertex epgmVertex = vertexFactory.createVertex(vertex.getValue(), graphIds);

        vertexIdMap.put(vertex.getKey(), epgmVertex.getId());
        epgmVertices.add(epgmVertex);

    }

    // EDGES

    Collection<FSMEdge> edges = value.getEmbedding().getEdges().values();
    Set<Edge> epgmEdges = Sets.newHashSetWithExpectedSize(edges.size());

    for (FSMEdge edge : edges) {
        epgmEdges.add(edgeFactory.createEdge(edge.getLabel(), vertexIdMap.get(edge.getSourceId()),
                vertexIdMap.get(edge.getTargetId()), graphIds));
    }

    return new GraphTransaction(epgmGraphHead, epgmVertices, epgmEdges);
}

From source file:com.twitter.elephanttwin.lucene.indexing.HadoopSplitDocument.java

@Override
public void readFields(DataInput in) throws IOException {
    clear();/*from  w  w  w. j  ava  2s  .  com*/
    cnt = in.readInt();
    offset = in.readLong();
    int numKeyVals = in.readInt();
    keyValueListMap = Maps.newHashMapWithExpectedSize(numKeyVals);
    for (int i = 0; i < numKeyVals; i++) {
        String key = in.readUTF();
        int numEntries = in.readInt();
        Set<String> valueSet = Sets.newHashSetWithExpectedSize(numEntries);
        for (int j = 0; j < numEntries; j++) {
            valueSet.add(in.readUTF());
        }
        keyValueListMap.put(key, valueSet);
    }
    if (split == null) {
        // Initializing to nonsense
        split = new FileSplit(null, 0, 0, null);
    }
    split.readFields(in);

}

From source file:com.opengamma.engine.fudgemsg.CompiledViewCalculationConfigurationFudgeBuilder.java

protected Set<ComputationTargetSpecification> decodeComputationTargets(final FudgeDeserializer deserializer,
        final FudgeMsg msg) {
    final FudgeMsg submsg = msg.getMessage(COMPUTATION_TARGETS_FIELD);
    if (submsg == null) {
        return Collections.emptySet();
    }//from w  w  w.  j a va  2s. c  o m
    final Set<ComputationTargetSpecification> result = Sets.newHashSetWithExpectedSize(submsg.getNumFields());
    for (final FudgeField field : submsg) {
        result.add(deserializer.fieldValueToObject(ComputationTargetReference.class, field).getSpecification());
    }
    return result;
}