Example usage for java.util TreeMap put

List of usage examples for java.util TreeMap put

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:com.aliyun.odps.mapred.bridge.streaming.StreamJob.java

/**
 * Prints out the jobconf properties on stdout
 * when verbose is specified./*from  w w w .j  a v a2  s . co  m*/
 */
protected void listJobConfProperties() {
    msg("==== JobConf properties:");
    TreeMap<String, String> sorted = new TreeMap<String, String>();
    for (final Map.Entry<String, String> en : jobConf_) {
        sorted.put(en.getKey(), en.getValue());
    }
    for (final Map.Entry<String, String> en : sorted.entrySet()) {
        msg(en.getKey() + "=" + en.getValue());
    }
    msg("====");
}

From source file:com.nubits.nubot.trading.wrappers.PeatioWrapper.java

public ApiResponse enterOrder(String type, CurrencyPair pair, double amount, double rate) {
    ApiResponse apiResponse = new ApiResponse();
    String order_id = "";
    String url = apiBaseUrl;//from  w  ww .j  a v a2s.co m
    String method = API_TRADE;
    boolean isGet = false;

    TreeMap<String, String> query_args = new TreeMap<>();

    query_args.put("side", type.toLowerCase());
    query_args.put("volume", Double.toString(amount));
    query_args.put("price", Double.toString(rate));
    query_args.put("market", pair.toString());
    query_args.put("canonical_verb", "POST");
    query_args.put("canonical_uri", method);

    ApiResponse response = getQuery(url, method, query_args, true, isGet);
    if (response.isPositive()) {
        JSONObject httpAnswerJson = (JSONObject) response.getResponseObject();
        if (httpAnswerJson.containsKey("id")) {
            order_id = httpAnswerJson.get("id").toString();
            apiResponse.setResponseObject(order_id);
        }
    } else {
        apiResponse = response;
    }

    return apiResponse;
}

From source file:agendavital.modelo.data.Noticia.java

