Example usage for java.util List set

List of usage examples for java.util List set

Introduction

In this page you can find the example usage for java.util List set.

Prototype

E set(int index, E element);

Source Link

Document

Replaces the element at the specified position in this list with the specified element (optional operation).

Usage

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.SubstituteVariableVisitor.java

@Override
public Void visitDataScanOperator(DataSourceScanOperator op, Pair<LogicalVariable, LogicalVariable> pair)
        throws AlgebricksException {
    List<LogicalVariable> variables = op.getVariables();
    for (int i = 0; i < variables.size(); i++) {
        if (variables.get(i) == pair.first) {
            variables.set(i, pair.second);
            return null;
        }//  w  w  w.ja  va 2  s  . c  om
    }
    substVarTypes(op, pair);
    return null;
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.SubstituteVariableVisitor.java

@Override
public Void visitUnnestMapOperator(UnnestMapOperator op, Pair<LogicalVariable, LogicalVariable> pair)
        throws AlgebricksException {
    List<LogicalVariable> variables = op.getVariables();
    for (int i = 0; i < variables.size(); i++) {
        if (variables.get(i) == pair.first) {
            variables.set(i, pair.second);
            return null;
        }/*from w w  w .  j  a va 2 s.  co  m*/
    }
    op.getExpressionRef().getValue().substituteVar(pair.first, pair.second);
    substVarTypes(op, pair);
    return null;
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.SubstituteVariableVisitor.java

@Override
public Void visitUnnestOperator(UnnestOperator op, Pair<LogicalVariable, LogicalVariable> pair)
        throws AlgebricksException {
    List<LogicalVariable> variables = op.getVariables();
    for (int i = 0; i < variables.size(); i++) {
        if (variables.get(i) == pair.first) {
            variables.set(i, pair.second);
            return null;
        }/*from  www .  j a  v a  2 s .c o m*/
    }
    op.getExpressionRef().getValue().substituteVar(pair.first, pair.second);
    substVarTypes(op, pair);
    return null;
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.SubstituteVariableVisitor.java

@Override
public Void visitExternalDataLookupOperator(ExternalDataLookupOperator op,
        Pair<LogicalVariable, LogicalVariable> pair) throws AlgebricksException {
    List<LogicalVariable> variables = op.getVariables();
    for (int i = 0; i < variables.size(); i++) {
        if (variables.get(i) == pair.first) {
            variables.set(i, pair.second);
            return null;
        }//w  ww . j  a  v a 2s .c  o m
    }
    op.getExpressionRef().getValue().substituteVar(pair.first, pair.second);
    substVarTypes(op, pair);
    return null;
}

From source file:com.epimorphics.lda.renderers.velocity.VelocityRendering.java

/**
 * Set additional properties that are calculated based on current state
 * @param velocityPath The Velocity path as given
 * @param p The current Properties object
 *///  w  w w .j  a  v  a  2 s . c o  m
protected void setDynamicProperties(List<String> velocityPath, Properties p) {
    if (p.getProperty(VELOCITY_FILE_RESOURCE_LOADER_PATH) == null) {
        if (velocityPath.size() > 1) {
            for (int i = 0; i < velocityPath.size(); i++) {
                velocityPath.set(i, velocityPath.get(i).replaceFirst("^file:", ""));
            }
            p.setProperty(VELOCITY_FILE_RESOURCE_LOADER_PATH, StringUtils.join(velocityPath, ", "));
        } else {
            String velocityURL = "";
            if (velocityPath.size() > 0) {
                velocityURL = velocityPath.get(0);
            }

            if (velocityURL.matches("^http:.*")) {
                p.setProperty("url.resource.loader.root", velocityURL);
            } else {
                p.setProperty(VELOCITY_FILE_RESOURCE_LOADER_PATH, velocityURL.replaceFirst("^file:", ""));
            }

        }
    }
}

From source file:com.aoindustries.website.signup.SignupCustomizeServerActionHelper.java

public static void setRequestAttributes(ServletContext servletContext, HttpServletRequest request,
        HttpServletResponse response, SignupSelectPackageForm signupSelectPackageForm,
        SignupCustomizeServerForm signupCustomizeServerForm) throws IOException, SQLException {
    AOServConnector rootConn = SiteSettings.getInstance(servletContext).getRootAOServConnector();
    PackageDefinition packageDefinition = rootConn.getPackageDefinitions()
            .get(signupSelectPackageForm.getPackageDefinition());
    if (packageDefinition == null)
        throw new SQLException(
                "Unable to find PackageDefinition: " + signupSelectPackageForm.getPackageDefinition());
    List<PackageDefinitionLimit> limits = packageDefinition.getLimits();

    // Find the cheapest resources to scale prices from
    int maxPowers = 0;
    PackageDefinitionLimit cheapestPower = null;
    int maxCPUs = 0;
    PackageDefinitionLimit cheapestCPU = null;
    int maxRAMs = 0;
    PackageDefinitionLimit cheapestRAM = null;
    int maxSataControllers = 0;
    PackageDefinitionLimit cheapestSataController = null;
    int maxScsiControllers = 0;
    PackageDefinitionLimit cheapestScsiController = null;
    int maxDisks = 0;
    PackageDefinitionLimit cheapestDisk = null;
    for (PackageDefinitionLimit limit : limits) {
        String resourceName = limit.getResource().getName();
        if (resourceName.startsWith("hardware_power_")) {
            int limitPower = limit.getHardLimit();
            if (limitPower > 0) {
                if (limitPower > maxPowers)
                    maxPowers = limitPower;
                if (cheapestPower == null)
                    cheapestPower = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestPower.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestPower = limit;
                }//from   w ww .  j a  v  a 2 s . c  o m
            }
        } else if (resourceName.startsWith("hardware_processor_")) {
            int limitCpu = limit.getHardLimit();
            if (limitCpu > 0) {
                if (limitCpu > maxCPUs)
                    maxCPUs = limitCpu;
                if (cheapestCPU == null)
                    cheapestCPU = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestCPU.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestCPU = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_ram_")) {
            int limitRAM = limit.getHardLimit();
            if (limitRAM > 0) {
                if (limitRAM > maxRAMs)
                    maxRAMs = limitRAM;
                if (cheapestRAM == null)
                    cheapestRAM = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestRAM.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestRAM = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_disk_controller_sata_")) {
            int limitSataController = limit.getHardLimit();
            if (limitSataController > 0) {
                if (limitSataController > maxSataControllers)
                    maxSataControllers = limitSataController;
                if (cheapestSataController == null)
                    cheapestSataController = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestSataController.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestSataController = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_disk_controller_scsi_")) {
            int limitScsiController = limit.getHardLimit();
            if (limitScsiController > 0) {
                if (limitScsiController > maxScsiControllers)
                    maxScsiControllers = limitScsiController;
                if (cheapestScsiController == null)
                    cheapestScsiController = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestScsiController.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestScsiController = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_disk_")) {
            int hardLimit = limit.getHardLimit();
            if (hardLimit > 0) {
                if (cheapestDisk == null)
                    cheapestDisk = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestDisk.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestDisk = limit;
                }
                if (hardLimit > maxDisks)
                    maxDisks = hardLimit;
            }
        }
    }
    if (cheapestCPU == null)
        throw new SQLException("Unable to find cheapestCPU");
    if (cheapestRAM == null)
        throw new SQLException("Unable to find cheapestRAM");
    if (cheapestDisk == null)
        throw new SQLException("Unable to find cheapestDisk");

    // Find all the options
    List<Option> powerOptions = new ArrayList<Option>();
    List<Option> cpuOptions = new ArrayList<Option>();
    List<Option> ramOptions = new ArrayList<Option>();
    List<Option> sataControllerOptions = new ArrayList<Option>();
    List<Option> scsiControllerOptions = new ArrayList<Option>();
    List<List<Option>> diskOptions = new ArrayList<List<Option>>();
    for (int c = 0; c < maxDisks; c++)
        diskOptions.add(new ArrayList<Option>());
    for (PackageDefinitionLimit limit : limits) {
        Resource resource = limit.getResource();
        String resourceName = resource.getName();
        if (resourceName.startsWith("hardware_power_")) {
            int limitPower = limit.getHardLimit();
            if (limitPower > 0) {
                assert cheapestPower != null;
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestPower.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxPowers == 1 ? resource.toString()
                        : (maxPowers + "x" + resource.toString());
                powerOptions.add(new Option(limit.getPkey(), description,
                        BigDecimal.valueOf(maxPowers).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_processor_")) {
            int limitCpu = limit.getHardLimit();
            if (limitCpu > 0) {
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestCPU.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxCPUs == 1 ? resource.toString() : (maxCPUs + "x" + resource.toString());
                cpuOptions.add(new Option(limit.getPkey(), description,
                        BigDecimal.valueOf(maxCPUs).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_ram_")) {
            int limitRAM = limit.getHardLimit();
            if (limitRAM > 0) {
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestRAM.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxRAMs == 1 ? resource.toString() : (maxRAMs + "x" + resource.toString());
                ramOptions.add(new Option(limit.getPkey(), description,
                        BigDecimal.valueOf(maxRAMs).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_disk_controller_sata_")) {
            int limitSataController = limit.getHardLimit();
            if (limitSataController > 0) {
                assert cheapestSataController != null;
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestSataController.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxSataControllers == 1 ? resource.toString()
                        : (maxSataControllers + "x" + resource.toString());
                sataControllerOptions.add(new Option(limit.getPkey(), description, BigDecimal
                        .valueOf(maxSataControllers).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_disk_controller_scsi_")) {
            int limitScsiController = limit.getHardLimit();
            if (limitScsiController > 0) {
                assert cheapestScsiController != null;
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestScsiController.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxScsiControllers == 1 ? resource.toString()
                        : (maxScsiControllers + "x" + resource.toString());
                scsiControllerOptions.add(new Option(limit.getPkey(), description, BigDecimal
                        .valueOf(maxScsiControllers).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_disk_")) {
            int limitDisk = limit.getHardLimit();
            if (limitDisk > 0) {
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal adjustedRate = additionalRate;
                // Discount adjusted rate if the cheapest disk is of this type
                if (cheapestDisk.getResource().getName().startsWith("hardware_disk_")) {
                    BigDecimal cheapestRate = cheapestDisk.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    adjustedRate = adjustedRate.subtract(cheapestRate);
                }
                for (int c = 0; c < maxDisks; c++) {
                    List<Option> options = diskOptions.get(c);
                    // Add none option
                    if (maxDisks > 1 && options.isEmpty())
                        options.add(new Option(-1, "None",
                                c == 0 ? adjustedRate.subtract(additionalRate) : BigDecimal.valueOf(0, 2)));
                    options.add(new Option(limit.getPkey(), resource.toString(),
                            c == 0 ? adjustedRate : additionalRate));
                }
            }
        }
    }

    // Sort by price
    Collections.sort(powerOptions, new Option.PriceComparator());
    Collections.sort(cpuOptions, new Option.PriceComparator());
    Collections.sort(ramOptions, new Option.PriceComparator());
    Collections.sort(sataControllerOptions, new Option.PriceComparator());
    Collections.sort(scsiControllerOptions, new Option.PriceComparator());
    for (List<Option> diskOptionList : diskOptions)
        Collections.sort(diskOptionList, new Option.PriceComparator());

    // Clear any customization settings that are not part of the current package definition (this happens when they
    // select a different package type)
    if (signupCustomizeServerForm.getPowerOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getPowerOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setPowerOption(-1);
    }
    if (signupCustomizeServerForm.getCpuOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getCpuOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setCpuOption(-1);
    }
    if (signupCustomizeServerForm.getRamOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getRamOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setRamOption(-1);
    }
    if (signupCustomizeServerForm.getSataControllerOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getSataControllerOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setSataControllerOption(-1);
    }
    if (signupCustomizeServerForm.getScsiControllerOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getScsiControllerOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setScsiControllerOption(-1);
    }
    List<String> formDiskOptions = signupCustomizeServerForm.getDiskOptions();
    while (formDiskOptions.size() > maxDisks)
        formDiskOptions.remove(formDiskOptions.size() - 1);
    for (int c = 0; c < formDiskOptions.size(); c++) {
        String S = formDiskOptions.get(c);
        if (S != null && S.length() > 0 && !S.equals("-1")) {
            int pkey = Integer.parseInt(S);
            PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits().get(pkey);
            if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
                formDiskOptions.set(c, "-1");
        }
    }

    // Determine if at least one disk is selected
    boolean isAtLeastOneDiskSelected = signupCustomizeServerForm.isAtLeastOneDiskSelected();

    // Default to cheapest if not already selected
    if (cheapestPower != null && signupCustomizeServerForm.getPowerOption() == -1)
        signupCustomizeServerForm.setPowerOption(cheapestPower.getPkey());
    if (signupCustomizeServerForm.getCpuOption() == -1)
        signupCustomizeServerForm.setCpuOption(cheapestCPU.getPkey());
    if (signupCustomizeServerForm.getRamOption() == -1)
        signupCustomizeServerForm.setRamOption(cheapestRAM.getPkey());
    if (cheapestSataController != null && signupCustomizeServerForm.getSataControllerOption() == -1)
        signupCustomizeServerForm.setSataControllerOption(cheapestSataController.getPkey());
    if (cheapestScsiController != null && signupCustomizeServerForm.getScsiControllerOption() == -1)
        signupCustomizeServerForm.setScsiControllerOption(cheapestScsiController.getPkey());
    for (int c = 0; c < maxDisks; c++) {
        List<Option> options = diskOptions.get(c);
        if (!options.isEmpty()) {
            Option firstOption = options.get(0);
            if (!isAtLeastOneDiskSelected && options.size() >= 2
                    && firstOption.getPriceDifference().compareTo(BigDecimal.ZERO) < 0) {
                firstOption = options.get(1);
            }
            String defaultSelected = Integer.toString(firstOption.getPackageDefinitionLimit());
            if (formDiskOptions.size() <= c || formDiskOptions.get(c) == null
                    || formDiskOptions.get(c).length() == 0 || formDiskOptions.get(c).equals("-1"))
                formDiskOptions.set(c, defaultSelected);
        } else {
            formDiskOptions.set(c, "-1");
        }
    }

    // Find the basePrice (base plus minimum number of cheapest of each resource class)
    BigDecimal basePrice = packageDefinition.getMonthlyRate();
    if (basePrice == null)
        basePrice = BigDecimal.valueOf(0, 2);
    if (cheapestPower != null && cheapestPower.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestPower.getAdditionalRate().multiply(BigDecimal.valueOf(maxPowers)));
    if (cheapestCPU.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestCPU.getAdditionalRate().multiply(BigDecimal.valueOf(maxCPUs)));
    if (cheapestRAM.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestRAM.getAdditionalRate());
    if (cheapestSataController != null && cheapestSataController.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestSataController.getAdditionalRate());
    if (cheapestScsiController != null && cheapestScsiController.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestScsiController.getAdditionalRate());
    if (cheapestDisk.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestDisk.getAdditionalRate());

    // Store to request
    request.setAttribute("packageDefinition", packageDefinition);
    request.setAttribute("powerOptions", powerOptions);
    request.setAttribute("cpuOptions", cpuOptions);
    request.setAttribute("ramOptions", ramOptions);
    request.setAttribute("sataControllerOptions", sataControllerOptions);
    request.setAttribute("scsiControllerOptions", scsiControllerOptions);
    request.setAttribute("diskOptions", diskOptions);
    request.setAttribute("basePrice", basePrice);
}

From source file:hudson.tasks.Ant.java

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
        throws InterruptedException, IOException {
    ArgumentListBuilder args = new ArgumentListBuilder();

    EnvVars env = build.getEnvironment(listener);

    AntInstallation ai = getAnt();//  ww w.ja v a 2  s  .c  om
    if (ai == null) {
        args.add(launcher.isUnix() ? "ant" : "ant.bat");
    } else {
        ai = ai.forNode(Computer.currentComputer().getNode(), listener);
        ai = ai.forEnvironment(env);
        String exe = ai.getExecutable(launcher);
        if (exe == null) {
            listener.fatalError(Messages.Ant_ExecutableNotFound(ai.getName()));
            return false;
        }
        args.add(exe);
    }

    VariableResolver<String> vr = build.getBuildVariableResolver();

    String buildFile = env.expand(this.buildFile);
    String targets = Util.replaceMacro(env.expand(this.targets), vr);

    FilePath buildFilePath = buildFilePath(build.getModuleRoot(), buildFile, targets);

    if (!buildFilePath.exists()) {
        // because of the poor choice of getModuleRoot() with CVS/Subversion, people often get confused
        // with where the build file path is relative to. Now it's too late to change this behavior
        // due to compatibility issue, but at least we can make this less painful by looking for errors
        // and diagnosing it nicely. See HUDSON-1782

        // first check if this appears to be a valid relative path from workspace root
        FilePath buildFilePath2 = buildFilePath(build.getWorkspace(), buildFile, targets);
        if (buildFilePath2.exists()) {
            // This must be what the user meant. Let it continue.
            buildFilePath = buildFilePath2;
        } else {
            // neither file exists. So this now really does look like an error.
            listener.fatalError("Unable to find build script at " + buildFilePath);
            return false;
        }
    }

    if (buildFile != null) {
        args.add("-file", buildFilePath.getName());
    }

    Set<String> sensitiveVars = build.getSensitiveBuildVariables();

    args.addKeyValuePairs("-D", build.getBuildVariables(), sensitiveVars);

    args.addKeyValuePairsFromPropertyString("-D", properties, vr, sensitiveVars);

    args.addTokenized(targets.replaceAll("[\t\r\n]+", " "));

    if (ai != null)
        env.put("ANT_HOME", ai.getHome());
    if (antOpts != null)
        env.put("ANT_OPTS", env.expand(antOpts));

    if (!launcher.isUnix()) {
        args = args.toWindowsCommand();
        // For some reason, ant on windows rejects empty parameters but unix does not.
        // Add quotes for any empty parameter values:
        List<String> newArgs = new ArrayList<String>(args.toList());
        newArgs.set(newArgs.size() - 1,
                newArgs.get(newArgs.size() - 1).replaceAll("(?<= )(-D[^\" ]+)= ", "$1=\"\" "));
        args = new ArgumentListBuilder(newArgs.toArray(new String[newArgs.size()]));
    }

    long startTime = System.currentTimeMillis();
    try {
        AntConsoleAnnotator aca = new AntConsoleAnnotator(listener.getLogger(), build.getCharset());
        int r;
        try {
            r = launcher.launch().cmds(args).envs(env).stdout(aca).pwd(buildFilePath.getParent()).join();
        } finally {
            aca.forceEol();
        }
        return r == 0;
    } catch (IOException e) {
        Util.displayIOException(e, listener);

        String errorMessage = Messages.Ant_ExecFailed();
        if (ai == null && (System.currentTimeMillis() - startTime) < 1000) {
            if (getDescriptor().getInstallations() == null)
                // looks like the user didn't configure any Ant installation
                errorMessage += Messages.Ant_GlobalConfigNeeded();
            else
                // There are Ant installations configured but the project didn't pick it
                errorMessage += Messages.Ant_ProjectConfigNeeded();
        }
        e.printStackTrace(listener.fatalError(errorMessage));
        return false;
    }
}

From source file:com.comphenix.xp.messages.MessageFormatter.java

private List<ResourceHolder> addGenerated(MessageFormatter other) {

    List<ResourceHolder> current = new ArrayList<ResourceHolder>(getGenerated());
    List<ResourceHolder> adding = other.getGenerated();

    // Add each resource
    for (int i = 0; i < adding.size(); i++) {
        // Elements outside the list are treated as empty
        if (i < current.size())
            current.set(i, current.get(i).add(adding.get(i)));
        else/*from  w w  w. j av  a 2  s.  c o  m*/
            current.add(adding.get(i));
    }

    return current;
}

From source file:es.pode.empaquetador.presentacion.archivos.gestor.GestorArchivosControllerImpl.java

/**
 * @see es.pode.empaquetador.presentacion.archivos.gestor.GestorArchivosController#cargarDatos(org.apache.struts.action.ActionMapping, es.pode.empaquetador.presentacion.archivos.gestor.CargarDatosForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///from   ww w.j  a v  a  2 s .c  om
public final void cargarDatos(ActionMapping mapping,
        es.pode.empaquetador.presentacion.archivos.gestor.CargarDatosForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    GestorArchivosSession sesArch = getGestorArchivosSession(request);
    String ideID = this.getEmpaquetadorSession(request).getIdLocalizador();

    ArchivoVO recuperado = this.getSrvGestorArchivosService().recuperarArbol(ideID);
    //relleno

    if (sesArch == null || sesArch.getPath() == null) {
        List portapapeles = new ArrayList();
        List pathList = new ArrayList();
        pathList.add(recuperado);

        sesArch.setAccion(NORMAL);
        sesArch.setModoPegar(false);
        sesArch.setPath(pathList);
        sesArch.setPortapapeles(portapapeles);
    } else {
        List listaPath = sesArch.getPath();
        listaPath.set(0, recuperado);
        for (int i = 1; i < listaPath.size(); i++) {
            ArchivoVO elemento = (ArchivoVO) listaPath.get(i);
            String nombre = elemento.getNombre();
            ArchivoVO elementoAnterior = (ArchivoVO) listaPath.get(i - 1);
            ArchivoVO[] arrayContenidos = elementoAnterior.getContenidos();

            ArchivoVO hijo = null;
            for (int j = 0; j < arrayContenidos.length && hijo == null; j++) {
                if (arrayContenidos[j].getNombre().equals(nombre)) {
                    hijo = arrayContenidos[j];
                }
            }

            listaPath.set(i, hijo);
        }
    }
    ArchivoVO[] lista = null;
    ArchivoVO ultimoEnPath = new ArchivoVO();
    if (sesArch.getPath().size() != 1) {
        ultimoEnPath = (ArchivoVO) sesArch.getPath().get(sesArch.getPath().size() - 1);
        if (ultimoEnPath.getCarpetaPadre() == null) {
            lista = this.getSrvGestorArchivosService().listar(ideID, ultimoEnPath.getNombre());
        } else {

            lista = this.getSrvGestorArchivosService().listar(ideID,
                    ultimoEnPath.getCarpetaPadre() + BARRA + ultimoEnPath.getNombre());
        }

    } else /*if (sesArch.getPath().size()==1)*/
    {
        lista = this.getSrvGestorArchivosService().listar(ideID, null);
    }

    //transformo el AchivoVO[] a un arrayList
    List listado = Arrays.asList(lista);

    //inserto la lista en el fomulario
    form.setListado(listado);

    //relleno el portapapeles
    form.setPortapapeles(sesArch.getPortapapeles());

    //paso la lista de path
    form.setPath(sesArch.getPath());

    form.setArbol((ArchivoVO) sesArch.getPath().get(0));
}

From source file:com.flexive.shared.content.FxPropertyData.java

/**
 * Apply the multiplicity to XPath and children if its a group
 *//*from ww  w. j a  v  a  2 s  .com*/
@Override
protected void applyIndices() {
    List<XPathElement> elements = XPathElement.split(this.getXPathFull());
    final int lastIdx = elements.size() - 1;
    if (elements.get(lastIdx).getIndex() != this.getIndex()) {
        elements = Lists.newArrayList(elements);
        elements.set(lastIdx, this.getXPathElement());
        setXPathFull(XPathElement.toXPath(elements));
    }
}