Example usage for java.util LinkedList addAll

List of usage examples for java.util LinkedList addAll

Introduction

In this page you can find the example usage for java.util LinkedList addAll.

Prototype

public boolean addAll(Collection<? extends E> c) 

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.

Usage

From source file:ubic.gemma.datastructure.matrix.ExpressionDataMatrixColumnSort.java

/**
 * Sort biomaterials according to a list of ordered factors
 * //from  ww w.  ja  va 2 s.c o m
 * @param start biomaterials to sort
 * @param factorsToUse sorted list of factors to define sort order for biomaterials, cannot be null
 * @return
 */
public static List<BioMaterial> orderBiomaterialsBySortedFactors(List<BioMaterial> start,
        List<ExperimentalFactor> factors) {

    if (start.size() == 1) {
        return start;
    }

    if (start.size() == 0) {
        throw new IllegalArgumentException("Must provide some biomaterials");
    }
    if (factors == null) {
        throw new IllegalArgumentException("Must provide sorted factors, or at least an empty list");
    }
    if (factors.isEmpty()) {
        // we're done.
        return start;
    }

    ExperimentalFactor simplest = factors.get(0);

    if (simplest == null) {
        // we're done.
        return start;
    }

    /*
     * Order this chunk by the selected factor
     */

    Map<FactorValue, List<BioMaterial>> fv2bms = buildFv2BmMap(start);
    List<BioMaterial> ordered = orderByFactor(simplest, fv2bms, start,
            new HashMap<ExperimentalFactor, Collection<BioMaterial>>());

    LinkedList<ExperimentalFactor> factorsStillToDo = new LinkedList<ExperimentalFactor>();
    factorsStillToDo.addAll(factors);
    factorsStillToDo.remove(simplest);

    if (factorsStillToDo.size() == 0) {
        /*
         * No more ordering is necessary.
         */
        return ordered;
    }

    log.debug("Factors: " + factors.size());

    /*
     * Recurse in and order each chunk. First split it up, but retaining the order we just made.
     */
    LinkedHashMap<FactorValue, List<BioMaterial>> chunks = chunkOnFactor(simplest, ordered);

    if (chunks == null) {
        // this means we should bail, gracefully.
        return start;
    }

    /*
     * Process each chunk.
     */
    List<BioMaterial> result = new ArrayList<BioMaterial>();
    for (FactorValue fv : chunks.keySet()) {
        List<BioMaterial> chunk = chunks.get(fv);

        if (chunk.size() < 2) {
            result.addAll(chunk);
        } else {
            List<BioMaterial> orderedChunk = orderBiomaterialsBySortedFactors(chunk, factorsStillToDo);
            result.addAll(orderedChunk);
        }
    }

    return result;

}

From source file:ubic.gemma.datastructure.matrix.ExpressionDataMatrixColumnSort.java

/**
 * Sort biomaterials according to a list of ordered factors
 * /*from   w w w. j a va  2s.  co  m*/
 * @param start biomaterials to sort
 * @param factorsToUse sorted list of factors to define sort order for biomaterials, cannot be null
 * @return
 */
