List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
From source file:com.opengamma.financial.view.ViewEvaluationFunction.java
@Override @SuppressWarnings("unchecked") public Set<ValueSpecification> getResults(final FunctionCompilationContext context, final ComputationTarget target) { final TTarget viewEvaluation = (TTarget) target.getValue(); final Collection<String> calcConfigs = viewEvaluation.getViewDefinition() .getAllCalculationConfigurationNames(); final Set<ValueSpecification> results = Sets.newHashSetWithExpectedSize(calcConfigs.size()); final ComputationTargetSpecification targetSpec = target.toSpecification(); for (final String calcConfig : calcConfigs) { results.add(getResultSpec(calcConfig, targetSpec)); }//w ww. j a va 2s . c om return results; }
From source file:com.twitter.common.collections.Multimaps.java
/** * Returns the set of keys associated with the largest values in the multimap. * * @param map The multimap to search.//www .j a v a 2 s. com * @param topValues Number of groupings to find the keys for. * @return The keys associated with the largest groups, of maximum size {@code topValues}. */ public static <K> Set<K> getLargestGroups(Multimap<K, ?> map, int topValues) { Ordering<Multiset.Entry<K>> groupOrdering = new Ordering<Multiset.Entry<K>>() { @Override public int compare(Multiset.Entry<K> entry1, Multiset.Entry<K> entry2) { return entry1.getCount() - entry2.getCount(); // overflow-safe, since sizes are nonnegative } }; Set<K> topKeys = Sets.newHashSetWithExpectedSize(topValues); for (Multiset.Entry<K> entry : groupOrdering.greatestOf(map.keys().entrySet(), topValues)) { topKeys.add(entry.getElement()); } return topKeys; }
From source file:org.sosy_lab.cpachecker.pcc.strategy.parallel.interleaved.PartialReachedSetIOCheckingOnlyInterleavedStrategy.java
@Override public boolean checkCertificate(ReachedSet pReachedSet) throws CPAException, InterruptedException { final AtomicBoolean checkResult = new AtomicBoolean(true); Semaphore partitionsAvailable = new Semaphore(0); 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); logger.log(Level.INFO, "Create reading thread"); Thread readingThread = new Thread(new PartitionReader(checkResult, partitionsAvailable)); try {//from w ww . j av a 2s.c o m readingThread.start(); PartitioningCheckingHelper checkInfo = new PartitioningCheckingHelper() { @Override 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++) { partitionsAvailable.acquire(); if (!checkResult.get()) { return false; } 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 (!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 { checkResult.set(false); readingThread.interrupt(); } }
From source file:org.jetbrains.jet.lang.resolve.calls.smartcasts.DelegatingDataFlowInfo.java
@Override @NotNull// www . j av a2s .c o m public Set<JetType> getPossibleTypes(@NotNull DataFlowValue key) { Set<JetType> theseTypes = typeInfo.get(key); Set<JetType> types = parent == null ? theseTypes : Sets.union(theseTypes, parent.getPossibleTypes(key)); if (getNullability(key).canBeNull()) { return types; } Set<JetType> enrichedTypes = Sets.newHashSetWithExpectedSize(types.size() + 1); JetType originalType = key.getType(); if (originalType.isNullable()) { enrichedTypes.add(TypeUtils.makeNotNullable(originalType)); } for (JetType type : types) { enrichedTypes.add(TypeUtils.makeNotNullable(type)); } return enrichedTypes; }
From source file:com.google.gerrit.server.git.HackPushNegotiateHook.java
private static Set<ObjectId> idsOf(Collection<Ref> refs) { Set<ObjectId> r = Sets.newHashSetWithExpectedSize(refs.size()); for (Ref ref : refs) { if (ref.getObjectId() != null) { r.add(ref.getObjectId());/* w ww . j a va 2 s. co m*/ } } return r; }
From source file:com.edmunds.etm.management.impl.VipManager.java
private void updateVip(ManagementVip vip) { if (!vip.hasChanges()) { return;/*from w w w.j a v a2 s .c o m*/ } // Update vip pool members Collection<ManagementPoolMember> deltaMembers = vip.getPoolMembers().values(); Set<ManagementPoolMember> updatedMembers = Sets.newHashSetWithExpectedSize(deltaMembers.size()); for (ManagementPoolMember poolMember : deltaMembers) { switch (poolMember.getLoadBalancerState()) { case CREATE_REQUEST: updatedMembers.add(poolMember); break; case ACTIVE: updatedMembers.add(poolMember); break; case DELETE_REQUEST: break; default: throw new IllegalStateException("Unexpected State: " + vip.getLoadBalancerState()); } } // Write the new vip ManagementVip updatedVip = new ManagementVip(vip.getLoadBalancerState(), vip.getMavenModule(), vip.getHostAddress(), updatedMembers, vip.getRootContext(), vip.getRules(), vip.getHttpMonitor()); final String vipPath = getVipNodePath(vip); ManagementVipDto vipDto = ManagementVip.writeDto(updatedVip); setNodeData(vipPath, vipDtoToBytes(vipDto)); }
From source file:concretisations.checkers.pieces.CheckerPiece.java
private Set<DirectionInterface> getMutations(final ManagedCellInterface cell, final SideInterface side, final CheckersMutations mutationType) { final Set<DirectionInterface> mutations = Sets.newHashSetWithExpectedSize(this.legalDirections.size()); final Predicate predicate = this.getPredicate(mutationType); for (final DirectionInterface direction : this.legalDirections) { if (predicate.apply(cell, side, direction)) { mutations.add(direction);//from w w w .j av a 2 s . com } } return mutations; }
From source file:com.opengamma.financial.analytics.model.option.StandardOptionDataAnalyticOptionModelFunction.java
@Override public Set<ValueSpecification> getResults(final FunctionCompilationContext context, final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) { final Set<ValueSpecification> originalResults = getResults(context, target); String curveName = null;/* w ww.j av a2 s.com*/ for (final ValueSpecification input : inputs.keySet()) { if (ValueRequirementNames.YIELD_CURVE.equals(input.getValueName())) { curveName = input.getProperty(ValuePropertyNames.CURVE); } } if (curveName == null) { // No yield curve in our inputs, so no yield curve in our output return originalResults; } final Set<ValueSpecification> newResults = Sets.newHashSetWithExpectedSize(originalResults.size()); for (final ValueSpecification result : originalResults) { newResults.add(new ValueSpecification(result.getValueName(), result.getTargetSpecification(), result.getProperties().copy().withoutAny(ValuePropertyNames.CURVE) .with(ValuePropertyNames.CURVE, curveName).get())); } return newResults; }
From source file:org.sosy_lab.cpachecker.pcc.strategy.parallel.io.PartialReachedSetParallelReadingStrategy.java
@Override public boolean checkCertificate(final ReachedSet pReachedSet) throws CPAException, InterruptedException { AtomicBoolean checkResult = new AtomicBoolean(true); AtomicInteger availablePartitions = new AtomicInteger(0); AtomicInteger id = new AtomicInteger(0); Semaphore partitionChecked = new Semaphore(0); Semaphore readPartitions = new Semaphore(ioHelper.getNumPartitions()); 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"); int threads = enableParallelCheck ? numThreads : 1; ExecutorService executor = Executors.newFixedThreadPool(threads); try {// w ww.j a v a 2s. c o m for (int i = 0; i < threads; i++) { executor.execute(new ParallelPartitionChecker(availablePartitions, id, checkResult, readPartitions, 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.pinterest.terrapin.controller.HdfsManager.java
static double calculateDeviationForResource(String resource, IdealState idealState, RoutingTableProvider routingTableProvider) { Set<String> partitions = idealState.getPartitionSet(); int totalAssignments = 0, totalDeviations = 0; // Check if the external view has deviated from the actual view. for (String partition : partitions) { // Make a copy of the instance mapping in the ideal state. Set<String> idealInstances = new HashSet(idealState.getInstanceSet(partition)); totalAssignments += idealInstances.size(); // Now check against our real state and count the amount of deviating // assignments. List<InstanceConfig> currentInstanceConfigs = routingTableProvider.getInstances(resource, partition, "ONLINE"); Set<String> currentInstances = Sets.newHashSetWithExpectedSize(currentInstanceConfigs.size()); if (currentInstanceConfigs != null) { for (InstanceConfig instanceConfig : currentInstanceConfigs) { currentInstances.add(instanceConfig.getHostName()); }//w w w . j a v a 2s . co m } idealInstances.removeAll(currentInstances); totalDeviations += idealInstances.size(); } return (double) totalDeviations / totalAssignments; }