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:org.sosy_lab.cpachecker.util.ci.CustomInstructionRequirementsWriter.java

private List<String> removeDuplicates(final List<String> pre, final List<String> post, final List<String> ci) {
    int sumSize = pre.size() + post.size() + ci.size();
    List<String> duplicateFreeSet = new ArrayList<>(sumSize);
    Set<String> set = Sets.newHashSetWithExpectedSize(sumSize);

    addNonMembersToList(pre, duplicateFreeSet, set);
    addNonMembersToList(post, duplicateFreeSet, set);
    addNonMembersToList(ci, duplicateFreeSet, set);
    return duplicateFreeSet;
}

From source file:se.softhouse.jargo.ParsedArguments.java

Set<String> nonParsedArguments() {
    Set<String> validArguments = Sets.newHashSetWithExpectedSize(allArguments.size());
    for (Argument<?> argument : allArguments) {
        boolean wasGiven = wasGiven(argument);
        if (!wasGiven || argument.isAllowedToRepeat()) {
            for (String name : argument.names()) {
                if (argument.separator().equals(ArgumentBuilder.DEFAULT_SEPARATOR)
                        || argument.isPropertyMap()) {
                    validArguments.add(name);
                } else {
                    validArguments.add(name + argument.separator());
                }// ww  w. j a v  a 2s.co  m

            }
        }
    }
    return validArguments;
}

From source file:concretisations.checkers.pieces.CheckerPiece.java

@Override
public final Set<? extends MutationInterface> computePotentialMutations(final ManagedCellInterface cell,
        final SideInterface side) {
    final Set<MutationInterface> potentialMutations = Sets.newHashSetWithExpectedSize(4);
    for (final DirectionInterface direction : this.getMutations(cell, side, CheckersMutations.JUMP)) {
        potentialMutations.add(CheckersMutationFactory.newJumpMutation(cell, direction));
    }//from  w  w  w  . ja v a  2 s  .  co m
    for (final DirectionInterface direction : this.getMutations(cell, side, CheckersMutations.WALK)) {
        potentialMutations.add(CheckersMutationFactory.newWalkMutation(cell, direction));
    }
    return potentialMutations;
}

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

@SuppressWarnings("unchecked")
@Override/*from www . j  a  va  2s.c o m*/
public Map<ExternalIdBundle, Collection<V>> getAll(final Collection<ExternalIdBundle> bundles,
        VersionCorrection versionCorrection) {
    ArgumentChecker.notNull(bundles, "bundles");
    ArgumentChecker.notNull(versionCorrection, "versionCorrection");
    if (versionCorrection.containsLatest()) {
        return getUnderlying().getAll(bundles, versionCorrection);
    }
    final Map<ExternalIdBundle, Collection<V>> results = Maps.newHashMapWithExpectedSize(bundles.size());
    final Collection<ExternalIdBundle> misses = new ArrayList<ExternalIdBundle>(bundles.size());
    final Map<ExternalIdBundle, Collection<UniqueId>> lookupBundles = Maps
            .newHashMapWithExpectedSize(bundles.size());
    final Set<UniqueId> lookupIds = 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 Collection) {
                final Collection<UniqueId> identifiers = (Collection<UniqueId>) e.getObjectValue();
                if (identifiers.isEmpty()) {
                    results.put(bundle, Collections.<V>emptySet());
                } else {
                    lookupBundles.put(bundle, identifiers);
                    lookupIds.addAll(identifiers);
                }
                continue;
            }
        }
        misses.add(bundle);
    }
    if (!lookupIds.isEmpty()) {
        final Map<UniqueId, V> underlying = get(lookupIds);
        for (Map.Entry<ExternalIdBundle, Collection<UniqueId>> lookupBundle : lookupBundles.entrySet()) {
            final ArrayList<V> resultCollection = new ArrayList<V>(lookupBundle.getValue().size());
            for (UniqueId uid : lookupBundle.getValue()) {
                final V resultValue = underlying.get(uid);
                if (resultValue != null) {
                    resultCollection.add(resultValue);
                }
            }
            resultCollection.trimToSize();
            results.put(lookupBundle.getKey(), resultCollection);
        }
    }
    if (!misses.isEmpty()) {
        final Map<ExternalIdBundle, Collection<V>> underlying = getUnderlying().getAll(misses,
                versionCorrection);
        for (ExternalIdBundle miss : misses) {
            final Pair<ExternalIdBundle, VersionCorrection> key = Pair.of(miss, versionCorrection);
            final Collection<V> result = underlying.get(miss);
            if ((result == null) || result.isEmpty()) {
                cacheIdentifiers(Collections.<UniqueId>emptyList(), key);
            } else {
                final List<UniqueId> uids = new ArrayList<UniqueId>(result.size());
                for (final V item : result) {
                    uids.add(item.getUniqueId());
                }
                Collections.sort(uids);
                cacheIdentifiers(uids, key);
                cacheItems(result);
                results.put(miss, result);
            }
        }
    }
    return results;
}

From source file:org.apache.kylin.storage.translate.ColumnValueRange.java

private Set<String> filter(Set<String> equalValues, String beginValue, String endValue) {
    Set<String> result = Sets.newHashSetWithExpectedSize(equalValues.size());
    for (String v : equalValues) {
        if (between(v, beginValue, endValue)) {
            result.add(v);/*from ww  w. j  av a 2s  . c o m*/
        }
    }
    return equalValues;
}

From source file:org.n52.iceland.coding.SupportedTypeRepository.java

