Example usage for com.google.common.collect Lists newArrayListWithCapacity

List of usage examples for com.google.common.collect Lists newArrayListWithCapacity

Introduction

In this page you can find the example usage for com.google.common.collect Lists newArrayListWithCapacity.

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithCapacity(int initialArraySize) 

Source Link

Document

Creates an ArrayList instance backed by an array with the specified initial size; simply delegates to ArrayList#ArrayList(int) .

Usage

From source file:at.molindo.esi4j.action.impl.DefaultMultiSearchResponseWrapper.java

@Override
public synchronized List<MultiSearchItemResponseWrapper> getMultiSearchItemResponses() {
    if (_objects == null) {
        MultiSearchResponse.Item[] reps = _response.getResponses();
        _objects = Lists.newArrayListWithCapacity(reps.length);
        for (int i = 0; i < reps.length; i++) {
            _objects.add(new DefaultMultiSearchItemResponseWrapper(reps[i], _reader));
        }//from  w  w  w. jav a 2s  .  c  om
    }
    return _objects;
}

From source file:org.terasology.assets.format.AssetDataFile.java

/**
 * @return The path to the file (excluding file name) relative to the module
 *///from w  w w.  j a  v a  2 s. c om
public List<String> getPath() {
    List<String> result = Lists.newArrayListWithCapacity(path.getNameCount() - 1);
    for (int i = 0; i < path.getNameCount() - 1; ++i) {
        result.add(path.getName(i).toString());
    }
    return result;
}

From source file:io.appform.nautilus.funnel.utils.PathUtils.java

public static List<String> normalise(final List<String> inputPath) {
    List<String> path = new ArrayList<>(inputPath);
    //Remove self loops
    for (int i = 1; i < path.size(); i++) {
        if (Objects.equals(path.get(i), path.get(i - 1))) {
            path.set(i, null);//from  w w w .  j a v  a  2 s . c  om
        }
    }
    List<String> dedupList = path.parallelStream().filter(listItem -> !Strings.isNullOrEmpty(listItem))
            .collect(Collectors.toCollection(ArrayList::new));
    //Sequence can't be greater than half of the path
    int seqSize = dedupList.size() / 2;
    while (seqSize >= 2) { //Can't have smaller repetitions

        //The algo marks the duplicate bits as true
        BitSet bitSet = new BitSet(dedupList.size());
        //System.out.println("SEQ SIZE: " + seqSize);
        for (int i = 0; i < dedupList.size() - seqSize; i++) {

            //Create the sequence to search for
            final List<String> subList = dedupList.subList(i, i + seqSize);
            boolean duplicateSeqFound = true;
            //System.out.println("CHECKING: " + Joiner.on("->").join(subList));
            if (dedupList.size() < i + 2 * seqSize) {
                //System.out.println("SKIPPING");
                continue;
            }
            for (int j = i + seqSize, k = 0; k < subList.size(); j++, k++) {
                if (!subList.get(k).equals(dedupList.get(j))) {
                    //There is a non-duplicate bit
                    //Useless to go further with this sequence
                    duplicateSeqFound = false;
                    break;
                }
            }

            if (duplicateSeqFound) {
                //Set the bits
                bitSet.set(i, i + seqSize);
                List<String> tmpList = Lists.newArrayListWithCapacity(dedupList.size() - seqSize);
                for (int ii = 0; ii < dedupList.size(); ii++) {
                    if (!bitSet.get(ii)) {
                        //Add not new path only if bit is not set
                        tmpList.add(dedupList.get(ii));
                    }
                }
                //Next loop will use the compressed path
                dedupList = tmpList;
                //System.out.println("DUPL: " + Joiner.on("->").join(subList));
                //System.out.println("NORM PATH: " + Joiner.on("->").join(dedupList));
                break;
            }
        }

        seqSize = (bitSet.isEmpty()) //If no duplicate was found in this iteration
                ? seqSize - 1 //Try with a smaller sequence
                : dedupList.size() / 2; //Deduplicate the modified path
    }

    return dedupList;
}

From source file:adwords.axis.v201502.campaignmanagement.AddCampaignLabels.java