public static TreeMap<LocalDate, ArrayList<Noticia>> buscar(String _parametro)
        throws ConexionBDIncorrecta, SQLException {
    final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
    ArrayList<String> _tags = UtilidadesBusqueda.separarPalabras(_parametro);
    TreeMap<LocalDate, ArrayList<Noticia>> busqueda = null;
    try (Connection conexion = ConfigBD.conectar()) {
        busqueda = new TreeMap<>();
        for (String _tag : _tags) {
            String tag = ConfigBD.String2Sql(_tag, true);
            String buscar = String.format("SELECT id_Noticia, fecha from noticias "
                    + "WHERE id_noticia IN (SELECT id_noticia from momentos_noticias_etiquetas "
                    + "WHERE id_etiqueta IN (SELECT id_etiqueta from etiquetas WHERE nombre LIKE %s)) "
                    + "OR titulo LIKE %s " + "OR cuerpo LIKE %s " + "OR categoria LIKE %s "
                    + "OR fecha LIKE %s; ", tag, tag, tag, tag, tag);
            ResultSet rs = conexion.createStatement().executeQuery(buscar);
            while (rs.next()) {
                LocalDate date = LocalDate.parse(rs.getString("fecha"), dateFormatter);
                Noticia insertarNoticia = new Noticia(rs.getInt("id_noticia"));
                if (busqueda.containsKey(date)) {
                    boolean encontrado = false;
                    for (int i = 0; i < busqueda.get(date).size() && !encontrado; i++)
                        if (busqueda.get(date).get(i).getId() == insertarNoticia.getId())
                            encontrado = true;
                    if (!encontrado)
                        busqueda.get(date).add(insertarNoticia);
                } else {
                    busqueda.put(date, new ArrayList<>());
                    busqueda.get(date).add(insertarNoticia);
                }//ww  w  .jav a 2  s . c  om
            }

        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    Iterator it = busqueda.keySet().iterator();
    return busqueda;
}

From source file:com.nubits.nubot.trading.wrappers.PeatioWrapper.java

@Override
public ApiResponse getOrderDetail(String orderID) {
    ApiResponse apiResponse = new ApiResponse();
    Order order = null;/*from  w ww  . ja v  a2 s.c  o  m*/
    String url = apiBaseUrl;
    String method = API_ORDER;
    boolean isGet = true;

    TreeMap<String, String> query_args = new TreeMap<>();
    query_args.put("canonical_verb", "GET");
    query_args.put("canonical_uri", "/api/v2/order");
    query_args.put("id", orderID);

    ApiResponse response = getQuery(url, method, query_args, true, isGet);
    if (response.isPositive()) {
        JSONObject httpAnswerJson = (JSONObject) response.getResponseObject();
        if (httpAnswerJson.containsKey("error")) {
            JSONObject error = (JSONObject) httpAnswerJson.get("error");
            int code = ~(Integer) error.get("code");
            String msg = error.get("message").toString();
            apiResponse.setError(new ApiError(code, msg));
            return apiResponse;
        }
        /*Sample result
         * {"id":7,"side":"sell","price":"3100.0","avg_price":"3101.2","state":"wait","market":"btccny","created_at":"2014-04-18T02:02:33Z","volume":"100.0","remaining_volume":"89.8","executed_volume":"10.2","trades":[{"id":2,"price":"3100.0","volume":"10.2","market":"btccny","created_at":"2014-04-18T02:04:49Z","side":"sell"}]}
         */

        apiResponse.setResponseObject(parseOrder(httpAnswerJson));
    } else {
        apiResponse = response;
    }

    return apiResponse;
}

From source file:de.burlov.ultracipher.core.Database.java

/**
 * Laedt Daten aus dem JSON String/*from ww  w .j  a  v a2 s  .  c  o  m*/
 *
 * @param json
 * @throws Exception
 */
public void importJson(String json) throws Exception {
    JSONTokener t = new JSONTokener(json);
    TreeMap<String, DataEntry> newEntries = new TreeMap<String, DataEntry>();
    JSONArray rootArray = (JSONArray) t.nextValue();
    /*
     * Primaere Daten laden
     */
    JSONArray array = rootArray.getJSONArray(0);
    for (int i = 0; i < array.length(); i++) {
        JSONObject o = array.getJSONObject(i);
        DataEntry e = new DataEntry(o.getString(ID));
        e.setLastChanged(o.getLong(CHANGED));
        e.setName(o.getString(NAME));
        e.setTags(o.getString(TAGS));
        e.setText(o.getString(TEXT));

        newEntries.put(e.getId(), e);
    }
    /*
     * Ids der geloeschten Elemente laden
     */
    array = rootArray.getJSONArray(1);
    TreeMap<String, Long> deletedMap = new TreeMap<String, Long>();
    for (int i = 0; i < array.length(); i++) {
        JSONArray arr = array.getJSONArray(i);
        String id = arr.getString(0);
        Long time = arr.getLong(1);
        deletedMap.put(id, time);
    }
    this.entries = newEntries;
    this.deletedEntries = deletedMap;
}

From source file:com.nubits.nubot.trading.wrappers.PeatioWrapper.java

@Override
public ApiResponse cancelOrder(String orderID, CurrencyPair pair) {
    ApiResponse apiResponse = new ApiResponse();
    String url = apiBaseUrl;//  w  ww .jav  a 2 s.  c o m
    String method = API_CANCEL_ORDER;
    boolean isGet = false;

    TreeMap<String, String> query_args = new TreeMap<>();

    query_args.put("id", orderID);
    query_args.put("canonical_verb", "POST");
    query_args.put("canonical_uri", method);

    ApiResponse response = getQuery(url, method, query_args, true, isGet);
    if (response.isPositive()) {
        JSONObject httpAnswerJson = (JSONObject) response.getResponseObject();
        if (httpAnswerJson.containsKey("error")) {
            JSONObject error = (JSONObject) httpAnswerJson.get("error");
            int code = (Integer) error.get("code");
            String msg = error.get("message").toString();
            apiResponse.setError(new ApiError(code, msg));
            return apiResponse;
        }
        /*Sample result
         * Cancel order is an asynchronous operation. A success response only means your cancel
         * request has been accepted, it doesn't mean the order has been cancelled.
         * You should always use /api/v2/order or websocket api to get order's latest state.
         */

        apiResponse.setResponseObject(true);
    } else {
        apiResponse = response;
    }

    return apiResponse;
}

From source file:com.nubits.nubot.trading.wrappers.BitSparkWrapper.java

@Override
public ApiResponse clearOrders(CurrencyPair pair) {
    ApiResponse apiResponse = new ApiResponse();
    String url = API_BASE_URL;
    String method = API_CLEAR_ORDERS;
    boolean isGet = false;

    TreeMap<String, String> query_args = new TreeMap<>();

    query_args.put("canonical_verb", "POST");
    query_args.put("canonical_uri", method);

    ApiResponse response = getQuery(url, method, query_args, true, isGet);
    if (response.isPositive()) {
        apiResponse.setResponseObject(true);
    } else {//from  w  ww .jav a  2s . c  o m
        apiResponse = response;
    }

    return apiResponse;
}

From source file:edu.jhu.cvrg.servlet.TSDBBacking.java

public String retrieveSingleLead(String subjectId, String metric, long unixTimeStart, long unixTimeEnd,
        String downsampleRate) throws OpenTSDBException {
    //pause();//w w w .java  2 s .com
    HashMap<String, String> tags = new HashMap<String, String>();
    if (metric.startsWith("ecg")) {
        tags.put("subjectId", subjectId);
    }
    JSONObject dataForView;
    String finalDataString = "";
    //Interval Annotation result is {"tsuid":"00005900000200036A00000400036B","description":"Test Annotation 20160405 - 
    //text for additional interval notation","notes":"","endTime":1420070467,"startTime":1420070465}
    try {
        dataForView = TimeSeriesRetriever.getDownsampledTimeSeries(OPENTSDB_URL, unixTimeStart, unixTimeEnd,
                metric, downsampleRate, tags, OPENTSDB_BOO);

        double sampRate = 1;
        double aduGain = 1;
        JSONObject rawData = new JSONObject();
        String leadMetric = "";
        JSONObject leadTags = new JSONObject();

        //System.out.println(dataForView);
        rawData = dataForView.getJSONObject("dps");
        leadMetric = dataForView.getString("metric");
        leadTags = dataForView.getJSONObject("tags");

        DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");

        //          if (leadMetric != null){
        //             //System.out.println(leadMetric + ": lead Metric");
        //         }

        if (!leadTags.isNull("format")) {
            String value = leadTags.getString("format");
            switch (value.toLowerCase()) {
            case "phillips103":
                sampRate = 2; // 1000 / 500 (original sample rate)
                aduGain = 2;
                break;
            case "phillips104":
                sampRate = 2;
                aduGain = 2;
                break;
            case "schiller":
                sampRate = 2;
                aduGain = 2;
                break;
            case "hl7aecg":
                sampRate = 1; // 1000 / 1000 (original sample rate)
                aduGain = 0.025;
                break;
            case "gemusexml":
                sampRate = 4; // 1000 / 250 (original sample rate)
                aduGain = 2.05;
                break;
            default:
                break;
            }
        }

        if (rawData != null) {
            TreeMap<String, String> map = new TreeMap<String, String>();
            Iterator iter = rawData.keys();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                Long onggg = (long) (Long.parseLong(key) * sampRate);

                // need to scale time appropriately for ecg leads

                Date time = new Date(onggg);
                String reportDate = df.format(time);
                //String shortKey = key.substring(5);
                Long numValue = (long) (Long.parseLong(rawData.getString(key)) * aduGain);

                String value = String.valueOf(numValue);
                map.put(reportDate, value);
            }
            int counterR = 0;
            for (Map.Entry<String, String> entry : map.entrySet()) {
                counterR++;
                String k = entry.getKey();
                String v = entry.getValue();
                finalDataString += "[" + k + "," + v + "],";
            }
            System.out.println(":" + counterR + ": " + finalDataString);
            //System.out.println(":" + counterR + ": " + finalDataString);
            if (finalDataString.charAt(finalDataString.length() - 1) == ',') {
                finalDataString = finalDataString.substring(0, finalDataString.length() - 1);
            }
        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return finalDataString;

}

From source file:edu.utexas.cs.tactex.utilityestimation.UtilityEstimatorDefaultForConsumption.java

/**
 * @param defaultSpec //from  ww w.ja va 2  s. co  m
 * @param customer2RelevantTariffCharges 
 */
@Override
public TreeMap<Double, TariffSpecification> estimateUtilities(List<TariffSpecification> consideredTariffActions,
        HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions,
        List<TariffSpecification> competingTariffs,
        HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> customer2RelevantTariffCharges,
        HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> customer2ShiftedEnergy,
        HashMap<CustomerInfo, ArrayRealVector> customer2NonShiftedEnergy,
        MarketPredictionManager marketPredictionManager, CostCurvesPredictor costCurvesPredictor,
        int currentTimeslot, Broker me) {

    // this is just for printing predicted vs. actual customer subscriptions
    predictions.clear();

    TreeMap<Double, TariffSpecification> utility2spec = new TreeMap<Double, TariffSpecification>();

    // all possible tariff actions: {suggestedSpeces} U {no-op}
    // a value of null means no-op
    for (TariffSpecification spec : consideredTariffActions) {
        double utility = predictUtility(spec, customer2RelevantTariffCharges, tariffSubscriptions,
                competingTariffs, currentTimeslot, customer2ShiftedEnergy, customer2NonShiftedEnergy,
                marketPredictionManager, costCurvesPredictor);
        utility2spec.put(utility + publicationFee(spec), spec);
    }

    return utility2spec;
}

From source file:hr.restart.util.chart.ChartXYZ.java

/**
 * TO BE REMOVED/*from  w w w.java  2 s  .  c  o  m*/
 * @return
 */
final public SortedMap initMapTest() {
    TreeMap map = new TreeMap();

    //to be removed or changed
    Pair objectZ = new Pair("Klijent 1", "01");
    map.put((Object) objectZ, new Double(1.2));
    objectZ = new Pair("Klijent 1", "02");
    map.put((Object) objectZ, new Double(0.2));
    objectZ = new Pair("Klijent 1", "03");
    map.put((Object) objectZ, new Double(0.2));
    objectZ = new Pair("Klijent 1", "04");
    map.put((Object) objectZ, new Double(1.2));
    objectZ = new Pair("Klijent 1", "05");
    map.put((Object) objectZ, new Double(1.5));
    objectZ = new Pair("Klijent 1", "06");
    map.put((Object) objectZ, new Double(1.2));
    objectZ = new Pair("Klijent 1", "07");
    map.put((Object) objectZ, new Double(1.2));
    objectZ = new Pair("Klijent 1", "08");
    map.put((Object) objectZ, new Double(1.42));
    objectZ = new Pair("Klijent 1", "09");
    map.put((Object) objectZ, new Double(0.2));
    objectZ = new Pair("Klijent 1", "10");
    map.put((Object) objectZ, new Double(0.7));
    objectZ = new Pair("Klijent 1", "11");
    map.put((Object) objectZ, new Double(1.2));
    objectZ = new Pair("Klijent 1", "12");
    map.put((Object) objectZ, new Double(1.5));

    //       objectZ = new Pair("Klijent 2","01");              
    //       map.put((Object)objectZ,new Double(0.2));       
    //       objectZ = new Pair("Klijent 2","02");              
    //       map.put((Object)objectZ,new Double(2.2));                        
    objectZ = new Pair("Klijent 2", "03");
    map.put((Object) objectZ, new Double(2.2));
    objectZ = new Pair("Klijent 2", "04");
    map.put((Object) objectZ, new Double(3.2));
    objectZ = new Pair("Klijent 2", "05");
    map.put((Object) objectZ, new Double(2.5));
    objectZ = new Pair("Klijent 2", "06");
    map.put((Object) objectZ, new Double(1.7));
    objectZ = new Pair("Klijent 2", "07");
    map.put((Object) objectZ, new Double(1.9));
    objectZ = new Pair("Klijent 2", "08");
    map.put((Object) objectZ, new Double(1.42));
    objectZ = new Pair("Klijent 2", "09");
    map.put((Object) objectZ, new Double(0.9));
    objectZ = new Pair("Klijent 2", "10");
    map.put((Object) objectZ, new Double(0.7));
    objectZ = new Pair("Klijent 2", "11");
    map.put((Object) objectZ, new Double(1.2));
    objectZ = new Pair("Klijent 2", "12");
    map.put((Object) objectZ, new Double(1.5));

    return map;
}