Example usage for java.util TreeMap putAll

List of usage examples for java.util TreeMap putAll

Introduction

In this page you can find the example usage for java.util TreeMap putAll.

Prototype

public void putAll(Map<? extends K, ? extends V> map) 

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:org.apache.accumulo.shell.commands.ConfigCommand.java

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException,
        ClassNotFoundException, NamespaceNotFoundException {
    reader = shellState.getReader();/*from  w  w w  .  j a v  a2s  .c  om*/

    final String tableName = cl.getOptionValue(tableOpt.getOpt());
    if (tableName != null && !shellState.getConnector().tableOperations().exists(tableName)) {
        throw new TableNotFoundException(null, tableName, null);
    }
    final String namespace = cl.getOptionValue(namespaceOpt.getOpt());
    if (namespace != null && !shellState.getConnector().namespaceOperations().exists(namespace)) {
        throw new NamespaceNotFoundException(null, namespace, null);
    }
    if (cl.hasOption(deleteOpt.getOpt())) {
        // delete property from table
        String property = cl.getOptionValue(deleteOpt.getOpt());
        if (property.contains("=")) {
            throw new BadArgumentException("Invalid '=' operator in delete operation.", fullCommand,
                    fullCommand.indexOf('='));
        }
        if (tableName != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                Shell.log.warn("Invalid per-table property : " + property
                        + ", still removing from zookeeper if it's there.");
            }
            shellState.getConnector().tableOperations().removeProperty(tableName, property);
            Shell.log.debug("Successfully deleted table configuration option.");
        } else if (namespace != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                Shell.log.warn("Invalid per-table property : " + property
                        + ", still removing from zookeeper if it's there.");
            }
            shellState.getConnector().namespaceOperations().removeProperty(namespace, property);
            Shell.log.debug("Successfully deleted namespace configuration option.");
        } else {
            if (!Property.isValidZooPropertyKey(property)) {
                Shell.log.warn("Invalid per-table property : " + property
                        + ", still removing from zookeeper if it's there.");
            }
            shellState.getConnector().instanceOperations().removeProperty(property);
            Shell.log.debug("Successfully deleted system configuration option");
        }
    } else if (cl.hasOption(setOpt.getOpt())) {
        // set property on table
        String property = cl.getOptionValue(setOpt.getOpt()), value = null;
        if (!property.contains("=")) {
            throw new BadArgumentException("Missing '=' operator in set operation.", fullCommand,
                    fullCommand.indexOf(property));
        }
        final String pair[] = property.split("=", 2);
        property = pair[0];
        value = pair[1];

        if (tableName != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                throw new BadArgumentException("Invalid per-table property.", fullCommand,
                        fullCommand.indexOf(property));
            }
            if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
                new ColumnVisibility(value); // validate that it is a valid expression
            }
            shellState.getConnector().tableOperations().setProperty(tableName, property, value);
            Shell.log.debug("Successfully set table configuration option.");
        } else if (namespace != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                throw new BadArgumentException("Invalid per-table property.", fullCommand,
                        fullCommand.indexOf(property));
            }
            if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
                new ColumnVisibility(value); // validate that it is a valid expression
            }
            shellState.getConnector().namespaceOperations().setProperty(namespace, property, value);
            Shell.log.debug("Successfully set table configuration option.");
        } else {
            if (!Property.isValidZooPropertyKey(property)) {
                throw new BadArgumentException("Property cannot be modified in zookeeper", fullCommand,
                        fullCommand.indexOf(property));
            }
            shellState.getConnector().instanceOperations().setProperty(property, value);
            Shell.log.debug("Successfully set system configuration option");
        }
    } else {
        // display properties
        final TreeMap<String, String> systemConfig = new TreeMap<String, String>();
        systemConfig.putAll(shellState.getConnector().instanceOperations().getSystemConfiguration());

        final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
        final PrintFile printFile = outputFile == null ? null : new PrintFile(outputFile);

        final TreeMap<String, String> siteConfig = new TreeMap<String, String>();
        siteConfig.putAll(shellState.getConnector().instanceOperations().getSiteConfiguration());

        final TreeMap<String, String> defaults = new TreeMap<String, String>();
        for (Entry<String, String> defaultEntry : AccumuloConfiguration.getDefaultConfiguration()) {
            defaults.put(defaultEntry.getKey(), defaultEntry.getValue());
        }

        final TreeMap<String, String> namespaceConfig = new TreeMap<String, String>();
        if (tableName != null) {
            String n = Namespaces.getNamespaceName(shellState.getInstance(), Tables.getNamespaceId(
                    shellState.getInstance(), Tables.getTableId(shellState.getInstance(), tableName)));
            for (Entry<String, String> e : shellState.getConnector().namespaceOperations().getProperties(n)) {
                namespaceConfig.put(e.getKey(), e.getValue());
            }
        }

        Iterable<Entry<String, String>> acuconf = shellState.getConnector().instanceOperations()
                .getSystemConfiguration().entrySet();
        if (tableName != null) {
            acuconf = shellState.getConnector().tableOperations().getProperties(tableName);
        } else if (namespace != null) {
            acuconf = shellState.getConnector().namespaceOperations().getProperties(namespace);
        }
        final TreeMap<String, String> sortedConf = new TreeMap<String, String>();
        for (Entry<String, String> propEntry : acuconf) {
            sortedConf.put(propEntry.getKey(), propEntry.getValue());
        }

        for (Entry<String, String> propEntry : acuconf) {
            final String key = propEntry.getKey();
            // only show properties with similar names to that
            // specified, or all of them if none specified
            if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) {
                continue;
            }
            if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) {
                continue;
            }
            COL2 = Math.max(COL2, propEntry.getKey().length() + 3);
        }

        final ArrayList<String> output = new ArrayList<String>();
        printConfHeader(output);

        for (Entry<String, String> propEntry : sortedConf.entrySet()) {
            final String key = propEntry.getKey();

            // only show properties with similar names to that
            // specified, or all of them if none specified
            if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) {
                continue;
            }
            if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) {
                continue;
            }
            String siteVal = siteConfig.get(key);
            String sysVal = systemConfig.get(key);
            String curVal = propEntry.getValue();
            String dfault = defaults.get(key);
            String nspVal = namespaceConfig.get(key);
            boolean printed = false;

            if (dfault != null && key.toLowerCase().contains("password")) {
                siteVal = sysVal = dfault = curVal = curVal.replaceAll(".", "*");
            }
            if (sysVal != null) {
                if (defaults.containsKey(key) && !Property.getPropertyByKey(key).isExperimental()) {
                    printConfLine(output, "default", key, dfault);
                    printed = true;
                }
                if (!defaults.containsKey(key) || !defaults.get(key).equals(siteVal)) {
                    printConfLine(output, "site", printed ? "   @override" : key,
                            siteVal == null ? "" : siteVal);
                    printed = true;
                }
                if (!siteConfig.containsKey(key) || !siteVal.equals(sysVal)) {
                    printConfLine(output, "system", printed ? "   @override" : key, sysVal);
                    printed = true;
                }

            }
            if (nspVal != null) {
                if (!systemConfig.containsKey(key) || !sysVal.equals(nspVal)) {
                    printConfLine(output, "namespace", printed ? "   @override" : key, nspVal);
                    printed = true;
                }
            }

            // show per-table value only if it is different (overridden)
            if (tableName != null && !curVal.equals(nspVal)) {
                printConfLine(output, "table", printed ? "   @override" : key, curVal);
            } else if (namespace != null && !curVal.equals(sysVal)) {
                printConfLine(output, "namespace", printed ? "   @override" : key, curVal);
            }
        }
        printConfFooter(output);
        shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()), printFile);
        if (printFile != null) {
            printFile.close();
        }
    }
    return 0;
}

