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:net.derquinse.common.io.ChunkedDirectByteSource.java

@Override
public MemoryByteSource toHeap(boolean merge) {
    if (merge) {/*from   ww  w.j a va  2s  .c  o  m*/
        byte[] buffer = new byte[chunks.getTotalSize()];
        writeTo(buffer, 0);
        return new ByteArrayByteSource(buffer);
    } else {
        List<ByteArrayByteSource> list = Lists.newArrayListWithCapacity(chunks.size());
        for (SingleDirectByteSource s : chunks) {
            list.add(s.toHeap(true));
        }
        return new ChunkedHeapByteSource(new Chunks<ByteArrayByteSource>(list));
    }
}

From source file:net.minecraftforge.gradle.patcher.TaskSubprojectCall.java

@TaskAction
public void doTask() throws IOException {
    // resolve replacements
    for (Entry<String, Object> entry : replacements.entrySet()) {
        replacements.put(entry.getKey(), Constants.resolveString(entry.getValue()).replace('\\', '/'));
    }//from www.j  ava 2 s . c o m

    // extract extra initscripts
    List<File> initscripts = Lists.newArrayListWithCapacity(initResources.size());
    for (int i = 0; i < initResources.size(); i++) {
        File file = new File(getTemporaryDir(), "initscript" + i);
        String thing = Resources.toString(initResources.get(i), Constants.CHARSET);

        for (Entry<String, Object> entry : replacements.entrySet()) {
            thing = thing.replace(entry.getKey(), (String) entry.getValue());
        }

        Files.write(thing, file, Constants.CHARSET);
        initscripts.add(file);
    }

    // get current Gradle instance
    Gradle gradle = getProject().getGradle();

    getProject().getLogger().lifecycle("------------------------ ");
    getProject().getLogger().lifecycle("--------SUB-CALL-------- ");
    getProject().getLogger().lifecycle("------------------------ ");

    // connect to project
    ProjectConnection connection = GradleConnector.newConnector()
            .useGradleUserHomeDir(gradle.getGradleUserHomeDir()).useInstallation(gradle.getGradleHomeDir())
            .forProjectDirectory(getProjectDir()).connect();

    //get args
    ArrayList<String> args = new ArrayList<String>(5);
    args.addAll(Splitter.on(' ').splitToList(getCallLine()));

    for (File f : initscripts) {
        args.add("-I" + f.getCanonicalPath());
    }

    // build
    connection.newBuild().setStandardOutput(System.out).setStandardInput(System.in).setStandardError(System.err)
            .withArguments(args.toArray(new String[args.size()])).setColorOutput(false).run();

    getProject().getLogger().lifecycle("------------------------ ");
    getProject().getLogger().lifecycle("------END-SUB-CALL------ ");
    getProject().getLogger().lifecycle("------------------------ ");
}

From source file:blue.lapis.common.command.impl.BooleanTokenParser.java

@Override
public List<String> suggest(CommandSource source, String token) {
    token = token.trim();/* w  w  w  .  j  a va 2  s . c  o  m*/
    if (!token.isEmpty()) {
        token = Parsing.toLowerCase(token);

        ArrayList<String> result = Lists.newArrayListWithCapacity(1);

        for (String bool : TRUE)
            if (bool.startsWith(token)) {
                result.add(bool);
            }
        for (String bool : FALSE)
            if (bool.startsWith(token)) {
                result.add(bool);
            }

        if (!result.isEmpty())
            return ImmutableList.copyOf(result);
    }

    return ImmutableList.of("true", "false");
}

From source file:com.android.tools.lint.psi.EcjPsiReferenceList.java

@NonNull
@Override/*  w  ww. j  av a2 s  .c o m*/
public PsiClassType[] getReferencedTypes() {
    if (mReferences == null) {
        return PsiClassType.EMPTY_ARRAY;
    }
    if (mTypes == null) {
        List<PsiClassType> types = Lists.newArrayListWithCapacity(mReferences.length);
        for (TypeReference reference : mReferences) {
            PsiType type = mManager.findType(reference);
            if (type instanceof PsiClassType) {
                types.add((PsiClassType) type);
            }
        }
        mTypes = types.toArray(PsiClassType.EMPTY_ARRAY);
    }
    return mTypes;
}

From source file:com.android.build.gradle.tasks.GenerateResValues.java

@SuppressWarnings("unused") // Synthetic input.
@Input/*from   ww  w . j  a va2 s  .co  m*/
List<String> getItemValues() {
    List<Object> resolvedItems = getItems();
    List<String> list = Lists.newArrayListWithCapacity(resolvedItems.size() * 3);

    for (Object object : resolvedItems) {
        if (object instanceof String) {
            list.add((String) object);
        } else if (object instanceof ClassField) {
            ClassField field = (ClassField) object;
            list.add(field.getType());
            list.add(field.getName());
            list.add(field.getValue());
        }
    }

    return list;
}

From source file:org.eclipse.xtext.xbase.typesystem.override.AbstractResolvedOperation.java

