List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
From source file:org.eclipse.xtext.common.types.util.Primitives.java
public JvmTypeReference asPrimitiveIfWrapperType(JvmTypeReference type) { return new AbstractTypeReferenceVisitor.InheritanceAware<JvmTypeReference>() { private Set<JvmType> visiting = Sets.newHashSetWithExpectedSize(2); @Override// w w w . ja v a2s .c om public JvmTypeReference doVisitMultiTypeReference(JvmMultiTypeReference reference) { for (JvmTypeReference ref : reference.getReferences()) { JvmTypeReference refAsPrimitiveIfWrapper = visit(ref); if (refAsPrimitiveIfWrapper != ref) return refAsPrimitiveIfWrapper; } return reference; } @Override public JvmTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference type) { if (type.getType() instanceof JvmTypeParameter && visiting.add(type.getType())) { EList<JvmTypeConstraint> constraints = ((JvmTypeParameter) type.getType()).getConstraints(); for (JvmUpperBound upperBound : filter(constraints, JvmUpperBound.class)) { JvmTypeReference upperBoundType = upperBound.getTypeReference(); JvmTypeReference asPrimitive = visit(upperBoundType); if (asPrimitive != upperBoundType) return asPrimitive; } return type; } else if (typeReferences.is(type, Byte.class)) { return typeReferences.getTypeForName(Byte.TYPE, type.getType()); } else if (typeReferences.is(type, Short.class)) { return typeReferences.getTypeForName(Short.TYPE, type.getType()); } else if (typeReferences.is(type, Character.class)) { return typeReferences.getTypeForName(Character.TYPE, type.getType()); } else if (typeReferences.is(type, Integer.class)) { return typeReferences.getTypeForName(Integer.TYPE, type.getType()); } else if (typeReferences.is(type, Long.class)) { return typeReferences.getTypeForName(Long.TYPE, type.getType()); } else if (typeReferences.is(type, Float.class)) { return typeReferences.getTypeForName(Float.TYPE, type.getType()); } else if (typeReferences.is(type, Double.class)) { return typeReferences.getTypeForName(Double.TYPE, type.getType()); } else if (typeReferences.is(type, Boolean.class)) { return typeReferences.getTypeForName(Boolean.TYPE, type.getType()); } else if (typeReferences.is(type, Void.class)) { return typeReferences.getTypeForName(Void.TYPE, type.getType()); } return type; } @Override public JvmTypeReference doVisitTypeReference(JvmTypeReference reference) { return reference; } @Override protected JvmTypeReference handleNullReference() { return null; } }.visit(type); }
From source file:org.artifactory.storage.db.build.service.BuildStoreServiceImpl.java
private void insertModules(long buildId, Build build) throws SQLException { List<Module> modules = build.getModules(); if (modules == null || modules.isEmpty()) { // Nothing to do here return;/*from w ww .j a v a 2s.c o m*/ } for (Module module : modules) { BuildModule dbModule = new BuildModule(dbService.nextId(), buildId, module.getId()); Properties properties = module.getProperties(); Set<ModuleProperty> moduleProperties; if (properties != null && !properties.isEmpty()) { moduleProperties = Sets.newHashSetWithExpectedSize(properties.size()); for (Map.Entry<Object, Object> entry : properties.entrySet()) { moduleProperties.add(new ModuleProperty(dbService.nextId(), dbModule.getModuleId(), entry.getKey().toString(), entry.getValue().toString())); } } else { moduleProperties = Sets.newHashSetWithExpectedSize(1); } dbModule.setProperties(moduleProperties); buildModulesDao.createBuildModule(dbModule); List<Artifact> artifacts = module.getArtifacts(); List<BuildArtifact> dbArtifacts; if (artifacts != null && !artifacts.isEmpty()) { dbArtifacts = Lists.newArrayListWithExpectedSize(artifacts.size()); for (Artifact artifact : artifacts) { // Artifact properties are not inserted in DB dbArtifacts.add(new BuildArtifact(dbService.nextId(), dbModule.getModuleId(), artifact.getName(), artifact.getType(), artifact.getSha1(), artifact.getMd5())); } } else { dbArtifacts = Lists.newArrayListWithExpectedSize(1); } buildArtifactsDao.createBuildArtifacts(dbArtifacts); List<Dependency> dependencies = module.getDependencies(); List<BuildDependency> dbDependencies; if (dependencies != null && !dependencies.isEmpty()) { dbDependencies = Lists.newArrayListWithExpectedSize(dependencies.size()); for (Dependency dependency : dependencies) { // Dependency properties are not inserted in DB dbDependencies.add(new BuildDependency(dbService.nextId(), dbModule.getModuleId(), dependency.getId(), dependency.getScopes(), dependency.getType(), dependency.getSha1(), dependency.getMd5())); } } else { dbDependencies = Lists.newArrayListWithExpectedSize(1); } buildDependenciesDao.createBuildDependencies(dbDependencies); } }
From source file:org.onosproject.net.topology.AbstractPathService.java
private Set<Path> edgeToEdgePaths(EdgeLink srcLink, EdgeLink dstLink) { Set<Path> endToEndPaths = Sets.newHashSetWithExpectedSize(1); endToEndPaths.add(edgeToEdgePath(srcLink, dstLink, null)); return endToEndPaths; }
From source file:com.attribyte.essem.ESUserStore.java
/** * Gets a list of recent user tags.// ww w .j a v a 2 s.co m * @param index The index. * @param uid The user id. * @return The list of tags. */ public List<String> getUserTags(final String index, final String uid) throws IOException { List<StoredGraph> graphs = getUserGraphs(index, uid, 0, 100); List<String> tags = Lists.newArrayListWithExpectedSize(16); Set<String> tagSet = Sets.newHashSetWithExpectedSize(16); for (StoredGraph graph : graphs) { for (String tag : graph.tags) { if (!tagSet.contains(tag)) { tagSet.add(tag); tags.add(tag); } } } return tags; }
From source file:eu.numberfour.n4js.ui.containers.NfarStorageMapper.java
private void updateCache(IN4JSEclipseProject project) { Set<URI> libArchives = knownLibArchives.get(project.getLocation()); if (libArchives != null) { Map<URI, Set<URI>> filteredMap = Maps.filterKeys(knownLibArchives, Predicates.not(Predicates.equalTo(project.getLocation()))); Set<URI> remainingLibs = Sets.newHashSet(Iterables.concat(filteredMap.values())); for (URI archive : libArchives) { if (!remainingLibs.contains(archive)) { knownEntries.remove(archive); }// w w w . j av a 2 s.co m } } if (project.exists()) { libArchives = Sets.newHashSetWithExpectedSize(3); List<? extends IN4JSArchive> libraries = project.getLibraries(); for (IN4JSArchive archive : libraries) { URI location = archive.getLocation(); libArchives.add(location); if (!knownEntries.containsKey(location)) { Set<URI> entryURIs = Sets.newHashSet(); traverseArchive(archive, entryURIs); knownEntries.put(location, Collections.unmodifiableSet(entryURIs)); } } knownLibArchives.put(project.getLocation(), libArchives); } else { knownLibArchives.remove(project.getLocation()); } }
From source file:com.opengamma.financial.analytics.model.sensitivities.ExternallyProvidedSensitivitiesYieldCurveNodeSensitivitiesFunction.java
@Override public Set<ValueSpecification> getResults(final FunctionCompilationContext context, final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) { String curveName = null;//from w w w . ja v a2s .c o m String curveCalculationConfig = null; final ComputationTargetSpecification targetSpec = target.toSpecification(); final Set<ValueSpecification> results = Sets.newHashSetWithExpectedSize(2); for (final Map.Entry<ValueSpecification, ValueRequirement> input : inputs.entrySet()) { if (ValueRequirementNames.YIELD_CURVE.equals(input.getKey().getValueName())) { assert curveName == null; assert curveCalculationConfig == null; curveName = input.getKey().getProperty(ValuePropertyNames.CURVE); curveCalculationConfig = input.getKey().getProperty(ValuePropertyNames.CURVE_CALCULATION_CONFIG); assert curveName != null; assert curveCalculationConfig != null; final ValueProperties.Builder properties = createValueProperties(target); properties.with(ValuePropertyNames.CURVE, curveName); properties.with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, curveCalculationConfig); results.add(new ValueSpecification(YCNS_REQUIREMENT, targetSpec, properties.get())); } } s_logger.debug("getResults(2) returning " + results); return results; }
From source file:ru.runa.wfe.ss.logic.SubstitutionLogic.java
private List<Actor> getSubstitutionActors(List<Substitution> substitutions) { Set<Long> actorIdSet = Sets.newHashSetWithExpectedSize(substitutions.size()); for (Substitution substitution : substitutions) { actorIdSet.add(substitution.getActorId()); }/*from w w w . ja v a2 s.c om*/ return executorDao.getActors(Lists.newArrayList(actorIdSet)); }
From source file:com.google.gerrit.gpg.server.PostGpgKeys.java
private Set<Fingerprint> readKeysToRemove(Input input, Collection<ExternalId> existingExtIds) { if (input.delete == null || input.delete.isEmpty()) { return ImmutableSet.of(); }// w w w. ja v a 2 s .c o m Set<Fingerprint> fingerprints = Sets.newHashSetWithExpectedSize(input.delete.size()); for (String id : input.delete) { try { fingerprints.add(new Fingerprint(GpgKeys.parseFingerprint(id, existingExtIds))); } catch (ResourceNotFoundException e) { // Skip removal. } } return fingerprints; }
From source file:net.automatalib.automata.base.compact.AbstractCompactSimpleNondet.java
public void setTransitions(int state, int inputIdx, Collection<? extends Integer> successors) { // TODO: replace by primitive specialization int transIdx = toMemoryIndex(state, inputIdx); //TIntSet succs = transitions[transIdx]; Set<Integer> succs = transitions[transIdx]; // TODO: replace by primitive specialization if (succs == null) { //succs = new TIntHashSet(successors); succs = Sets.newHashSetWithExpectedSize(successors.size()); // TODO: replace by primitive specialization transitions[transIdx] = succs;/*from w ww . j av a2s. c o m*/ } else { succs.clear(); } succs.addAll(successors); }
From source file:com.android.builder.internal.packaging.sign.v2.ApkSignerV2.java
/** * Signs the provided APK using APK Signature Scheme v2 and returns the APK Signing Block * containing the signature.//www .j a v a 2 s . c o m * * <p>NOTE: To enable APK signature verifier to detect v2 signature stripping, header sections * of META-INF/*.SF files of APK being signed must contain the * {@code X-Android-APK-Signed: 2} attribute. * * @param signerConfigs signer configurations, one for each signer. At least one configuration * must be provided. * * @throws InvalidKeyException if a signing key is not suitable for this signature scheme or * cannot be used in general * @throws SignatureException if an error occurs when computing digests of generating * signatures */ @NonNull public static byte[] generateApkSigningBlock(@NonNull DigestSource beforeCentralDir, @NonNull DigestSource centralDir, @NonNull DigestSource eocd, @NonNull List<SignerConfig> signerConfigs) throws InvalidKeyException, SignatureException { if (signerConfigs.isEmpty()) { throw new IllegalArgumentException("No signer configs provided. At least one is required"); } // Figure out which digest(s) to use for APK contents. Set<ContentDigestAlgorithm> contentDigestAlgorithms = Sets.newHashSetWithExpectedSize(1); for (SignerConfig signerConfig : signerConfigs) { for (SignatureAlgorithm signatureAlgorithm : signerConfig.signatureAlgorithms) { contentDigestAlgorithms.add(signatureAlgorithm.getContentDigestAlgorithm()); } } // Compute digests of APK contents. Map<ContentDigestAlgorithm, byte[]> contentDigests; // digest algorithm ID -> digest try { contentDigests = computeContentDigests(contentDigestAlgorithms, new DigestSource[] { beforeCentralDir, centralDir, eocd }); } catch (DigestException e) { throw new SignatureException("Failed to compute digests of APK", e); } // Sign the digests and wrap the signatures and signer info into an APK Signing Block. return generateApkSigningBlock(signerConfigs, contentDigests); }