Example usage for java.util TreeMap keySet

List of usage examples for java.util TreeMap keySet

Introduction

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

Prototype

public Set<K> keySet() 

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:org.motechproject.mobile.omi.manager.SMSMessageFormatter.java

private String formatCommunityDefaulterMessage(TreeMap<String, TreeMap<String, List<String>>> defaulters) {

    if (defaulters == null || defaulters.isEmpty()) {
        return "\nNo defaulters found for this clinic";
    }/*  www  .j  a v a  2s .c o m*/

    String message = "";

    Set<NameValuePair> data = new HashSet<NameValuePair>();

    TreeSet<String> communities = new TreeSet<String>(defaulters.keySet());
    for (String c : communities) {
        TreeMap<String, List<String>> patientDefaulters = defaulters.get(c);
        message += "\n" + c;

        message += formatDefaulterMessage(patientDefaulters);
    }

    return message;
}

From source file:com.opengamma.analytics.financial.provider.calculator.discounting.CashFlowEquivalentCalculator.java

@Override
public AnnuityPaymentFixed visitGenericAnnuity(final Annuity<? extends Payment> annuity,
        final MulticurveProviderInterface multicurves) {
    ArgumentChecker.notNull(annuity, "Annuity");
    ArgumentChecker.notNull(multicurves, "Multicurves provider");
    final TreeMap<Double, Double> flow = new TreeMap<>();
    final Currency ccy = annuity.getCurrency();
    for (final Payment p : annuity.getPayments()) {
        final AnnuityPaymentFixed cfe = p.accept(this, multicurves);
        for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) {
            addcf(flow, cfe.getNthPayment(loopcf).getPaymentTime(), cfe.getNthPayment(loopcf).getAmount());
        }//from  www. j  av  a2  s  .  c  om
    }
    final PaymentFixed[] agregatedCfe = new PaymentFixed[flow.size()];
    int loopcf = 0;
    for (final double time : flow.keySet()) {
        agregatedCfe[loopcf++] = new PaymentFixed(ccy, time, flow.get(time));
    }
    return new AnnuityPaymentFixed(agregatedCfe);
}

From source file:com.itemanalysis.jmetrik.graph.nicc.NonparametricCurveAnalysis.java

/**
 * Called from done on EDT/*from  www .j a v a2s  .  co m*/
 *
 * @throws IllegalArgumentException
 */
private void publishAllSeries() throws IllegalArgumentException {
    double[] tcc = new double[gridPoints];
    double[] values;
    double[] points = uniformDistributionApproximation.getPoints();

    double tccMin = 0;
    double tccMax = 0;

    for (VariableAttributes v : categoryRegression.keySet()) {
        KernelRegressionCategories kCategories;
        XYSeries series;

        //add lines to this collection repeat for each item
        XYSeriesCollection xyCollection = new XYSeriesCollection();

        //increment TCC for focal group, also create expected value series
        series = new XYSeries("");
        kCategories = categoryRegression.get(v);
        tccMin += kCategories.getMinimumPossibleScore();
        tccMax += kCategories.getMaximumPossibleScore();
        values = kCategories.getExpectedValues();
        for (int i = 0; i < tcc.length; i++) {
            tcc[i] += values[i];
            series.add(points[i], values[i]);
        }

        XYSeries catSeries;
        //add line for every category
        TreeMap<Object, KernelRegression> kregMap = kCategories.getRegressionMap();
        for (Object o : kregMap.keySet()) {
            catSeries = new XYSeries(o.toString() + "(" + kCategories.getScoreValue(o) + ")");
            values = kregMap.get(o).value();
            for (int i = 0; i < points.length; i++)
                catSeries.add(points[i], values[i]);
            xyCollection.addSeries(catSeries);
        }

        if (allCategories) {
            nonparametricPanel.updateDatasetFor(v.getName().toString(), 0, 1, xyCollection);
        } else {
            nonparametricPanel.updateDatasetFor(v.getName().toString(), kCategories.getMinimumPossibleScore(),
                    kCategories.getMaximumPossibleScore(), xyCollection);
        }

    } //end loop over items

    //add series for test characteristic curve
    XYSeriesCollection xyCollection = new XYSeriesCollection();
    XYSeries tccSeries1 = new XYSeries("TCC");
    for (int i = 0; i < tcc.length; i++) {
        tccSeries1.add(points[i], tcc[i]);
    }
    xyCollection.addSeries(tccSeries1);

    nonparametricPanel.updateDatasetFor("tcc", tccMin, tccMax, xyCollection);

}