From source file:org.apache.accumulo.core.util.shell.commands.ConfigCommand.java

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException,
        ClassNotFoundException, NamespaceNotFoundException {
    reader = shellState.getReader();/*from   w w w  . j  a va2s. c om*/

    final String tableName = cl.getOptionValue(tableOpt.getOpt());
    if (tableName != null && !shellState.getConnector().tableOperations().exists(tableName)) {
        throw new TableNotFoundException(null, tableName, null);
    }
    final String namespace = cl.getOptionValue(namespaceOpt.getOpt());
    if (namespace != null && !shellState.getConnector().namespaceOperations().exists(namespace)) {
        throw new NamespaceNotFoundException(null, namespace, null);
    }
    if (cl.hasOption(deleteOpt.getOpt())) {
        // delete property from table
        String property = cl.getOptionValue(deleteOpt.getOpt());
        if (property.contains("=")) {
            throw new BadArgumentException("Invalid '=' operator in delete operation.", fullCommand,
                    fullCommand.indexOf('='));
        }
        if (tableName != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                Shell.log.warn("Invalid per-table property : " + property
                        + ", still removing from zookeeper if it's there.");
            }
            shellState.getConnector().tableOperations().removeProperty(tableName, property);
            Shell.log.debug("Successfully deleted table configuration option.");
        } else if (namespace != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                Shell.log.warn("Invalid per-table property : " + property
                        + ", still removing from zookeeper if it's there.");
            }
            shellState.getConnector().namespaceOperations().removeProperty(namespace, property);
            Shell.log.debug("Successfully deleted namespace configuration option.");
        } else {
            if (!Property.isValidZooPropertyKey(property)) {
                Shell.log.warn("Invalid per-table property : " + property
                        + ", still removing from zookeeper if it's there.");
            }
            shellState.getConnector().instanceOperations().removeProperty(property);
            Shell.log.debug("Successfully deleted system configuration option");
        }
    } else if (cl.hasOption(setOpt.getOpt())) {
        // set property on table
        String property = cl.getOptionValue(setOpt.getOpt()), value = null;
        if (!property.contains("=")) {
            throw new BadArgumentException("Missing '=' operator in set operation.", fullCommand,
                    fullCommand.indexOf(property));
        }
        final String pair[] = property.split("=", 2);
        property = pair[0];
        value = pair[1];

        if (tableName != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                throw new BadArgumentException("Invalid per-table property.", fullCommand,
                        fullCommand.indexOf(property));
            }
            if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
                new ColumnVisibility(value); // validate that it is a valid expression
            }
            shellState.getConnector().tableOperations().setProperty(tableName, property, value);
            Shell.log.debug("Successfully set table configuration option.");
        } else if (namespace != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                throw new BadArgumentException("Invalid per-table property.", fullCommand,
                        fullCommand.indexOf(property));
            }
            if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
                new ColumnVisibility(value); // validate that it is a valid expression
            }
            shellState.getConnector().namespaceOperations().setProperty(namespace, property, value);
            Shell.log.debug("Successfully set table configuration option.");
        } else {
            if (!Property.isValidZooPropertyKey(property)) {
                throw new BadArgumentException("Property cannot be modified in zookeeper", fullCommand,
                        fullCommand.indexOf(property));
            }
            shellState.getConnector().instanceOperations().setProperty(property, value);
            Shell.log.debug("Successfully set system configuration option");
        }
    } else {
        // display properties
        final TreeMap<String, String> systemConfig = new TreeMap<String, String>();
        systemConfig.putAll(shellState.getConnector().instanceOperations().getSystemConfiguration());

        final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
        final PrintFile printFile = outputFile == null ? null : new PrintFile(outputFile);

        final TreeMap<String, String> siteConfig = new TreeMap<String, String>();
        siteConfig.putAll(shellState.getConnector().instanceOperations().getSiteConfiguration());

        final TreeMap<String, String> defaults = new TreeMap<String, String>();
        for (Entry<String, String> defaultEntry : AccumuloConfiguration.getDefaultConfiguration()) {
            defaults.put(defaultEntry.getKey(), defaultEntry.getValue());
        }

        final TreeMap<String, String> namespaceConfig = new TreeMap<String, String>();
        if (tableName != null) {
            String n = Namespaces.getNamespaceName(shellState.getInstance(), Tables.getNamespaceId(
                    shellState.getInstance(), Tables.getTableId(shellState.getInstance(), tableName)));
            for (Entry<String, String> e : shellState.getConnector().namespaceOperations().getProperties(n)) {
                namespaceConfig.put(e.getKey(), e.getValue());
            }
        }

        Iterable<Entry<String, String>> acuconf = shellState.getConnector().instanceOperations()
                .getSystemConfiguration().entrySet();
        if (tableName != null) {
            acuconf = shellState.getConnector().tableOperations().getProperties(tableName);
        } else if (namespace != null) {
            acuconf = shellState.getConnector().namespaceOperations().getProperties(namespace);
        }
        final TreeMap<String, String> sortedConf = new TreeMap<String, String>();
        for (Entry<String, String> propEntry : acuconf) {
            sortedConf.put(propEntry.getKey(), propEntry.getValue());
        }

        for (Entry<String, String> propEntry : acuconf) {
            final String key = propEntry.getKey();
            // only show properties with similar names to that
            // specified, or all of them if none specified
            if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) {
                continue;
            }
            if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) {
                continue;
            }
            COL2 = Math.max(COL2, propEntry.getKey().length() + 3);
        }

        final ArrayList<String> output = new ArrayList<String>();
        printConfHeader(output);

        for (Entry<String, String> propEntry : sortedConf.entrySet()) {
            final String key = propEntry.getKey();

            // only show properties with similar names to that
            // specified, or all of them if none specified
            if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) {
                continue;
            }
            if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) {
                continue;
            }
            String siteVal = siteConfig.get(key);
            String sysVal = systemConfig.get(key);
            String curVal = propEntry.getValue();
            String dfault = defaults.get(key);
            String nspVal = namespaceConfig.get(key);
            boolean printed = false;

            if (dfault != null && key.toLowerCase().contains("password")) {
                siteVal = sysVal = dfault = curVal = curVal.replaceAll(".", "*");
            }
            if (sysVal != null) {
                if (defaults.containsKey(key)) {
                    printConfLine(output, "default", key, dfault);
                    printed = true;
                }
                if (!defaults.containsKey(key) || !defaults.get(key).equals(siteVal)) {
                    printConfLine(output, "site", printed ? "   @override" : key,
                            siteVal == null ? "" : siteVal);
                    printed = true;
                }
                if (!siteConfig.containsKey(key) || !siteVal.equals(sysVal)) {
                    printConfLine(output, "system", printed ? "   @override" : key,
                            sysVal == null ? "" : sysVal);
                    printed = true;
                }

            }
            if (nspVal != null) {
                if (!systemConfig.containsKey(key) || !sysVal.equals(nspVal)) {
                    printConfLine(output, "namespace", printed ? "   @override" : key,
                            nspVal == null ? "" : nspVal);
                    printed = true;
                }
            }

            // show per-table value only if it is different (overridden)
            if (tableName != null && !curVal.equals(nspVal)) {
                printConfLine(output, "table", printed ? "   @override" : key, curVal);
            } else if (namespace != null && !curVal.equals(sysVal)) {
                printConfLine(output, "namespace", printed ? "   @override" : key, curVal);
            }
        }
        printConfFooter(output);
        shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()), printFile);
        if (printFile != null) {
            printFile.close();
        }
    }
    return 0;
}