@Override
public List<IResolvedOperation> getOverriddenAndImplementedMethods() {
    if (validOverrides != null)
        return validOverrides;
    List<JvmOperation> candidates = getOverriddenAndImplementedMethodCandidates();
    if (candidates.isEmpty())
        return Collections.emptyList();
    List<IResolvedOperation> result = Lists.newArrayListWithCapacity(candidates.size());
    for (JvmOperation candidate : candidates) {
        // we know that our candidates are computed from the hierarchy
        // thus there is no need to check the declarator for inheritance
        IOverrideCheckResult checkResult = getOverrideTester().isSubsignature(this, candidate, false);
        if (checkResult.isOverridingOrImplementing()) {
            result.add(createResolvedOperationInHierarchy(candidate, checkResult));
        }/*  ww  w. j  a va2  s .c  o  m*/
    }
    return validOverrides = Collections.unmodifiableList(result);
}

From source file:org.artifactory.update.md.current.PassThroughMetadataReaderImpl.java

@Override
public List<MetadataEntryInfo> getMetadataEntries(File file, MutableStatusHolder status) {
    if (!file.isDirectory()) {
        status.error("Expecting a directory but got file: " + file.getAbsolutePath(), log);
        return Collections.emptyList();
    }/*w w  w  .j  av a 2s .  c om*/

    String[] metadataFileNames = file.list(new SuffixFileFilter(".xml"));
    if (metadataFileNames == null) {
        status.error("Cannot read list of metadata files from " + file.getAbsolutePath() + ": "
                + Files.readFailReason(file), log);
        return Collections.emptyList();
    }

    //Import all the xml files within the metadata folder
    List<MetadataEntryInfo> result = Lists.newArrayListWithCapacity(metadataFileNames.length);
    for (String metadataFileName : metadataFileNames) {
        File metadataFile = new File(file, metadataFileName);
        String extension = PathUtils.getExtension(metadataFileName);
        if (!verify(status, metadataFileName, metadataFile, extension)) {
            continue;
        }
        status.debug("Importing metadata from '" + metadataFile.getPath() + "'.", log);

        try {
            // metadata name is the name of the file without the extension
            String metadataName = PathUtils.stripExtension(metadataFileName);
            String xmlContent = FileUtils.readFileToString(metadataFile, "utf-8");
            MetadataEntryInfo metadataEntry = createMetadataEntry(metadataName, xmlContent);
            result.add(metadataEntry);
        } catch (Exception e) {
            status.error("Failed to import xml metadata from '" + metadataFile.getAbsolutePath() + "'.", e,
                    log);
        }
    }
    return result;
}

From source file:com.palantir.atlasdb.schema.RowTransformers.java

/**
 * Returns a function that changes the type of the components in each row without changing their order.
 *///from   w w w. ja  v a2 s . com
public static Function<byte[], byte[]> rowNameTransformation(List<EncodingType> initialTypes,
        List<EncodingType> finalTypes) {
    Preconditions.checkArgument(initialTypes.size() == finalTypes.size());
    List<RowComponent> fullPermutation = Lists.newArrayListWithCapacity(initialTypes.size());
    for (int i = 0; i < initialTypes.size(); i++) {
        fullPermutation.add(RowComponent.of(i, finalTypes.get(i)));
    }
    return rowNamePermuformation(initialTypes, fullPermutation);
}

From source file:org.eclipse.xtext.xbase.typesystem.util.BoundTypeArgumentMerger.java