public static List<BioMaterialValueObject> orderBiomaterialsBySortedFactorsVO(
        List<BioMaterialValueObject> start, List<ExperimentalFactor> factors) {

    if (start.size() == 1) {
        return start;
    }

    if (start.size() == 0) {
        throw new IllegalArgumentException("Must provide some biomaterials");
    }
    if (factors == null) {
        throw new IllegalArgumentException("Must provide sorted factors, or at least an empty list");
    }
    if (factors.isEmpty()) {
        // we're done.
        return start;
    }

    ExperimentalFactor simplest = factors.get(0);

    if (simplest == null) {
        // we're done.
        return start;
    }

    /*
     * Order this chunk by the selected factor
     */

    Map<FactorValueValueObject, List<BioMaterialValueObject>> fv2bms = buildFv2BmVOMap(start);
    List<BioMaterialValueObject> ordered = orderByFactorVo(simplest, fv2bms, start,
            new HashMap<ExperimentalFactor, Collection<BioMaterialValueObject>>());

    LinkedList<ExperimentalFactor> factorsStillToDo = new LinkedList<ExperimentalFactor>();
    factorsStillToDo.addAll(factors);
    factorsStillToDo.remove(simplest);

    if (factorsStillToDo.size() == 0) {
        /*
         * No more ordering is necessary.
         */
        return ordered;
    }

    log.debug("Factors: " + factors.size());

    /*
     * Recurse in and order each chunk. First split it up, but retaining the order we just made.
     */
    LinkedHashMap<FactorValueValueObject, List<BioMaterialValueObject>> chunks = chunkOnFactorVO(simplest,
            ordered);

    if (chunks == null) {
        // this means we should bail, gracefully.
        return start;
    }

    /*
     * Process each chunk.
     */
    List<BioMaterialValueObject> result = new ArrayList<BioMaterialValueObject>();
    for (FactorValueValueObject fv : chunks.keySet()) {
        List<BioMaterialValueObject> chunk = chunks.get(fv);

        if (chunk.size() < 2) {
            result.addAll(chunk);
        } else {
            List<BioMaterialValueObject> orderedChunk = orderBiomaterialsBySortedFactorsVO(chunk,
                    factorsStillToDo);
            result.addAll(orderedChunk);
        }
    }

    return result;

}

From source file:org.fusesource.mop.support.CommandDefinition.java

/**
 * Lets split the argument list into the artifact(s) strings then the remaining arguments
 *//*from   w  ww .  j  av a  2 s . co  m*/
protected void splitArgumentList(LinkedList<String> argList, LinkedList<String> artifacts,
        LinkedList<String> remainingArgs) {
    if (argList.isEmpty()) {
        return;
    }
    artifacts.add(argList.removeFirst());
    while (!argList.isEmpty()) {
        String arg = argList.removeFirst();
        if (mop.isAnotherArtifactId(arg)) {
            artifacts.add(arg);
        } else {
            remainingArgs.add(arg);
            remainingArgs.addAll(argList);
            break;
        }
    }

}

From source file:com.handcraftedbits.bamboo.plugin.go.task.test.GoTestTaskType.java

@NotNull
@Override//from   w  w w .  j  a  v  a  2  s. c  om
public TaskResult execute(@NotNull final TaskContext taskContext) throws TaskException {
    final GoTestTaskConfiguration configuration = new GoTestTaskConfiguration(getTaskHelper(), taskContext);
    int i = 0;
    final File outputDirectory = new File(taskContext.getWorkingDirectory(), configuration.getLogOutputPath());
    final List<GoArgumentList> packagesWithArguments = configuration
            .getPackagesWithArguments(GoTestTaskConfiguration.flagsToExclude);
    final ProcessHelper processHelper = getTaskHelper().createProcessHelper(taskContext);

    if (outputDirectory.exists()) {
        try {
            FileUtils.forceDelete(outputDirectory);
        }

        catch (final IOException e) {
            taskContext.getBuildLogger().addErrorLogEntry(getTaskHelper().getText(
                    "task.test.error.directory." + "results.delete", outputDirectory.getAbsolutePath()));

            return TaskResultBuilder.newBuilder(taskContext).failedWithError().build();
        }
    }

    if (!outputDirectory.mkdirs()) {
        taskContext.getBuildLogger().addErrorLogEntry(getTaskHelper()
                .getText("task.test.error.directory." + "results.create", outputDirectory.getAbsolutePath()));

        return TaskResultBuilder.newBuilder(taskContext).failedWithError().build();
    }

    for (final GoArgumentList packageWithArguments : packagesWithArguments) {
        final LinkedList<String> commandLine = new LinkedList<>();
        final FileOutputHandler fileOutputHandler = new FileOutputHandler(
                new File(outputDirectory, "goTestOutput" + (i++) + ".log"));
        final ExternalProcess process;

        commandLine.add(configuration.getGoExecutable());
        commandLine.add("test");
        commandLine.add("-v");
        commandLine.addAll(packageWithArguments.getItems());

        if (configuration.shouldLogOutputToBuild()) {
            process = processHelper.executeProcess(commandLine, configuration.getSourcePath(),
                    configuration.getEnvironmentVariables(),
                    new CompositeOutputHandler(taskContext.getBuildLogger(),
                            processHelper.createStandardOutputHandler(), fileOutputHandler),
                    new CompositeOutputHandler(taskContext.getBuildLogger(),
                            processHelper.createStandardErrorHandler(), fileOutputHandler));
        }

        else {
            process = processHelper.executeProcess(commandLine, configuration.getSourcePath(),
                    configuration.getEnvironmentVariables(), fileOutputHandler, fileOutputHandler);
        }

        if (process.getHandler().getExitCode() != 0) {
            return TaskResultBuilder.newBuilder(taskContext).checkReturnCode(process, 0).build();
        }
    }

    return TaskResultBuilder.newBuilder(taskContext).success().build();
}