From source file:com.opengamma.analytics.financial.interestrate.CashFlowEquivalentCalculator.java

@Override
public AnnuityPaymentFixed visitBondFixedSecurity(final BondFixedSecurity bond, final YieldCurveBundle curves) {
    Validate.notNull(curves);//  w  w  w .  j av  a  2s .c om
    Validate.notNull(bond);
    Currency ccy = bond.getCurrency();
    TreeMap<Double, Double> flow = new TreeMap<Double, Double>();
    AnnuityPaymentFixed cfeNom = visit(bond.getNominal(), curves);
    AnnuityPaymentFixed cfeCpn = visit(bond.getCoupon(), curves);
    for (final PaymentFixed p : cfeNom.getPayments()) {
        flow.put(p.getPaymentTime(), p.getAmount());
    }
    for (final PaymentFixed p : cfeCpn.getPayments()) {
        addcf(flow, p.getPaymentTime(), p.getAmount());
    }
    PaymentFixed[] agregatedCfe = new PaymentFixed[flow.size()];
    int loopcf = 0;
    for (double time : flow.keySet()) {
        agregatedCfe[loopcf++] = new PaymentFixed(ccy, time, flow.get(time), cfeCpn.getDiscountCurve());
    }
    return new AnnuityPaymentFixed(agregatedCfe);

}

From source file:org.mda.bcb.tcgagsdata.create.ProcessFile.java

protected void writeGeneListFile(TreeMap<String, Integer> theGeneEqList) throws IOException {
    File outputDir = getOutputDir();
    File outputFile = new File(outputDir, "gene_list.tsv");
    try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(outputFile.getAbsolutePath()),
            Charset.availableCharsets().get("ISO-8859-1"))) {
        boolean first = true;
        for (String gene : theGeneEqList.keySet()) {
            if (false == first) {
                bw.write("\t");
            } else {
                first = false;//from www .  j a  v a  2s .  co m
            }
            bw.write(gene);
        }
        bw.newLine();
    }
}

From source file:org.mda.bcb.tcgagsdata.create.ProcessFile.java

protected void writeCombinedFiles(TreeMap<String, Integer> theGeneEqList) throws IOException {
    File outputDir = getOutputDir();
    TcgaGSData.printWithFlag("mGeneEqMap.size()=" + theGeneEqList.size());
    TcgaGSData.printWithFlag("mSampleList.size()=" + mSampleList.size());
    // gene lines
    HashMap<String, ArrayList<String>> hashprefixToGeneList = new HashMap<>();
    for (String geneEq : theGeneEqList.keySet()) {
        String md5prefix = DigestUtils.md5Hex(geneEq).substring(0, 2);
        ArrayList<String> genesublist = hashprefixToGeneList.get(md5prefix);
        if (null == genesublist) {
            genesublist = new ArrayList<>();
        }/*from  w w w .  ja  va 2s  . c  om*/
        genesublist.add(geneEq);
        hashprefixToGeneList.put(md5prefix, genesublist);
    }
    for (String md5prefix : hashprefixToGeneList.keySet()) {
        ArrayList<String> genesublist = hashprefixToGeneList.get(md5prefix);
        writeToMD5File(md5prefix, theGeneEqList, genesublist);
    }
}

