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.builder.AndroidBuilder.java

/**
 * Returns the compile classpath for this config. If the config tests a library, this
 * will include the classpath of the tested config
 *
 * @return a non null, but possibly empty set.
 *//*from w w w  . ja  v  a 2 s  .  com*/
@NonNull
public Set<File> getCompileClasspath(@NonNull VariantConfiguration variantConfiguration) {
    Set<File> compileClasspath = variantConfiguration.getCompileClasspath();

    ProductFlavor mergedFlavor = variantConfiguration.getMergedFlavor();

    if (mergedFlavor.getRenderscriptSupportMode()) {
        File renderScriptSupportJar = RenderScriptProcessor
                .getSupportJar(mBuildTools.getLocation().getAbsolutePath());

        Set<File> fullJars = Sets.newHashSetWithExpectedSize(compileClasspath.size() + 1);
        fullJars.addAll(compileClasspath);
        fullJars.add(renderScriptSupportJar);
        compileClasspath = fullJars;
    }

    return compileClasspath;
}

From source file:com.google.gerrit.server.git.strategy.SubmitStrategy.java

/**
 * Add operations to a batch update that execute this submit strategy.
 *
 * <p>Guarantees exactly one op is added to the update for each change in the input set.
 *
 * @param bu batch update to add operations to.
 * @param toMerge the set of submitted commits that should be merged using this submit strategy.
 *     Implementations are responsible for ordering of commits, and will not modify the input in
 *     place./*from   www.j  a va2  s.  c om*/
 * @throws IntegrationException if an error occurred initializing the operations (as opposed to an
 *     error during execution, which will be reported only when the batch update executes the
 *     operations).
 */
public final void addOps(BatchUpdate bu, Set<CodeReviewCommit> toMerge) throws IntegrationException {
    List<SubmitStrategyOp> ops = buildOps(toMerge);
    Set<CodeReviewCommit> added = Sets.newHashSetWithExpectedSize(ops.size());

    for (SubmitStrategyOp op : ops) {
        added.add(op.getCommit());
    }

    // First add ops for any implicitly merged changes.
    List<CodeReviewCommit> difference = new ArrayList<>(Sets.difference(toMerge, added));
    Collections.reverse(difference);
    for (CodeReviewCommit c : difference) {
        bu.addOp(c.change().getId(), new ImplicitIntegrateOp(args, c));
    }

    // Then ops for explicitly merged changes
    for (SubmitStrategyOp op : ops) {
        bu.addOp(op.getId(), op);
    }
}

From source file:org.gradoop.util.AsciiGraphLoader.java

/**
 * Returns all vertices that belong to the given graphs.
 *
 * @param graphIds graph identifiers/* ww w.j  av  a  2  s  .c om*/
 * @return vertices that are contained in the graphs
 */
public Collection<V> getVerticesByGraphIds(GradoopIdSet graphIds) {
    Collection<V> result = Sets.newHashSetWithExpectedSize(graphIds.size());
    for (V vertex : vertices.values()) {
        if (vertex.getGraphIds().containsAny(graphIds)) {
            result.add(vertex);
        }
    }
    return result;
}

From source file:com.opengamma.core.AbstractEHCachingSourceWithExternalBundle.java