From source file:mitm.application.djigzo.james.mailets.MailAttributes.java

private LinkedList<String> parseAttributes(Collection<String> attributes, Mail mail) throws MessagingException {
    LinkedList<String> result = new LinkedList<String>();

    if (attributes != null) {
        for (String attribute : attributes) {
            result.addAll(parseAttribute(attribute, mail));
        }/*w  ww.  j  av  a 2s .  c  om*/
    }

    return result;
}

From source file:org.kitodo.dataformat.access.DivXmlElementAccess.java

/**
 * Creates a METS {@code <div>} element from this structure.
 *
 * @param mediaUnitIDs//from  w  ww.ja v a 2 s .com
 *            the assigned identifier for each media unit so that the link
 *            pairs of the struct link section can be formed later
 * @param smLinkData
 *            the link pairs of the struct link section are added to this
 *            list
 * @param mets
 *            the METS structure in which the meta-data is added
 * @return a METS {@code <div>} element
 */
DivType toDiv(Map<MediaUnit, String> mediaUnitIDs, LinkedList<Pair<String, String>> smLinkData, Mets mets) {
    DivType div = new DivType();
    div.setID(metsReferrerId);
    div.setLABEL(super.getLabel());
    div.setORDERLABEL(super.getOrderlabel());
    div.setTYPE(super.getType());
    smLinkData.addAll(super.getViews().parallelStream().map(View::getMediaUnit).map(mediaUnitIDs::get)
            .map(mediaUnitId -> Pair.of(metsReferrerId, mediaUnitId)).collect(Collectors.toList()));

    Optional<MdSecType> optionalDmdSec = createMdSec(super.getMetadata(), MdSec.DMD_SEC);
    if (optionalDmdSec.isPresent()) {
        MdSecType dmdSec = optionalDmdSec.get();
        String name = metsReferrerId + ':' + MdSec.DMD_SEC.toString();
        dmdSec.setID(UUID.nameUUIDFromBytes(name.getBytes(StandardCharsets.UTF_8)).toString());
        mets.getDmdSec().add(dmdSec);
        div.getDMDID().add(dmdSec);
    }
    Optional<AmdSecType> optionalAmdSec = createAmdSec(super.getMetadata(), metsReferrerId, div);
    if (optionalAmdSec.isPresent()) {
        AmdSecType admSec = optionalAmdSec.get();
        mets.getAmdSec().add(admSec);
    }
    if (Objects.nonNull(super.getLink())) {
        MptrXmlElementAccess.addMptrToDiv(super.getLink(), div);
    }
    for (IncludedStructuralElement subincludedStructuralElement : super.getChildren()) {
        div.getDiv().add(
                new DivXmlElementAccess(subincludedStructuralElement).toDiv(mediaUnitIDs, smLinkData, mets));
    }
    return div;
}

From source file:com.amazonaws.services.logs.connectors.kinesis.KinesisTransformer.java

@Override
public Collection<Record> fromClasses(Collection<CloudWatchLogsEvent> events) throws IOException {
    LinkedList<Record> records = new LinkedList<Record>();

    LinkedList<CloudWatchLogsEvent> buffer = new LinkedList<CloudWatchLogsEvent>();
    String key = null;// w w  w .j a v a  2 s. c o m
    Iterator<CloudWatchLogsEvent> iter = events.iterator();
    while (iter.hasNext()) {
        CloudWatchLogsEvent event = iter.next();
        String nextKey = getPartitionKey(event);
        if (key != null && !key.equals(nextKey)) {
            records.addAll(createRecords(buffer));
            buffer.clear();
        }
        buffer.add(event);
    }
    if (buffer.size() > 0)
        records.addAll(createRecords(buffer));
    return records;
}