From source file:com.opengamma.analytics.financial.interestrate.CashFlowEquivalentCalculator.java

@Override
public AnnuityPaymentFixed visitSwap(final Swap<?, ?> swap, final YieldCurveBundle curves) {
    Validate.notNull(curves);//from w  w  w . j  a  v  a  2 s.c  om
    Validate.notNull(swap);
    Currency ccy = swap.getFirstLeg().getCurrency();
    Validate.isTrue(ccy.equals(swap.getSecondLeg().getCurrency()),
            "Cash flow equivalent available only for single currency swaps.");
    TreeMap<Double, Double> flow = new TreeMap<Double, Double>();
    AnnuityPaymentFixed cfeLeg1 = visit(swap.getFirstLeg(), curves);
    AnnuityPaymentFixed cfeLeg2 = visit(swap.getSecondLeg(), curves);
    for (final PaymentFixed p : cfeLeg1.getPayments()) {
        flow.put(p.getPaymentTime(), p.getAmount());
    }
    for (final PaymentFixed p : cfeLeg2.getPayments()) {
        addcf(flow, p.getPaymentTime(), p.getAmount());
    }
    PaymentFixed[] agregatedCfe = new PaymentFixed[flow.size()];
    int loopcf = 0;
    for (double time : flow.keySet()) {
        agregatedCfe[loopcf++] = new PaymentFixed(ccy, time, flow.get(time), cfeLeg1.getDiscountCurve());
    }
    return new AnnuityPaymentFixed(agregatedCfe);
}

From source file:com.pindroid.client.PinboardApi.java

/**
 * Performs an api call to Pinboard's http based api methods.
 * /*  w ww .  ja  v  a 2 s.  c o  m*/
 * @param url URL of the api method to call.
 * @param params Extra parameters included in the api call, as specified by different methods.
 * @param account The account being synced.
 * @param context The current application context.
 * @return A String containing the response from the server.
 * @throws IOException If a server error was encountered.
 * @throws AuthenticationException If an authentication error was encountered.
 * @throws TooManyRequestsException 
 * @throws PinboardException 
 */
private static InputStream PinboardApiCall(String url, TreeMap<String, String> params, Account account,
        Context context)
        throws IOException, AuthenticationException, TooManyRequestsException, PinboardException {

    final AccountManager am = AccountManager.get(context);

    if (account == null)
        throw new AuthenticationException();

    final String username = account.name;
    String authtoken = "00000000000000000000"; // need to provide a sane default value, since a token that is too short causes a 500 error instead of 401

    try {
        String tempAuthtoken = am.blockingGetAuthToken(account, Constants.AUTHTOKEN_TYPE, true);
        if (tempAuthtoken != null)
            authtoken = tempAuthtoken;
    } catch (Exception e) {
        e.printStackTrace();
        throw new AuthenticationException("Error getting auth token");
    }

    params.put("auth_token", username + ":" + authtoken);

    final Uri.Builder builder = new Uri.Builder();
    builder.scheme(SCHEME);
    builder.authority(PINBOARD_AUTHORITY);
    builder.appendEncodedPath(url);
    for (String key : params.keySet()) {
        builder.appendQueryParameter(key, params.get(key));
    }

    String apiCallUrl = builder.build().toString();

    Log.d("apiCallUrl", apiCallUrl);
    final HttpGet post = new HttpGet(apiCallUrl);

    post.setHeader("User-Agent", "PinDroid");
    post.setHeader("Accept-Encoding", "gzip");

    final DefaultHttpClient client = (DefaultHttpClient) HttpClientFactory.getThreadSafeClient();

    final HttpResponse resp = client.execute(post);

    final int statusCode = resp.getStatusLine().getStatusCode();

    if (statusCode == HttpStatus.SC_OK) {

        final HttpEntity entity = resp.getEntity();

        InputStream instream = entity.getContent();

        final Header encoding = entity.getContentEncoding();

        if (encoding != null && encoding.getValue().equalsIgnoreCase("gzip")) {
            instream = new GZIPInputStream(instream);
        }

        return instream;
    } else if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
        am.invalidateAuthToken(Constants.AUTHTOKEN_TYPE, authtoken);

        try {
            authtoken = am.blockingGetAuthToken(account, Constants.AUTHTOKEN_TYPE, true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AuthenticationException("Invalid auth token");
        }

        throw new AuthenticationException();
    } else if (statusCode == Constants.HTTP_STATUS_TOO_MANY_REQUESTS) {
        throw new TooManyRequestsException(300);
    } else if (statusCode == HttpStatus.SC_REQUEST_URI_TOO_LONG) {
        throw new PinboardException();
    } else {
        throw new IOException();
    }
}