From source file:gda.scan.ConcurrentScanChild.java

TreeMap<Integer, Scannable[]> generateDevicesToMoveByLevel(TreeMap<Integer, Scannable[]> scannableLevels,
        Vector<Detector> detectors) {

    TreeMap<Integer, Scannable[]> devicesToMoveByLevel = new TreeMap<Integer, Scannable[]>();
    devicesToMoveByLevel.putAll(scannableLevels);

    for (Scannable detector : detectors) {

        Integer level = detector.getLevel();

        if (devicesToMoveByLevel.containsKey(level)) {
            Scannable[] levelArray = devicesToMoveByLevel.get(level);
            levelArray = (Scannable[]) ArrayUtils.add(levelArray, detector);
            devicesToMoveByLevel.put(level, levelArray);
        } else {/* w w  w. ja va  2  s. c o m*/
            Scannable[] levelArray = new Scannable[] { detector };
            devicesToMoveByLevel.put(level, levelArray);
        }
    }
    return devicesToMoveByLevel;
}

From source file:org.overlord.sramp.shell.ShellCommandFactory.java

/**
 * Gets the available commands, ordered by command {@link QName}.
 *///from w w w. jav a  2 s .  co m
private Map<QName, Class<? extends ShellCommand>> getCommands() {
    TreeMap<QName, Class<? extends ShellCommand>> treeMap = new TreeMap<QName, Class<? extends ShellCommand>>(
            new Comparator<QName>() {
                @Override
                public int compare(QName name1, QName name2) {
                    return name1.toString().compareTo(name2.toString());
                }
            });
    treeMap.putAll(this.registry);
    return treeMap;
}

