List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
From source file:org.openscience.cdk.isomorphism.UniqueBondMatches.java
/** * Create filter for the expected number of unique matches. The number of * matches can grow if required.//w ww .ja va 2 s.c o m * * @param expectedHits expected number of unique matches */ private UniqueBondMatches(int[][] g, int expectedHits) { this.unique = Sets.newHashSetWithExpectedSize(expectedHits); this.g = g; }
From source file:org.gradle.internal.component.model.DefaultMultipleCandidateResult.java
@Override public void closestMatch(T candidate) { if (singleMatch == null) { if (multipleMatches == null) { singleMatch = candidate;/*from www . j a v a 2s .c o m*/ } else { multipleMatches.add(candidate); } return; } if (singleMatch.equals(candidate)) { return; } multipleMatches = Sets.newHashSetWithExpectedSize(candidateValues.size()); multipleMatches.add(singleMatch); multipleMatches.add(candidate); singleMatch = null; }
From source file:com.opengamma.language.convert.SetConverter.java
@Override public void convertValue(final ValueConversionContext conversionContext, final Object value, final JavaTypeInfo<?> type) { if ((value == null) && type.isAllowNull()) { conversionContext.setResult(null); return;/*from w w w .ja va 2 s . c o m*/ } if (type.getRawClass() == Set.class) { // Converting from Values[] to Set final Value[] values = (Value[]) value; final JavaTypeInfo<?> setType = type.getParameterizedType(0); final Set<Object> result = Sets.newHashSetWithExpectedSize(values.length); for (Value entry : values) { conversionContext.convertValue(entry, setType); if (conversionContext.isFailed()) { conversionContext.setFail(); return; } result.add(conversionContext.getResult()); } conversionContext.setResult(result); } else { // Converting from Set to Values[] final Set<?> set = (Set<?>) value; final Value[] result = new Value[set.size()]; int i = 0; for (Object entry : set) { if (entry == null) { result[i++] = new Value(); } else { conversionContext.convertValue(entry, VALUE); if (conversionContext.isFailed()) { conversionContext.setFail(); return; } result[i++] = conversionContext.getResult(); } } // TODO: be nice to sort the result conversionContext.setResult(result); } }
From source file:org.sosy_lab.cpachecker.cpa.composite.CompositeState.java
@Override public String getViolatedPropertyDescription() throws IllegalStateException { checkState(isTarget());// w w w.j av a2 s. c o m Set<String> descriptions = Sets.newHashSetWithExpectedSize(states.size()); for (AbstractState element : states) { if ((element instanceof Targetable) && ((Targetable) element).isTarget()) { descriptions.add(((Targetable) element).getViolatedPropertyDescription()); } } descriptions.remove(""); return Joiner.on(", ").join(descriptions); }
From source file:com.torodb.torod.db.backends.query.processors.ProcessorTestUtils.java
private static HashSet<ProcessedQueryCriteriaWrapper> convertProcessedQueryCriteria( Set<ProcessedQueryCriteria> queries) { HashSet<ProcessedQueryCriteriaWrapper> result = Sets.newHashSetWithExpectedSize(queries.size()); Iterables.addAll(result,/*from w ww.ja v a 2 s .co m*/ Iterables.transform(queries, new Function<ProcessedQueryCriteria, ProcessedQueryCriteriaWrapper>() { @Override public ProcessedQueryCriteriaWrapper apply(ProcessedQueryCriteria input) { return new ProcessedQueryCriteriaWrapper(input); } })); return result; }
From source file:com.android.build.gradle.internal.dsl.NdkConfigDsl.java
@NonNull public NdkConfigDsl ldLibs(String... libs) { if (ldLibs == null) { ldLibs = Sets.newHashSetWithExpectedSize(libs.length); }/*ww w . ja v a2s . c o m*/ Collections.addAll(ldLibs, libs); return this; }
From source file:com.android.build.gradle.internal.transforms.ProguardConfigurable.java
@NonNull @Override//from w ww .jav a2 s. co m public Set<Scope> getReferencedScopes() { Set<Scope> set = Sets.newHashSetWithExpectedSize(5); if (variantType == VariantType.LIBRARY) { set.add(Scope.SUB_PROJECTS); set.add(Scope.SUB_PROJECTS_LOCAL_DEPS); set.add(Scope.EXTERNAL_LIBRARIES); } if (variantType.isForTesting()) { set.add(Scope.TESTED_CODE); } set.add(Scope.PROVIDED_ONLY); return Sets.immutableEnumSet(set); }
From source file:com.android.build.gradle.internal.core.MergedNdkConfig.java
public void append(@NonNull CoreNdkOptions ndkConfig) { // override// w ww. ja v a 2s .co m if (ndkConfig.getModuleName() != null) { moduleName = ndkConfig.getModuleName(); } if (ndkConfig.getStl() != null) { stl = ndkConfig.getStl(); } if (ndkConfig.getJobs() != null) { jobs = ndkConfig.getJobs(); } // append if (ndkConfig.getAbiFilters() != null) { if (abiFilters == null) { abiFilters = Sets.newHashSetWithExpectedSize(ndkConfig.getAbiFilters().size()); } abiFilters.addAll(ndkConfig.getAbiFilters()); } if (cFlags == null) { cFlags = ndkConfig.getcFlags(); } else if (ndkConfig.getcFlags() != null && !ndkConfig.getcFlags().isEmpty()) { cFlags = cFlags + " " + ndkConfig.getcFlags(); } if (ndkConfig.getLdLibs() != null) { if (ldLibs == null) { ldLibs = Lists.newArrayListWithCapacity(ndkConfig.getLdLibs().size()); } ldLibs.addAll(ndkConfig.getLdLibs()); } }
From source file:org.eclipse.che.api.environment.server.DefaultServicesStartStrategy.java
/** * Returns mapping of names of machines to its weights in dependency graph. * * @throws IllegalArgumentException/*from www. ja v a2 s. c o m*/ * if weights of machines can not be calculated */ private Map<String, Integer> weightMachines(Map<String, CheServiceImpl> services) throws IllegalArgumentException { HashMap<String, Integer> weights = new HashMap<>(); // create machines dependency graph Map<String, Set<String>> dependencies = new HashMap<>(services.size()); for (Map.Entry<String, CheServiceImpl> serviceEntry : services.entrySet()) { CheServiceImpl service = serviceEntry.getValue(); Set<String> machineDependencies = Sets.newHashSetWithExpectedSize( service.getDependsOn().size() + service.getLinks().size() + service.getVolumesFrom().size()); for (String dependsOn : service.getDependsOn()) { checkDependency(dependsOn, serviceEntry.getKey(), services, "A machine can not depend on itself"); machineDependencies.add(dependsOn); } // links also counts as dependencies for (String link : service.getLinks()) { String dependency = getServiceFromLink(link); checkDependency(dependency, serviceEntry.getKey(), services, "A machine can not link to itself"); machineDependencies.add(dependency); } // volumesFrom also counts as dependencies for (String volumesFrom : service.getVolumesFrom()) { String dependency = getServiceFromVolumesFrom(volumesFrom); checkDependency(dependency, serviceEntry.getKey(), services, "A machine can not contain 'volumes_from' to itself"); machineDependencies.add(dependency); } dependencies.put(serviceEntry.getKey(), machineDependencies); } // Find weight of each machine in graph. // Weight of machine is calculated as sum of all weights of machines it depends on. // Nodes with no dependencies gets weight 0 while (!dependencies.isEmpty()) { int previousSize = dependencies.size(); for (Iterator<Map.Entry<String, Set<String>>> it = dependencies.entrySet().iterator(); it.hasNext();) { // process not yet processed machines only Map.Entry<String, Set<String>> serviceEntry = it.next(); String service = serviceEntry.getKey(); Set<String> serviceDependencies = serviceEntry.getValue(); if (serviceDependencies.isEmpty()) { // no links - smallest weight 0 weights.put(service, 0); it.remove(); } else { // machine has dependencies - check if it has not weighted dependencies if (weights.keySet().containsAll(serviceDependencies)) { // all connections are weighted - lets evaluate current machine Optional<String> maxWeight = serviceDependencies.stream() .max((o1, o2) -> weights.get(o1).compareTo(weights.get(o2))); // optional can't be empty because size of the list is checked above //noinspection OptionalGetWithoutIsPresent weights.put(service, weights.get(maxWeight.get()) + 1); it.remove(); } } } if (dependencies.size() == previousSize) { throw new IllegalArgumentException( "Launch order of machines '" + Joiner.on(", ").join(dependencies.keySet()) + "' can't be evaluated. Circular dependency."); } } return weights; }
From source file:com.opengamma.engine.function.FunctionInputsImpl.java
public FunctionInputsImpl(final ComputationTargetSpecificationResolver.AtVersionCorrection resolver, final Collection<? extends ComputedValue> values, final Collection<ValueSpecification> missingValues) { _resolver = resolver;/*from ww w. j a v a2s .c o m*/ _missingValues = missingValues; _values = Sets.newHashSetWithExpectedSize(values.size()); for (final ComputedValue value : values) { addValue(value); } }