public static void runExample(AdWordsServices adWordsServices, AdWordsSession session, List<Long> campaignIds,
        Long labelId) throws Exception {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);

    // Create label operations.
    List<CampaignLabelOperation> operations = Lists.newArrayListWithCapacity(campaignIds.size());
    for (Long campaignId : campaignIds) {
        CampaignLabel campaignLabel = new CampaignLabel();
        campaignLabel.setCampaignId(campaignId);
        campaignLabel.setLabelId(labelId);

        CampaignLabelOperation operation = new CampaignLabelOperation();
        operation.setOperand(campaignLabel);
        operation.setOperator(Operator.ADD);

        operations.add(operation);/*from ww  w. jav  a2s.co m*/
    }

    // Display campaign labels.
    for (CampaignLabel campaignLabelResult : campaignService
            .mutateLabel(operations.toArray(new CampaignLabelOperation[operations.size()])).getValue()) {
        System.out.printf("Campaign label for campaign ID %d and label ID %d was added.%n",
                campaignLabelResult.getCampaignId(), campaignLabelResult.getLabelId());
    }
}

From source file:com.ngdata.hbaseindexer.indexer.SepEventRowData.java

/**
 * Makes a HBase Result object based on the KeyValue's from the SEP event. Usually, this will only be used in
 * situations where only new data is written (or updates are complete row updates), so we don't expect any
 * delete-type key-values, but just to be sure we filter them out.
 *//*from w  w w  . ja  va2 s.  c o m*/
@Override
public Result toResult() {

    List<KeyValue> filteredKeyValues = Lists.newArrayListWithCapacity(sepEvent.getKeyValues().size());

    for (KeyValue kv : getKeyValues()) {
        if (!kv.isDelete() && !kv.isDeleteFamily()) {
            filteredKeyValues.add(kv);
        }
    }

    // A Result object requires that the KeyValues are sorted (e.g., it does binary search on them)
    Collections.sort(filteredKeyValues, KeyValue.COMPARATOR);
    return newResult(filteredKeyValues);
}

From source file:org.kududb.util.NetUtil.java

/**
 * Parse a comma separated list of "host:port" pairs into a list of
 * {@link HostAndPort} objects. If no port is specified for an entry in
 * the comma separated list, then a default port is used.
 * The inverse of {@link #hostsAndPortsToString(List)}.
 *
 * @param commaSepAddrs The comma separated list of "host:port" pairs.
 * @param defaultPort   The default port to use if no port is specified.
 * @return A list of HostAndPort objects constructed from commaSepAddrs.
 *//*from   www  . java2  s . co  m*/
public static List<HostAndPort> parseStrings(final String commaSepAddrs, int defaultPort) {
    Iterable<String> addrStrings = Splitter.on(',').trimResults().split(commaSepAddrs);
    List<HostAndPort> hostsAndPorts = Lists.newArrayListWithCapacity(Iterables.size(addrStrings));
    for (String addrString : addrStrings) {
        HostAndPort hostAndPort = parseString(addrString, defaultPort);
        hostsAndPorts.add(hostAndPort);
    }
    return hostsAndPorts;
}

From source file:org.gradoop.common.model.impl.properties.PropertyList.java

/**
 * Default constructor
 */
public PropertyList() {
    properties = Lists.newArrayListWithCapacity(DEFAULT_CAPACITY);
}

From source file:com.maddyhome.idea.vim.ex.handler.ShiftRightHandler.java

public boolean execute(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context,
        @NotNull ExCommand cmd) {/*w  ww . j  a v  a  2 s.  com*/
    final TextRange range = cmd.getTextRange(editor, caret, context, true);
    final int[] endOffsets = range.getEndOffsets();
    final List<Integer> ends = Lists.newArrayListWithCapacity(endOffsets.length);
    for (int endOffset : endOffsets) {
        ends.add(endOffset - 1);
    }
    VimPlugin.getChange().indentRange(editor, caret, context,
            new TextRange(range.getStartOffsets(), ArrayUtil.toIntArray(ends)), cmd.getCommand().length(), 1);

    return true;
}

From source file:com.threerings.presents.tools.cpp.CPPArgBuilder.java

public List<String> getArgumentNames(ServiceMethod meth) {
    Type[] ptypes = meth.method.getGenericParameterTypes();
    List<String> args = Lists.newArrayListWithCapacity(ptypes.length);
    for (int ii = 0; ii < ptypes.length; ii++) {
        args.add("arg" + (ii + 1));
    }//from w  w w  .j av  a  2  s. c  o  m
    return args;
}

From source file:org.eclipse.xtext.xbase.scoping.batch.FeatureScopeSessionWithDynamicExtensions.java

@Override
public List<ExpressionBucket> getExtensionProviders() {
    List<ExpressionBucket> result = Lists.newArrayListWithCapacity(3);
    addExtensionProviders(result);//from  w  w  w .j a v a2  s .c o  m
    return result;
}