From source file:com.opengamma.analytics.financial.provider.sensitivity.inflation.MultipleCurrencyInflationSensitivity.java

/**
 * Create a new multiple currency sensitivity by adding the sensitivity associated to a given currency.
 * If the currency is not yet present in the existing sensitivity a new map is created with the extra entry.
 * If the currency is already present, the associated sensitivities are added (in the sense of {@link InterestRateCurveSensitivity}) and a new map is created with all the other
 * existing entries and the entry with the currency and the sum sensitivity.
 * @param ccy The currency. Not null./*from w w  w  .  j  av a 2  s  .c o m*/
 * @param sensitivity The sensitivity associated to the currency. Not null.
 * @return The new multiple currency sensitivity.
 */
public MultipleCurrencyInflationSensitivity plus(final Currency ccy, final InflationSensitivity sensitivity) {
    ArgumentChecker.notNull(ccy, "Currency");
    ArgumentChecker.notNull(sensitivity, "Sensitivity");
    final TreeMap<Currency, InflationSensitivity> map = new TreeMap<>();
    if (_sensitivity.containsKey(ccy)) {
        map.put(ccy, sensitivity.plus(_sensitivity.get(ccy)));
        for (final Currency loopccy : _sensitivity.keySet()) {
            if (loopccy != ccy) {
                map.put(loopccy, _sensitivity.get(loopccy));
            }
        }
    } else {
        map.putAll(_sensitivity);
        map.put(ccy, sensitivity);
    }
    return new MultipleCurrencyInflationSensitivity(map);
}