@Override
@SuppressWarnings("unchecked")
public Map<ExternalIdBundle, V> getSingle(final Collection<ExternalIdBundle> bundles,
        final VersionCorrection versionCorrection) {
    ArgumentChecker.notNull(bundles, "bundles");
    ArgumentChecker.notNull(versionCorrection, "versionCorrection");
    if (versionCorrection.containsLatest()) {
        return getUnderlying().getSingle(bundles, versionCorrection);
    }//from   w ww.java2s.c  om
    final Map<ExternalIdBundle, V> results = Maps.newHashMapWithExpectedSize(bundles.size());
    final Collection<ExternalIdBundle> misses = new ArrayList<ExternalIdBundle>(bundles.size());
    final Map<ExternalIdBundle, Collection<UniqueId>> hits = Maps.newHashMapWithExpectedSize(bundles.size());
    final Set<UniqueId> lookup = Sets.newHashSetWithExpectedSize(bundles.size());
    for (ExternalIdBundle bundle : bundles) {
        final Pair<ExternalIdBundle, VersionCorrection> key = Pair.of(bundle, versionCorrection);
        final Element e = _eidToUidCache.get(key);
        if (e != null) {
            if (e.getObjectValue() instanceof List) {
                final List<UniqueId> identifiers = (List<UniqueId>) e.getObjectValue();
                lookup.addAll(identifiers);
                hits.put(bundle, identifiers);
                continue;
            } else if (e.getObjectValue() instanceof UniqueId) {
                final UniqueId identifier = (UniqueId) e.getObjectValue();
                lookup.add(identifier);
                hits.put(bundle, Collections.singleton(identifier));
                continue;
            }
        }
        misses.add(bundle);
    }
    if (!lookup.isEmpty()) {
        final Map<UniqueId, V> underlying = getUnderlying().get(lookup);
        for (Map.Entry<ExternalIdBundle, Collection<UniqueId>> hit : hits.entrySet()) {
            final ExternalIdBundle bundle = hit.getKey();
            for (UniqueId uid : hit.getValue()) {
                final V result = underlying.get(uid);
                if (result != null) {
                    results.put(bundle, result);
                    break;
                }
            }
        }
    }
    if (!misses.isEmpty()) {
        final Map<ExternalIdBundle, ? extends V> underlying = getUnderlying().getSingle(misses,
                versionCorrection);
        for (ExternalIdBundle miss : misses) {
            final Pair<ExternalIdBundle, VersionCorrection> key = Pair.of(miss, versionCorrection);
            final V result = underlying.get(miss);
            if (result == null) {
                cacheIdentifiers(Collections.<UniqueId>emptyList(), key);
            } else {
                cacheIdentifiers(result.getUniqueId(), key);
                cacheItem(result);
                results.put(miss, result);
            }
        }
    }
    return results;
}

From source file:com.opengamma.financial.currency.CurrencyMatrixLookupFunction.java

@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs,
        final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
    final Set<ComputedValue> results = Sets.newHashSetWithExpectedSize(desiredValues.size());
    for (ValueRequirement desiredValue : desiredValues) {
        final Object input = inputs.getValue(desiredValue.getValueName());
        results.add(new ComputedValue(new ValueSpecification(desiredValue.getValueName(),
                target.toSpecification(), desiredValue.getConstraints()), input));
    }//from   w w w.j  ava  2s. c  o m
    return results;
}

From source file:org.jiemamy.eclipse.core.ui.editor.diagram.node.table.TableEditDialog.java

/**
 * ????????/*from   w  w  w  .j  a  v  a2  s  .  c  o  m*/
 * 
 * @param table 
 * @return ???{@code true}?????????{@code false}
 */
private boolean confirmConsistency(JmTable table) {
    boolean result = true;

    Set<DbObject> doms = getContext().getDbObjects();
    Set<String> domNames = Sets.newHashSetWithExpectedSize(doms.size());
    for (DbObject dom : doms) {
        if (dom.equals(table) == false) {
            domNames.add(dom.getName());
        }
    }

    if (domNames.contains(txtName.getText())) {
        // RESOURCE
        boolean entityCheckOk = MessageDialog.openQuestion(getParentShell(), "Confirm",
                "DbObject???????????????");
        if (entityCheckOk == false) {
            result = false;
        }
    }

    List<JmColumn> columns = table.getColumns();
    Set<String> columnNames = Sets.newHashSetWithExpectedSize(columns.size());
    for (JmColumn column : columns) {
        columnNames.add(column.getName());
    }

    if (columnNames.size() != columns.size()) {
        // RESOURCE
        boolean columnCheckOk = MessageDialog.openQuestion(getParentShell(), "Confirm",
                "???????????????");
        if (columnCheckOk == false) {
            result = false;
        }
    }
    return result;
}

From source file:com.opengamma.financial.analytics.model.swaption.deprecated.SwaptionBlackFunctionDeprecated.java

