Example usage for java.util Collections replaceAll

List of usage examples for java.util Collections replaceAll

Introduction

In this page you can find the example usage for java.util Collections replaceAll.

Prototype

public static <T> boolean replaceAll(List<T> list, T oldVal, T newVal) 

Source Link

Document

Replaces all occurrences of one specified value in a list with another.

Usage

From source file:com.autsia.bracer.BracerParser.java

/**
 * Evaluates once parsed math expression with "var" variable included
 *
 * @param variableValue User-specified <code>Double</code> value
 * @return <code>String</code> representation of the result
 * @throws <code>ParseException</code> if the input expression is not
 *                                     correct
 * @since 3.0//  ww w. j  a v  a 2  s .  com
 */
public String evaluate(double variableValue) throws ParseException {
    /* check if is there something to evaluate */
    if (stackRPN.empty()) {
        return "";
    }

    /* clean answer stack */
    stackAnswer.clear();

    /* get the clone of the RPN stack for further evaluating */
    @SuppressWarnings("unchecked")
    Stack<String> stackRPN = (Stack<String>) this.stackRPN.clone();

    /* enroll the variable value into expression */
    Collections.replaceAll(stackRPN, VARIABLE, Double.toString(variableValue));

    /* evaluating the RPN expression */
    while (!stackRPN.empty()) {
        String token = stackRPN.pop();
        if (isNumber(token)) {
            stackAnswer.push(token);
        } else if (isOperator(token)) {
            Complex a = complexFormat.parse(stackAnswer.pop());
            Complex b = complexFormat.parse(stackAnswer.pop());
            boolean aBoolean = a.getReal() == 1.0;
            boolean bBoolean = b.getReal() == 1.0;
            switch (token) {
            case "+":
                stackAnswer.push(complexFormat.format(b.add(a)));
                break;
            case "-":
                stackAnswer.push(complexFormat.format(b.subtract(a)));
                break;
            case "*":
                stackAnswer.push(complexFormat.format(b.multiply(a)));
                break;
            case "/":
                stackAnswer.push(complexFormat.format(b.divide(a)));
                break;
            case "|":
                stackAnswer.push(String.valueOf(aBoolean || bBoolean ? "1" : "0"));
                break;
            case "&":
                stackAnswer.push(String.valueOf(aBoolean && bBoolean ? "1" : "0"));
                break;
            }
        } else if (isFunction(token)) {
            Complex a = complexFormat.parse(stackAnswer.pop());
            boolean aBoolean = a.getReal() == 1.0;
            switch (token) {
            case "abs":
                stackAnswer.push(complexFormat.format(a.abs()));
                break;
            case "acos":
                stackAnswer.push(complexFormat.format(a.acos()));
                break;
            case "arg":
                stackAnswer.push(complexFormat.format(a.getArgument()));
                break;
            case "asin":
                stackAnswer.push(complexFormat.format(a.asin()));
                break;
            case "atan":
                stackAnswer.push(complexFormat.format(a.atan()));
                break;
            case "conj":
                stackAnswer.push(complexFormat.format(a.conjugate()));
                break;
            case "cos":
                stackAnswer.push(complexFormat.format(a.cos()));
                break;
            case "cosh":
                stackAnswer.push(complexFormat.format(a.cosh()));
                break;
            case "exp":
                stackAnswer.push(complexFormat.format(a.exp()));
                break;
            case "imag":
                stackAnswer.push(complexFormat.format(a.getImaginary()));
                break;
            case "log":
                stackAnswer.push(complexFormat.format(a.log()));
                break;
            case "neg":
                stackAnswer.push(complexFormat.format(a.negate()));
                break;
            case "real":
                stackAnswer.push(complexFormat.format(a.getReal()));
                break;
            case "sin":
                stackAnswer.push(complexFormat.format(a.sin()));
                break;
            case "sinh":
                stackAnswer.push(complexFormat.format(a.sinh()));
                break;
            case "sqrt":
                stackAnswer.push(complexFormat.format(a.sqrt()));
                break;
            case "tan":
                stackAnswer.push(complexFormat.format(a.tan()));
                break;
            case "tanh":
                stackAnswer.push(complexFormat.format(a.tanh()));
                break;
            case "pow":
                Complex b = complexFormat.parse(stackAnswer.pop());
                stackAnswer.push(complexFormat.format(b.pow(a)));
                break;
            case "not":
                stackAnswer.push(String.valueOf(!aBoolean ? "1" : "0"));
                break;
            }
        }
    }

    if (stackAnswer.size() > 1) {
        throw new ParseException("Some operator is missing", 0);
    }

    return stackAnswer.pop();
}

From source file:com.redhat.red.offliner.alist.PomArtifactListReader.java