From source file:com.opengamma.analytics.financial.forex.method.MultipleCurrencyInterestRateCurveSensitivity.java

/**
 * Create a new multiple currency sensitivity by adding the sensitivity associated to a given currency.
 * If the currency is not yet present in the existing sensitivity a new map is created with the extra entry.
 * If the currency is already present, the associated sensitivities are added (in the sense of {@link InterestRateCurveSensitivity}) and a new map is created with all the other
 * existing entries and the entry with the currency and the sum sensitivity.
 * @param ccy The currency. Not null.//from w  w w  . j  a va  2  s .c om
 * @param sensitivity The sensitivity associated to the currency. Not null.
 * @return The new multiple currency sensitivity.
 */
public MultipleCurrencyInterestRateCurveSensitivity plus(final Currency ccy,
        final InterestRateCurveSensitivity sensitivity) {
    ArgumentChecker.notNull(ccy, "Currency");
    ArgumentChecker.notNull(sensitivity, "Sensitivity");
    final TreeMap<Currency, InterestRateCurveSensitivity> map = new TreeMap<>();
    if (_sensitivity.containsKey(ccy)) {
        map.put(ccy, sensitivity.plus(_sensitivity.get(ccy)));
        for (final Currency loopccy : _sensitivity.keySet()) {
            if (loopccy != ccy) {
                map.put(loopccy, _sensitivity.get(loopccy));
            }
        }
    } else {
        map.putAll(_sensitivity);
        map.put(ccy, sensitivity);
    }
    return new MultipleCurrencyInterestRateCurveSensitivity(map);
}

From source file:model.plate.ANATestResult.java