@Override
public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context,
        final ComputationTarget target, final ValueRequirement desiredValue) {
    final ValueProperties constraints = desiredValue.getConstraints();
    final Set<String> forwardCurveNames = constraints.getValues(YieldCurveFunction.PROPERTY_FORWARD_CURVE);
    if (forwardCurveNames == null || forwardCurveNames.size() != 1) {
        return null;
    }/* w  w w  .  j ava  2s .c o m*/
    final Set<String> fundingCurveNames = constraints.getValues(YieldCurveFunction.PROPERTY_FUNDING_CURVE);
    if (fundingCurveNames == null || fundingCurveNames.size() != 1) {
        return null;
    }
    final Set<String> surfaceNames = constraints.getValues(ValuePropertyNames.SURFACE);
    if (surfaceNames == null || surfaceNames.size() != 1) {
        return null;
    }
    final Set<String> curveCalculationMethods = constraints
            .getValues(ValuePropertyNames.CURVE_CALCULATION_METHOD);
    if (curveCalculationMethods == null || curveCalculationMethods.size() != 1) {
        return null;
    }
    final String forwardCurveName = forwardCurveNames.iterator().next();
    final String fundingCurveName = fundingCurveNames.iterator().next();
    final String surfaceName = surfaceNames.iterator().next();
    final String curveCalculationMethod = curveCalculationMethods.iterator().next();
    final Set<ValueRequirement> requirements = Sets.newHashSetWithExpectedSize(4);
    final Currency currency = FinancialSecurityUtils.getCurrency(target.getSecurity());
    requirements.add(getCurveRequirement(forwardCurveName, forwardCurveName, fundingCurveName,
            curveCalculationMethod, currency));
    requirements.add(getCurveRequirement(fundingCurveName, forwardCurveName, fundingCurveName,
            curveCalculationMethod, currency));
    requirements.add(getVolatilityRequirement(surfaceName, currency));
    return requirements;
}

From source file:com.opengamma.financial.currency.AbstractCurrencyMatrixSourcingFunction.java

@Override
public Set<ValueSpecification> getResults(final FunctionCompilationContext context,
        final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) {
    final String valueRequirementName = getValueRequirementName();
    final ComputationTargetSpecification targetSpec = target.toSpecification();
    final CurrencyMatrix matrix = (CurrencyMatrix) target.getValue();
    final DetermineResults resultBuilder = new DetermineResults(matrix);
    for (ValueRequirement input : inputs.values()) {
        final Currency sourceCurrency = Currency.of(input.getConstraint(SOURCE_CURRENCY_TAG));
        final Currency targetCurrency = Currency.of(input.getConstraint(TARGET_CURRENCY_TAG));
        resultBuilder.present(sourceCurrency, targetCurrency);
    }/* w  w w  .j av a  2s.c  o  m*/
    final Set<ValueSpecification> results = Sets.newHashSetWithExpectedSize(
            resultBuilder._sourceCurrencies.size() * resultBuilder._targetCurrencies.size());
    final ValueProperties.Builder properties = createValueProperties();
    for (Currency sourceCurrency : resultBuilder._sourceCurrencies) {
        properties.withoutAny(SOURCE_CURRENCY_PROPERTY).with(SOURCE_CURRENCY_PROPERTY,
                sourceCurrency.getCode());
        for (Currency targetCurrency : resultBuilder._targetCurrencies) {
            if (resultBuilder.hasInputFor(sourceCurrency, targetCurrency)) {
                results.add(new ValueSpecification(valueRequirementName, targetSpec,
                        properties.withoutAny(TARGET_CURRENCY_PROPERTY)
                                .with(TARGET_CURRENCY_PROPERTY, targetCurrency.getCode()).get()));
            }
        }
    }
    return results;
}

From source file:com.opengamma.financial.analytics.model.curve.interestrate.MarketInstrumentImpliedYieldCurveFunction.java