public LightweightMergedBoundTypeArgument merge(Collection<LightweightBoundTypeArgument> allArguments,
        ITypeReferenceOwner owner) {/*w  w  w. j av a2s. c  om*/
    if (allArguments.isEmpty())
        return null;
    if (allArguments.size() == 1) {
        LightweightBoundTypeArgument argument = Iterables.getOnlyElement(allArguments);
        return getSingleArgumentAsMergedArgument(argument);
    }
    List<LightweightTypeReference> invariantTypes = Lists.newArrayListWithCapacity(0);
    List<VarianceInfo> invariantVariances = Lists.newArrayListWithCapacity(0);
    List<LightweightTypeReference> invariantTypesFromOut = Lists.newArrayListWithCapacity(0);
    List<VarianceInfo> invariantVariancesFromOut = Lists.newArrayListWithCapacity(0);
    List<LightweightTypeReference> outTypes = Lists.newArrayListWithCapacity(0);
    List<LightweightTypeReference> constraintOutTypes = Lists.newArrayListWithCapacity(0);
    List<VarianceInfo> outVariances = Lists.newArrayListWithCapacity(0);
    List<LightweightTypeReference> inTypes = Lists.newArrayListWithCapacity(0);
    List<VarianceInfo> inVariances = Lists.newArrayListWithCapacity(0);
    Set<Object> seenOrigin = Sets.newHashSet();
    for (LightweightBoundTypeArgument boundTypeArgument : allArguments) {
        Object origin = boundTypeArgument.getOrigin();
        switch (boundTypeArgument.getDeclaredVariance()) {
        case INVARIANT:
            processBoundTypeArgument(boundTypeArgument, invariantTypes, invariantVariances, origin, seenOrigin);
            break;
        case OUT:
            BoundTypeArgumentSource source = boundTypeArgument.getSource();
            if (invariantTypes.isEmpty() && isTransitiveHintFromReslved(boundTypeArgument, origin, source)) {
                invariantTypesFromOut.add(boundTypeArgument.getTypeReference());
                if (seenOrigin.add(origin)) {
                    invariantVariancesFromOut.add(VarianceInfo.INVARIANT);
                }
            }
            if (source == BoundTypeArgumentSource.CONSTRAINT) {
                constraintOutTypes.add(boundTypeArgument.getTypeReference());
            } else {
                outTypes.add(boundTypeArgument.getTypeReference());
            }
            addVariance(boundTypeArgument, outVariances, origin, seenOrigin);
            break;
        case IN:
            processBoundTypeArgument(boundTypeArgument, inTypes, inVariances, origin, seenOrigin);
            break;
        }
    }
    LightweightTypeReference type = null;
    VarianceInfo variance = null;
    if (outTypes.isEmpty() && inTypes.isEmpty()) {
        outTypes = constraintOutTypes;
    }
    if (!invariantTypes.isEmpty()) {
        type = invariantTypes.get(0);
        variance = VarianceInfo.INVARIANT.mergeDeclaredWithActuals(invariantVariances);
        if (variance == null && invariantVariances.contains(VarianceInfo.IN) && invariantTypes.size() > 1) {
            type = getCommonSuperTypes(invariantTypes, owner);
        } else if (!invariantTypesFromOut.isEmpty()) {
            LightweightTypeReference fromOut = invariantTypesFromOut.get(0);
            if (fromOut.isAssignableFrom(type)) {
                type = fromOut;
                variance = VarianceInfo.INVARIANT;
            }
        }
        if (!outVariances.isEmpty()) {
            VarianceInfo outVariance = VarianceInfo.OUT.mergeDeclaredWithActuals(outVariances);
            variance = VarianceInfo.OUT.mergeInvariance(variance, outVariance);
        } else if (!inVariances.isEmpty()) {
            VarianceInfo inVariance = VarianceInfo.IN.mergeDeclaredWithActuals(inVariances);
            variance = VarianceInfo.IN.mergeInvariance(variance, inVariance);
        }
    } else if (!outTypes.isEmpty()) {
        type = getCommonSuperTypes(outTypes, owner);
        variance = VarianceInfo.OUT.mergeDeclaredWithActuals(outVariances);
        if (!inVariances.isEmpty()) {
            LightweightTypeReference inType = getMostSpecialType(inTypes);
            boolean conformant = type.isAssignableFrom(inType,
                    new TypeConformanceComputationArgument(false, true, false, false, true, false));
            if (conformant) {
                VarianceInfo inVariance = VarianceInfo.IN.mergeDeclaredWithActuals(inVariances);
                variance = VarianceInfo.IN.mergeWithOut(variance, inVariance, conformant);
            } else {
                boolean reverseConformant = inType.isAssignableFrom(type,
                        new TypeConformanceComputationArgument(false, false, false, false, true, false));
                if (reverseConformant && variance == VarianceInfo.INVARIANT
                        && VarianceInfo.IN.mergeDeclaredWithActuals(inVariances) == VarianceInfo.INVARIANT) {
                    if (VarianceInfo.IN.mergeDeclaredWithActuals(outVariances) != null) {
                        type = inType;
                        variance = VarianceInfo.OUT;
                    }
                } else {
                    VarianceInfo inVariance = VarianceInfo.IN.mergeDeclaredWithActuals(inVariances);
                    variance = VarianceInfo.IN.mergeWithOut(variance, inVariance, conformant);
                }
            }
        }
    } else if (!inTypes.isEmpty()) {
        type = getMostSpecialType(inTypes);
        variance = VarianceInfo.IN.mergeDeclaredWithActuals(inVariances);
    }
    return new LightweightMergedBoundTypeArgument(type, variance);
}

From source file:com.ojuslabs.oct.data.Bond.java

/**
 * The atoms participating in a bond cannot change. Accordingly, they have
 * be non-null and valid in the current molecule. However, this constructor
 * is package-internal. It is the responsibility of {@link Molecule} to
 * comply with these requirements.//  w  w w  .ja va2s . c  o m
 * 
 * @param id
 *            The unique ID of this bond.
 * @param a1
 *            The first atom participating in this bond.
 * @param a2
 *            The second atom participating in this bond.
 * @param order
 *            The bond order of this bond. See {@link common.BondOrder} for
 *            possible values.
 */
Bond(int id, Atom a1, Atom a2, BondOrder order) {
    _id = id;
    _a1 = a1;
    _a2 = a2;

    _hash = hash(_a1, _a2);

    _order = order;
    _stereo = BondStereo.NONE;

    _rings = Lists.newArrayListWithCapacity(Constants.LIST_SIZE_S);
}