public void diagnose2(double control) {
    //titer,positivity,r2,pattern
    final Comparator<DiagnosisConstant.ANA_Titer> titerComparator = new Comparator<DiagnosisConstant.ANA_Titer>() {
        @Override/*w  ww .java 2s. co  m*/
        public int compare(DiagnosisConstant.ANA_Titer t, DiagnosisConstant.ANA_Titer t1) {
            if (t.getId() < 0) {
                throw new RuntimeException("Titer: " + t.name());
            }
            if (t1.getId() < 0) {
                throw new RuntimeException("Titer: " + t.name());
            }
            if (t.getId() > 6) {
                throw new RuntimeException("Titer: " + t.name());
            }
            if (t1.getId() > 6) {
                throw new RuntimeException("Titer: " + t.name());
            }
            return t.getId() < t1.getId() ? -1 : t.getId() == t1.getId() ? 0 : 1;
        }
    };
    TreeMap<DiagnosisConstant.ANA_Titer, Double> decreasingSignals = new TreeMap<>(titerComparator);
    decreasingSignals.putAll(signals);
    SimpleRegression regression = new SimpleRegression();
    Iterator<DiagnosisConstant.ANA_Titer> it = decreasingSignals.keySet().iterator();
    DiagnosisConstant.ANA_Titer t;
    Double signal;
    while (it.hasNext()) {
        t = it.next();
        signal = decreasingSignals.get(t);
        if (signal == null)
            continue;
        //            posCtrl=signal>posCtrl?signal:posCtrl; ??1:40, 
        regression.addData((double) t.getId(), signal);
        if (signal > control) {// * PlateConstants.PositiveCutOffRatio
            titer = t;
        }
    }

    r2 = regression.getRSquare();
    if (r2 < PlateConstants.R2_TH) {
        warningMessage.add(WarningMessage.SampleLinearity.getId());
    }
    if (titer == null)
        titer = DiagnosisConstant.ANA_Titer.ANA_LESS_1_40;
    if (DiagnosisConstant.ANA_Titer.ANA_LESS_1_40.equals(titer) || titer.getId() < 2) {//1:40

        System.out.println();
        for (DiagnosisConstant.ANA_Titer t1 : decreasingSignals.keySet()) {
            System.out.println(
                    this.julien_barcode + " Sample vs Control (th=" + PlateConstants.PositiveCutOffRatio + ")");
            System.out.println(t1 + ": signal=" + decreasingSignals.get(t1) + "\tv.s.\tcontrol=" + control
                    + " (" + decreasingSignals.get(t1) / control + ")");
        }
        System.out.println();
        positivity = DiagnosisConstant.ANA_Result.NEGATIVE;
        warningMessage.add(WarningMessage.WeakPositive.getId());

    } else {
        positivity = DiagnosisConstant.ANA_Result.POSITIVE;
    }
}

From source file:model.plate.ANATestResult.java

public boolean initPosCtrl2(double negControl) {
    final Comparator<DiagnosisConstant.ANA_Titer> titerComparator = new Comparator<DiagnosisConstant.ANA_Titer>() {
        @Override//w ww .j a v  a2 s. co m
        public int compare(DiagnosisConstant.ANA_Titer t, DiagnosisConstant.ANA_Titer t1) {
            if (t.getId() < 0) {
                throw new RuntimeException("Titer: " + t.name());
            }
            if (t1.getId() < 0) {
                throw new RuntimeException("Titer: " + t.name());
            }
            if (t.getId() > 6) {
                throw new RuntimeException("Titer: " + t.name());
            }
            if (t1.getId() > 6) {
                throw new RuntimeException("Titer: " + t.name());
            }
            return t.getId() < t1.getId() ? -1 : t.getId() == t1.getId() ? 0 : 1;
        }
    };
    TreeMap<DiagnosisConstant.ANA_Titer, Double> decreasingSignals = new TreeMap<>(titerComparator);
    decreasingSignals.putAll(signals);
    SimpleRegression regression = new SimpleRegression();
    Iterator<DiagnosisConstant.ANA_Titer> it = decreasingSignals.keySet().iterator();
    DiagnosisConstant.ANA_Titer t;
    double signal, posCtrl = getFirstPlateSignal();

    while (it.hasNext()) {
        t = it.next();
        signal = decreasingSignals.get(t);
        //            posCtrl=signal>posCtrl?signal:posCtrl; ??1:40, 
        regression.addData((double) t.getId(), signal);
        if (signal > posCtrl * PlateConstants.PositiveCutOffRatio
                || signal > negControl * PlateConstants.NegativeCutOffRatio) {
            titer = t;

        }
    }
    if (titer.getId() >= DiagnosisConstant.ANA_Titer.ANA_1_320.getId()) {
        positivity = DiagnosisConstant.ANA_Result.POSITIVE;
        System.out.println("found titer for " + plateID + " : " + titer);
        System.out.println();
        System.out.println();
    }
    r2 = regression.getRSquare();
    if (r2 < PlateConstants.R2_TH) {
        warningMessage.add(WarningMessage.PositiveControlLinearity.getId());
    }
    if (titer == null || titer.getId() < DiagnosisConstant.ANA_Titer.ANA_1_320.getId()) {//1:40
        titer = DiagnosisConstant.ANA_Titer.ANA_LESS_1_40;
        System.out.println();
        for (DiagnosisConstant.ANA_Titer t1 : decreasingSignals.keySet()) {
            System.out.println(plateID + " Control Sample Compare");
            System.out.println(t1 + ": posCtrl=" + decreasingSignals.get(t1) + "\tv.s.\tnegCtrl=" + negControl
                    + " (" + decreasingSignals.get(t1) / negControl + ")");
        }
        System.out.println();
        positivity = DiagnosisConstant.ANA_Result.NEGATIVE;
        System.out.println("barcode " + this.julien_barcode);
        warningMessage.add(WarningMessage.PositiveNegativeControlComparison.getId());

    } else {
        positivity = DiagnosisConstant.ANA_Result.POSITIVE;
    }
    if (posCtrl < negControl * PlateConstants.CTRL_RATIO_TH) {
        this.warningMessage.add(WarningMessage.PosCtrlFailed.getId());
        return false;
    }
    return true;
}