@Override
public Set<ValueSpecification> getResults(final FunctionCompilationContext context,
        final ComputationTarget target) {
    final Set<ValueSpecification> results = Sets.newHashSetWithExpectedSize(4);
    final ComputationTargetSpecification targetSpec = target.toSpecification();
    results.add(new ValueSpecification(ValueRequirementNames.YIELD_CURVE, targetSpec,
            createValueProperties().withAny(ValuePropertyNames.CURVE)
                    .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, getCalculationType())
                    .withAny(YieldCurveFunction.PROPERTY_FORWARD_CURVE)
                    .withAny(YieldCurveFunction.PROPERTY_FUNDING_CURVE).with(RESULT_PROPERTY_TYPE, TYPE_FORWARD)
                    .get()));//from   w  w  w.  j  ava 2  s. co  m
    results.add(new ValueSpecification(ValueRequirementNames.YIELD_CURVE, targetSpec,
            createValueProperties().withAny(ValuePropertyNames.CURVE)
                    .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, getCalculationType())
                    .withAny(YieldCurveFunction.PROPERTY_FORWARD_CURVE)
                    .withAny(YieldCurveFunction.PROPERTY_FUNDING_CURVE).with(RESULT_PROPERTY_TYPE, TYPE_FUNDING)
                    .get()));
    results.add(new ValueSpecification(ValueRequirementNames.YIELD_CURVE_JACOBIAN, targetSpec,
            createValueProperties().withAny(YieldCurveFunction.PROPERTY_FORWARD_CURVE)
                    .withAny(YieldCurveFunction.PROPERTY_FUNDING_CURVE)
                    .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, getCalculationType()).get()));
    if (getCalculationType().equals(PRESENT_VALUE_STRING)) {
        results.add(new ValueSpecification(ValueRequirementNames.PRESENT_VALUE_COUPON_SENSITIVITY, targetSpec,
                createValueProperties().withAny(YieldCurveFunction.PROPERTY_FORWARD_CURVE)
                        .withAny(YieldCurveFunction.PROPERTY_FUNDING_CURVE).get()));
    }
    return results;
}

From source file:com.android.tools.idea.gradle.project.sync.setup.module.android.DependenciesModuleSetupStep.java

/**
 * Sets the 'useLibrary' libraries or SDK add-ons as library dependencies.
 * <p>/*from www  .ja v  a2 s .co  m*/
 * These libraries are set at the project level, which makes it impossible to add them to a IDE SDK definition because the IDE SDK is
 * global to the whole IDE. To work around this limitation, we set these libraries as module dependencies instead.
 * </p>
 */
private void addExtraSdkLibrariesAsDependencies(@NotNull Module module,
        @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull AndroidProject androidProject) {
    ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
    Sdk sdk = moduleModel.getSdk();
    assert sdk != null; // If we got here, SDK will *NOT* be null.

    String suffix = null;
    AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
    if (sdkData != null) {
        SdkAdditionalData data = sdk.getSdkAdditionalData();
        if (data instanceof AndroidSdkAdditionalData) {
            AndroidSdkAdditionalData androidSdkData = (AndroidSdkAdditionalData) data;
            suffix = androidSdkData.getBuildTargetHashString();
        }
    }

    if (suffix == null) {
        // In practice, we won't get here. A proper Android SDK has been already configured by now, and the suffix won't be null.
        suffix = androidProject.getCompileTarget();
    }

    Set<String> currentIdeSdkFilePaths = Sets.newHashSetWithExpectedSize(5);
    for (VirtualFile sdkFile : sdk.getRootProvider().getFiles(CLASSES)) {
        // We need to convert the VirtualFile to java.io.File, because the path of the VirtualPath is using 'jar' protocol and it won't match
        // the path returned by AndroidProject#getBootClasspath().
        File sdkFilePath = virtualToIoFile(sdkFile);
        currentIdeSdkFilePaths.add(sdkFilePath.getPath());
    }
    Collection<String> bootClasspath = androidProject.getBootClasspath();
    for (String library : bootClasspath) {
        if (isNotEmpty(library) && !currentIdeSdkFilePaths.contains(library)) {
            // Library is not in the SDK IDE definition. Add it as library and make the module depend on it.
            File binaryPath = new File(library);
            String name = binaryPath.isFile() ? getNameWithoutExtension(binaryPath) : sanitizeFileName(library);
            // Include compile target as part of the name, to ensure the library name is unique to this Android platform.

            name = name + "-" + suffix; // e.g. maps-android-23, effects-android-23 (it follows the library naming convention: library-version
            myDependenciesSetup.setUpLibraryDependency(module, modelsProvider, name, COMPILE, binaryPath);
        }
    }
}