private Set<String> getSupportedTypeAsString(Set<? extends AbstractSupportedStringType> types) {
    Set<String> strings = Sets.newHashSetWithExpectedSize(types.size());
    for (AbstractSupportedStringType type : types) {
        strings.add(type.getValue());/*w  w  w  . j av a2 s.  c o m*/
    }
    return strings;
}

From source file:com.cloudera.oryx.rdf.common.tree.DecisionTree.java

private static Iterable<Integer> randomFeatures(ExampleSet examples, int featuresToTry, int numFeatures,
        RandomGenerator random) {/*from ww  w.  ja v a  2 s. c o  m*/
    Collection<Integer> features = Sets.newHashSetWithExpectedSize(featuresToTry);
    int max = FastMath.min(numFeatures, featuresToTry);
    int attempts = 0;
    while (features.size() < max && attempts < 2 * featuresToTry) {
        int featureNumber = random.nextInt(numFeatures);
        if (examples.getFeatureType(featureNumber) != FeatureType.IGNORED) {
            features.add(featureNumber);
        }
        attempts++;
    }
    return features;
}

From source file:org.apache.phoenix.expression.InListExpression.java

public InListExpression(List<Expression> keyExpressions, boolean rowKeyOrderOptimizable) {
    super(keyExpressions.get(0));
    this.rowKeyOrderOptimizable = rowKeyOrderOptimizable;
    Expression firstChild = keyExpressions.get(0);
    this.keyExpressions = keyExpressions.subList(1, keyExpressions.size());
    Set<ImmutableBytesPtr> values = Sets.newHashSetWithExpectedSize(keyExpressions.size() - 1);
    Integer maxLength = firstChild.getDataType().isFixedWidth() ? firstChild.getMaxLength() : null;
    int fixedWidth = -1;
    boolean isFixedLength = true;
    for (int i = 1; i < keyExpressions.size(); i++) {
        ImmutableBytesPtr ptr = new ImmutableBytesPtr();
        Expression child = keyExpressions.get(i);
        child.evaluate(null, ptr);/*  w ww  . ja  v a2  s.  co  m*/
        if (ptr.getLength() > 0) { // filter null as it has no impact
            if (rowKeyOrderOptimizable) {
                firstChild.getDataType().pad(ptr, maxLength, firstChild.getSortOrder());
            } else if (maxLength != null) {
                byte[] paddedBytes = StringUtil.padChar(ByteUtil.copyKeyBytesIfNecessary(ptr), maxLength);
                ptr.set(paddedBytes);
            }
            if (values.add(ptr)) {
                int length = ptr.getLength();
                if (fixedWidth == -1) {
                    fixedWidth = length;
                } else {
                    isFixedLength &= fixedWidth == length;
                }

                valuesByteLength += ptr.getLength();
            }
        }
    }
    this.fixedWidth = isFixedLength ? fixedWidth : -1;
    // Sort values by byte value so we can get min/max easily
    ImmutableBytesPtr[] valuesArray = values.toArray(new ImmutableBytesPtr[values.size()]);
    Arrays.sort(valuesArray, ByteUtil.BYTES_PTR_COMPARATOR);
    if (values.isEmpty()) {
        this.minValue = ByteUtil.EMPTY_BYTE_ARRAY_PTR;
        this.maxValue = ByteUtil.EMPTY_BYTE_ARRAY_PTR;
        this.values = Collections.emptySet();
    } else {
        this.minValue = valuesArray[0];
        this.maxValue = valuesArray[valuesArray.length - 1];
        // Use LinkedHashSet on client-side so that we don't need to serialize the
        // minValue and maxValue but can infer them based on the first and last position.
        this.values = new LinkedHashSet<ImmutableBytesPtr>(Arrays.asList(valuesArray));
    }
}

From source file:monasca.common.hibernate.db.AlarmDb.java

public AlarmDb setAlarmMetrics(final Collection<AlarmMetricDb> alarmMetrics) {
    if (alarmMetrics == null || alarmMetrics.isEmpty()) {
        return this;
    }/*from  w  ww. jav a 2 s .com*/

    final AlarmDb self = this;
    this.alarmMetrics = Sets.newHashSetWithExpectedSize(alarmMetrics.size());

    FluentIterable.from(alarmMetrics).transform(new Function<AlarmMetricDb, AlarmMetricDb>() {
        @Nullable
        @Override
        public AlarmMetricDb apply(@Nullable final AlarmMetricDb input) {
            assert input != null;
            input.setAlarm(self);
            return input;
        }
    }).copyInto(this.alarmMetrics);
    return this;
}

From source file:com.opengamma.financial.view.HistoricalViewEvaluationFunction.java

@Override
protected Set<ComputedValue> buildResults(ComputationTarget target,
        HistoricalViewEvaluationResultBuilder resultBuilder) {
    final Map<String, HistoricalViewEvaluationResult> viewResults = resultBuilder.getResults();
    final Set<ComputedValue> results = Sets.newHashSetWithExpectedSize(viewResults.size() + 1);
    final ComputationTargetSpecification targetSpec = target.toSpecification();
    for (final Map.Entry<String, HistoricalViewEvaluationResult> viewResult : viewResults.entrySet()) {
        String calcConfigName = viewResult.getKey();
        HistoricalViewEvaluationResult value = viewResult.getValue();
        results.add(new ComputedValue(getResultSpec(calcConfigName, targetSpec), value));
    }/*from w  w w.  j av a2  s.c  om*/
    final HistoricalViewEvaluationMarketData viewMarketData = resultBuilder.getMarketData();
    if (viewMarketData != null) {
        results.add(new ComputedValue(getMarketDataResultSpec(targetSpec), viewMarketData));
    }
    return results;
}