From source file:com.opengamma.analytics.financial.provider.sensitivity.multicurve.MultipleCurrencyMulticurveSensitivity.java

/**
 * Create a new multiple currency sensitivity by adding the sensitivity associated to a given currency.
 * If the currency is not yet present in the existing sensitivity a new map is created with the extra entry.
 * If the currency is already present, the associated sensitivities are added (in the sense of {@link InterestRateCurveSensitivity}) and a new map is created with all the other
 * existing entries and the entry with the currency and the sum sensitivity.
 * @param ccy The currency. Not null./*w ww .ja va2 s.  c  om*/
 * @param sensitivity The sensitivity associated to the currency. Not null.
 * @return The new multiple currency sensitivity.
 */
public MultipleCurrencyMulticurveSensitivity plus(final Currency ccy, final MulticurveSensitivity sensitivity) {
    ArgumentChecker.notNull(ccy, "Currency");
    ArgumentChecker.notNull(sensitivity, "Sensitivity");
    final TreeMap<Currency, MulticurveSensitivity> map = new TreeMap<>();
    if (_sensitivity.containsKey(ccy)) {
        map.put(ccy, sensitivity.plus(_sensitivity.get(ccy)));
        for (final Currency loopccy : _sensitivity.keySet()) {
            if (loopccy != ccy) {
                map.put(loopccy, _sensitivity.get(loopccy));
            }
        }
    } else {
        map.putAll(_sensitivity);
        map.put(ccy, sensitivity);
    }
    return new MultipleCurrencyMulticurveSensitivity(map);
}

From source file:com.opengamma.analytics.financial.interestrate.market.description.MultipleCurrencyCurveSensitivityMarket.java

/**
 * Create a new multiple currency sensitivity by adding the sensitivity associated to a given currency. 
 * If the currency is not yet present in the existing sensitivity a new map is created with the extra entry.
 * If the currency is already present, the associated sensitivities are added (in the sense of {@link InterestRateCurveSensitivity}) and a new map is created with all the other
 * existing entries and the entry with the currency and the sum sensitivity.
 * @param ccy The currency. Not null.// ww  w.j  a v  a 2s  .  c  o m
 * @param sensitivity The sensitivity associated to the currency. Not null.
 * @return The new multiple currency sensitivity.
 */
public MultipleCurrencyCurveSensitivityMarket plus(final Currency ccy,
        final CurveSensitivityMarket sensitivity) {
    ArgumentChecker.notNull(ccy, "Currency");
    ArgumentChecker.notNull(sensitivity, "Sensitivity");
    final TreeMap<Currency, CurveSensitivityMarket> map = new TreeMap<Currency, CurveSensitivityMarket>();
    if (_sensitivity.containsKey(ccy)) {
        map.put(ccy, sensitivity.plus(_sensitivity.get(ccy)));
        for (final Currency loopccy : _sensitivity.keySet()) {
            if (loopccy != ccy) {
                map.put(loopccy, _sensitivity.get(loopccy));
            }
        }
    } else {
        map.putAll(_sensitivity);
        map.put(ccy, sensitivity);
    }
    return new MultipleCurrencyCurveSensitivityMarket(map);
}