/**
 * Applies mirrors from the settings.xml on the {@code repositories}. Read mirrors replace the original repositories
 * in provided repository list.// w w w.j a va 2  s.c o m
 *
 * @param settings settings.xml contents
 * @param repositories list of repositories read from pom
 */
private void processMirrors(final Settings settings, final List<Repository> repositories) {
    List<Mirror> mirrors = settings.getMirrors();
    MirrorSelector mirrorSelector = new DefaultMirrorSelector();
    DefaultRepositoryLayout layout = new DefaultRepositoryLayout();
    for (Repository repository : new ArrayList<>(repositories)) {
        ArtifactRepository artRepository = new MavenArtifactRepository();
        artRepository.setId(repository.getId());
        // TODO read the layout from the original repository
        artRepository.setLayout(layout);
        Mirror mirror = mirrorSelector.getMirror(artRepository, mirrors);
        if (mirror != null) {
            Repository mirrorRepository = new Repository();
            mirrorRepository.setId(mirror.getId());
            mirrorRepository.setLayout(mirror.getLayout());
            mirrorRepository.setReleases(repository.getReleases());
            mirrorRepository.setSnapshots(repository.getSnapshots());
            mirrorRepository.setUrl(mirror.getUrl());
            Collections.replaceAll(repositories, repository, mirrorRepository);
        }
    }
}

From source file:gov.nih.nci.caarray.magetab.sdrf.SdrfDocument.java

private void addRowToTable(List<AbstractSampleDataRelationshipNode> nodes, DelimitedWriter writer) {
    List<String> rowValues = new ArrayList<String>();
    for (AbstractSampleDataRelationshipNode node : nodes) {
        rowValues.add(node.getName());/*from  w ww . j  a va  2 s. co m*/
        switch (node.getNodeType()) {
        case SOURCE:
            addSourceValues(rowValues, (Source) node);
            break;
        case SAMPLE:
            addBiomaterialValues(rowValues, (AbstractBioMaterial) node, SdrfNodeType.SAMPLE);
            break;
        case EXTRACT:
            addBiomaterialValues(rowValues, (AbstractBioMaterial) node, SdrfNodeType.EXTRACT);
            break;
        case LABELED_EXTRACT:
            addLabeledExtractValues(rowValues, (LabeledExtract) node);
            break;
        default:
            break;
        }
    }
    Collections.replaceAll(rowValues, EMPTY_SYMBOL, EXPORT_EMPTY_SYMBOL);
    writeRow(rowValues, writer);
}

From source file:com.bmc.gibraltar.automation.dataprovider.RestDataProvider.java

/**
 * @param viewDefinitionName name of View Definition
 * @return list of names for all Components, present in viewDefinitionName
 *//*from  w w  w .  ja  v a 2  s  .  c  o m*/
public List<String> getAllComponentsForViewDefinition(String viewDefinitionName) {
    List<String> allComponents = JsonPath.from(getViewDefinition(getViewDefinitionId(viewDefinitionName)))
            .getList("componentDefinitions.type");
    for (String componentType : allComponents) {
        Collections.replaceAll(allComponents, componentType, Component.getNameByType(componentType));
    }
    LOG.info("\n--> Components for View '" + viewDefinitionName + "': " + allComponents);
    return allComponents;
}

From source file:org.libreplan.business.trees.TreeNodeOnList.java

@Override
public void replace(T previousChild, T newChild) {
    setParentIfRequired(newChild);//from   w w w  .ja  v a  2 s.com
    Collections.replaceAll(children, previousChild, newChild);
    onChildAdded(newChild);
    onChildRemoved(previousChild);
}

From source file:sernet.verinice.report.service.impl.dynamictable.GraphReportDataModel.java

/**
 * @return the results (the dataSet data)
 *//*from ww  w  .j a v  a2s  .  co m*/
public List<List<String>> getResults() {
    List<List<String>> tmpList = new LinkedList<List<String>>();

    List<String> keyList = new LinkedList<String>(resultMap.keySet());
    Collections.sort(keyList);

    List<String> keyListCleaned = cleanUpKeyList(keyList);

    for (String cleanKey : keyListCleaned) {
        List<String> list = resultMap.get(cleanKey).getPropertyList();
        Collections.replaceAll(list, null, "");
        tmpList.add(list);
    }
    this.table = new ArrayList<List<String>>();
    table.addAll(tmpList);

    Collections.sort(table, new Comparator<List<String>>() {

        @Override
        public int compare(List<String> row1, List<String> row2) {
            return compareRows(row1, row2);
        }

    });

    if (LOG.isDebugEnabled()) {
        LOG.debug("Result looks like:\t" + table.toString());
    }
    return table;
}