From source file:io.mapzone.arena.refine.RefinePanel.java

@Override
public void createContents(final Composite parent) {
    parent.setLayout(FormLayoutFactory.defaults().create());

    final TreeMap<String, RefineFunction> functions = Maps.newTreeMap();
    for (Class<RefineFunction> cl : availableFunctions) {
        try {/* ww w . j a  va  2  s .c o  m*/
            RefineFunction function = cl.newInstance();
            function.init(map);
            functions.put(function.title(), function);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    Combo combo = new Combo(parent, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN);
    @SuppressWarnings("hiding")
    final Composite functionContainer = tk().createComposite(parent, SWT.NONE);

    final List<String> content = Lists.newArrayList(functions.keySet());
    combo.setItems(content.stream().toArray(String[]::new));
    combo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String functionTitle = content.get(combo.getSelectionIndex());
            RefineFunction function = functions.get(functionTitle);

            UIUtils.disposeChildren(functionContainer);

            // create panel
            IPanelSection section = tk().createPanelSection(functionContainer, function.description(),
                    SWT.BORDER);
            section.setExpanded(true);
            section.getBody().setLayout(FormLayoutFactory.defaults().create());
            function.createContents(tk(), section.getBody());
            FormDataFactory.on(section.getBody()).fill();

            functionContainer.layout();
        }
    });

    // layout
    final Label selectLabel = tk().createLabel(parent, i18n.get("selectFunction"), SWT.NONE);
    FormDataFactory.on(selectLabel).top(1).left(1);
    FormDataFactory.on(combo).top(selectLabel, 3).left(1).noBottom();
    FormDataFactory.on(functionContainer).fill().top(combo, 5);
}

From source file:com.opengamma.analytics.financial.provider.calculator.discounting.CashFlowEquivalentCalculator.java

@Override
public AnnuityPaymentFixed visitBondFixedSecurity(final BondFixedSecurity bond,
        final MulticurveProviderInterface multicurves) {
    ArgumentChecker.notNull(bond, "Bond");
    ArgumentChecker.notNull(multicurves, "Multicurves provider");
    final Currency ccy = bond.getCurrency();
    final TreeMap<Double, Double> flow = new TreeMap<>();
    final AnnuityPaymentFixed cfeNom = bond.getNominal().accept(this, multicurves);
    final AnnuityPaymentFixed cfeCpn = bond.getCoupon().accept(this, multicurves);
    for (final PaymentFixed p : cfeNom.getPayments()) {
        flow.put(p.getPaymentTime(), p.getAmount());
    }//from   www.j a  va 2  s .  c om
    for (final PaymentFixed p : cfeCpn.getPayments()) {
        addcf(flow, p.getPaymentTime(), p.getAmount());
    }
    final PaymentFixed[] agregatedCfe = new PaymentFixed[flow.size()];
    int loopcf = 0;
    for (final double time : flow.keySet()) {
        agregatedCfe[loopcf++] = new PaymentFixed(ccy, time, flow.get(time));
    }
    return new AnnuityPaymentFixed(agregatedCfe);

}