From source file:org.apache.hadoop.fs.shell.Command.java

/**
 *  Expands a list of arguments into {@link PathData} objects.  The default
 *  behavior is to call {@link #expandArgument(String)} on each element
 *  which by default globs the argument.  The loop catches IOExceptions,
 *  increments the error count, and displays the exception.
 * @param args strings to expand into {@link PathData} objects
 * @return list of all {@link PathData} objects the arguments
 * @throws IOException if anything goes wrong...
 *//*  w w w  .ja v  a2 s.co m*/
protected LinkedList<PathData> expandArguments(LinkedList<String> args) throws IOException {
    LinkedList<PathData> expandedArgs = new LinkedList<PathData>();
    for (String arg : args) {
        try {
            expandedArgs.addAll(expandArgument(arg));
        } catch (IOException e) { // other exceptions are probably nasty
            displayError(e);
        }
    }
    return expandedArgs;
}

From source file:com.heliosdecompiler.helios.tasks.AddFilesTask.java

private void handleDirectory(File file) throws IOException {
    LinkedList<File> filesToProcess = new LinkedList<>();
    filesToProcess.add(file);/*from  www .j  a  va 2s .c om*/
    Set<String> filesProcessed = new HashSet<>();

    while (!filesToProcess.isEmpty()) {
        File current = filesToProcess.pop();
        if (current.isFile() && filesProcessed.add(current.getCanonicalPath())) {
            handle(current);
        } else {
            File[] listFiles = current.listFiles();
            if (listFiles != null) {
                filesToProcess.addAll(Arrays.asList(listFiles));
            }
        }
    }
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSelectIntoJoinRule.java

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    Collection<LogicalVariable> joinLiveVarsLeft = new HashSet<LogicalVariable>();
    Collection<LogicalVariable> joinLiveVarsRight = new HashSet<LogicalVariable>();
    Collection<LogicalVariable> liveInOpsToPushLeft = new HashSet<LogicalVariable>();
    Collection<LogicalVariable> liveInOpsToPushRight = new HashSet<LogicalVariable>();

    List<ILogicalOperator> pushedOnLeft = new ArrayList<ILogicalOperator>();
    List<ILogicalOperator> pushedOnRight = new ArrayList<ILogicalOperator>();
    LinkedList<ILogicalOperator> notPushedStack = new LinkedList<ILogicalOperator>();
    Collection<LogicalVariable> usedVars = new HashSet<LogicalVariable>();
    Collection<LogicalVariable> producedVars = new HashSet<LogicalVariable>();

    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.SELECT) {
        return false;
    }/*from w  ww  .  ja va 2 s  . c  om*/
    SelectOperator select = (SelectOperator) op;
    Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
    AbstractLogicalOperator son = (AbstractLogicalOperator) opRef2.getValue();
    AbstractLogicalOperator op2 = son;
    boolean needToPushOps = false;
    while (son.isMap()) {
        needToPushOps = true;
        Mutable<ILogicalOperator> opRefLink = son.getInputs().get(0);
        son = (AbstractLogicalOperator) opRefLink.getValue();
    }

    if (son.getOperatorTag() != LogicalOperatorTag.INNERJOIN
            && son.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) {
        return false;
    }
    boolean isLoj = son.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN;
    AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) son;

    Mutable<ILogicalOperator> joinBranchLeftRef = join.getInputs().get(0);
    Mutable<ILogicalOperator> joinBranchRightRef = join.getInputs().get(1);

    if (needToPushOps) {
        ILogicalOperator joinBranchLeft = joinBranchLeftRef.getValue();
        ILogicalOperator joinBranchRight = joinBranchRightRef.getValue();
        VariableUtilities.getLiveVariables(joinBranchLeft, joinLiveVarsLeft);
        VariableUtilities.getLiveVariables(joinBranchRight, joinLiveVarsRight);
        Mutable<ILogicalOperator> opIterRef = opRef2;
        ILogicalOperator opIter = op2;
        while (opIter != join) {
            LogicalOperatorTag tag = ((AbstractLogicalOperator) opIter).getOperatorTag();
            if (tag == LogicalOperatorTag.PROJECT) {
                notPushedStack.addFirst(opIter);
            } else {
                VariableUtilities.getUsedVariables(opIter, usedVars);
                VariableUtilities.getProducedVariables(opIter, producedVars);
                if (joinLiveVarsLeft.containsAll(usedVars)) {
                    pushedOnLeft.add(opIter);
                    liveInOpsToPushLeft.addAll(producedVars);
                } else if (joinLiveVarsRight.containsAll(usedVars)) {
                    pushedOnRight.add(opIter);
                    liveInOpsToPushRight.addAll(producedVars);
                } else {
                    return false;
                }
            }
            opIterRef = opIter.getInputs().get(0);
            opIter = opIterRef.getValue();
        }
        if (isLoj && pushedOnLeft.isEmpty()) {
            return false;
        }
    }

    boolean intersectsAllBranches = true;
    boolean[] intersectsBranch = new boolean[join.getInputs().size()];
    LinkedList<LogicalVariable> selectVars = new LinkedList<LogicalVariable>();
    select.getCondition().getValue().getUsedVariables(selectVars);
    int i = 0;
    for (Mutable<ILogicalOperator> branch : join.getInputs()) {
        LinkedList<LogicalVariable> branchVars = new LinkedList<LogicalVariable>();
        VariableUtilities.getLiveVariables(branch.getValue(), branchVars);
        if (i == 0) {
            branchVars.addAll(liveInOpsToPushLeft);
        } else {
            branchVars.addAll(liveInOpsToPushRight);
        }
        if (OperatorPropertiesUtil.disjoint(selectVars, branchVars)) {
            intersectsAllBranches = false;
        } else {
            intersectsBranch[i] = true;
        }
        i++;
    }
    if (!intersectsBranch[0] && !intersectsBranch[1]) {
        return false;
    }
    if (needToPushOps) {
        pushOps(pushedOnLeft, joinBranchLeftRef, context);
        pushOps(pushedOnRight, joinBranchRightRef, context);
    }
    if (intersectsAllBranches) {
        addCondToJoin(select, join, context);
    } else { // push down
        Iterator<Mutable<ILogicalOperator>> branchIter = join.getInputs().iterator();
        ILogicalExpression selectCondition = select.getCondition().getValue();
        boolean lojToInner = false;
        for (int j = 0; j < intersectsBranch.length; j++) {
            Mutable<ILogicalOperator> branch = branchIter.next();
            boolean inter = intersectsBranch[j];
            if (inter) {
                if (j > 0 && isLoj) {
                    // if a left outer join, if the select condition is not-null filtering,
                    // we rewrite left outer join
                    // to inner join for this case.
                    if (containsNotNullFiltering(selectCondition)) {
                        lojToInner = true;
                    }
                }
                if ((j > 0 && isLoj) && containsNullFiltering(selectCondition)) {
                    // Select is-null($$var) cannot be pushed in the right branch of a LOJ;
                    notPushedStack.addFirst(select);
                } else {
                    // Conditions for the left branch can always be pushed.
                    // Other conditions can be pushed to the right branch of a LOJ.
                    copySelectToBranch(select, branch, context);
                }
            }
        }
        if (lojToInner) {
            // Rewrites left outer join  to inner join.
            InnerJoinOperator innerJoin = new InnerJoinOperator(join.getCondition());
            innerJoin.getInputs().addAll(join.getInputs());
            join = innerJoin;
            context.computeAndSetTypeEnvironmentForOperator(join);
        }
    }
    ILogicalOperator top = join;
    for (ILogicalOperator npOp : notPushedStack) {
        List<Mutable<ILogicalOperator>> npInpList = npOp.getInputs();
        npInpList.clear();
        npInpList.add(new MutableObject<ILogicalOperator>(top));
        context.computeAndSetTypeEnvironmentForOperator(npOp);
        top = npOp;
    }
    opRef.setValue(top);
    return true;

}