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.jsonstore.database.DatabaseSchema.java

public Map<String, Object> mapObject(JSONObject obj, JSONObject additional_search_fields) throws Throwable {
    Set<String> keys = this.nodes.keySet();
    JSONObject normalizedObj;//from   w  w w.j ava  2  s .co  m
    TreeMap<String, Object> result = new TreeMap<String, Object>();

    // Iterate over all the nodes in this schema and map the given
    // object.

    normalizedObj = normalizeObject(obj);

    for (String key : keys) {
        Object value = locateChildInObject(normalizedObj, key);

        if (value != null) {
            result.put(key, value);
        }

        if (additional_search_fields != null) {
            value = locateChildInObject(additional_search_fields, key);

            if (value != null) {
                result.put(key, value);
            }
        }
    }

    return result;
}

From source file:com.sfs.whichdoctor.dao.CreditDAOImpl.java

/**
 * Load groups./*from   w  ww .jav  a  2  s  . com*/
 *
 * @param guid the guid
 *
 * @return the array list< group bean>
 */
private ArrayList<GroupBean> loadGroups(final int guid) {

    // Create new SearchBean of type Credit and default values
    SearchResultsBean results = new SearchResultsBean();
    SearchBean groupSearch = this.getSearchDAO().initiate("group", null);
    groupSearch.setLimit(0);

    GroupBean searchCriteria = (GroupBean) groupSearch.getSearchCriteria();
    searchCriteria.setObjectType("Credits");
    ItemBean item = new ItemBean();
    item.setObject2GUID(guid);
    TreeMap<String, ItemBean> items = new TreeMap<String, ItemBean>();
    items.put("Credit", item);
    searchCriteria.setItems(items);

    groupSearch.setSearchCriteria(searchCriteria);

    try {
        BuilderBean loadGroup = new BuilderBean();
        loadGroup.setParameter("ITEMS", true);
        loadGroup.setParameter("REFERENCEID", String.valueOf(guid));
        results = this.getSearchDAO().search(groupSearch, loadGroup);
    } catch (Exception e) {
        dataLogger.error("Error loading groups for credit: " + e.getMessage());
    }

    ArrayList<GroupBean> groups = new ArrayList<GroupBean>();
    for (Object group : results.getSearchResults()) {
        groups.add((GroupBean) group);
    }

    return groups;
}

From source file:com.heliosapm.tsdblite.handlers.json.SplitTraceInputHandler.java

public String toHostObjectNameName(final ObjectName on) {
    final StringBuilder b = new StringBuilder("meta.");
    TreeMap<String, String> tgs = new TreeMap<String, String>(on.getKeyPropertyList());
    final String metricName = on.getDomain();
    String h = tgs.remove("host");
    String a = tgs.remove("app");
    final String host = h; //==null ? "*" : h;
    final String app = a == null ? "ANYAPP" : a;
    final int segIndex = metricName.indexOf('.');
    final String seg = segIndex == -1 ? metricName : metricName.substring(0, segIndex);
    if (host != null) {
        b.append(host).append(".").append(seg).append(":");
    }/* w  ww  .j av  a 2s.  c o  m*/
    if (app != null) {
        tgs.put("app", app);
        //         b.append(app).append(".").append(seg).append(":");
    }

    //      if(segIndex!=-1) {
    //         tgs.put("app", metricName.substring(segIndex+1));
    //      }
    for (Map.Entry<String, String> entry : tgs.entrySet()) {
        b.append(entry.getKey()).append("=").append(entry.getValue()).append(",");
    }
    b.deleteCharAt(b.length() - 1);
    return b.toString();
}

From source file:ch.algotrader.service.algo.VWAPOrderService.java

VWAPOrderStateVO createAlgoOrderState(final VWAPOrder algoOrder, final Date dateTime)
        throws OrderValidationException {

    Validate.notNull(algoOrder, "vwapOrder missing");

    Security security = algoOrder.getSecurity();
    SecurityFamily family = security.getSecurityFamily();
    Exchange exchange = family.getExchange();

    HistoricalDataService historicalDataService = this.applicationContext.getBean(HistoricalDataService.class);

    List<Bar> bars = historicalDataService.getHistoricalBars(security.getId(), //
            DateUtils.truncate(new Date(), Calendar.DATE), //
            algoOrder.getLookbackPeriod(), //
            TimePeriod.DAY, //
            algoOrder.getBucketSize(), //
            MarketDataEventType.TRADES, //
            Collections.emptyMap());

    TreeMap<LocalTime, Long> buckets = new TreeMap<>();
    Set<LocalDate> tradingDays = new HashSet<>();
    for (Bar bar : bars) {
        int vol = bar.getVol();
        LocalTime time = DateTimeLegacy.toLocalTime(bar.getDateTime());
        tradingDays.add(DateTimeLegacy.toLocalDate(bar.getDateTime()));
        if (buckets.containsKey(time)) {
            buckets.put(time, buckets.get(time) + vol);
        } else {/*ww  w . ja va 2  s .c o m*/
            buckets.put(time, (long) vol);
        }
    }

    // verify start and end time
    if (algoOrder.getStartTime() == null) {
        if (this.calendarService.isOpen(exchange.getId())) {
            algoOrder.setStartTime(dateTime);
        } else {
            Date nextOpenTime = this.calendarService.getNextOpenTime(exchange.getId());
            algoOrder.setStartTime(nextOpenTime);
        }
    }

    Date closeTime = this.calendarService.getNextCloseTime(exchange.getId());
    if (algoOrder.getEndTime() == null) {
        algoOrder.setEndTime(closeTime);
    }

    if (algoOrder.getStartTime().compareTo(dateTime) < 0) {
        throw new OrderValidationException("startTime needs to be in the future " + algoOrder);
    } else if (algoOrder.getEndTime().compareTo(dateTime) <= 0) {
        throw new OrderValidationException("endTime needs to be in the future " + algoOrder);
    } else if (algoOrder.getEndTime().compareTo(closeTime) > 0) {
        throw new OrderValidationException("endTime needs to be before next market closeTime for " + algoOrder);
    } else if (algoOrder.getEndTime().compareTo(algoOrder.getStartTime()) <= 0) {
        throw new OrderValidationException("endTime needs to be after startTime for " + algoOrder);
    }

    int historicalVolume = 0;
    LocalTime startTime = DateTimeLegacy.toLocalTime(algoOrder.getStartTime());
    LocalTime endTime = DateTimeLegacy.toLocalTime(algoOrder.getEndTime());
    LocalTime firstBucketStart = buckets.floorKey(startTime);
    LocalTime lastBucketStart = buckets.floorKey(endTime);

    SortedMap<LocalTime, Long> subBuckets = buckets.subMap(firstBucketStart, true, lastBucketStart, true);
    for (Map.Entry<LocalTime, Long> bucket : subBuckets.entrySet()) {

        long vol = bucket.getValue() / tradingDays.size();
        bucket.setValue(vol);

        if (bucket.getKey().equals(firstBucketStart)) {
            LocalTime firstBucketEnd = firstBucketStart.plus(algoOrder.getBucketSize().getValue(),
                    ChronoUnit.MILLIS);
            double fraction = (double) ChronoUnit.MILLIS.between(startTime, firstBucketEnd)
                    / algoOrder.getBucketSize().getValue();
            historicalVolume += vol * fraction;
        } else if (bucket.getKey().equals(lastBucketStart)) {
            double fraction = (double) ChronoUnit.MILLIS.between(lastBucketStart, endTime)
                    / algoOrder.getBucketSize().getValue();
            historicalVolume += vol * fraction;
        } else {
            historicalVolume += vol;
        }
    }

    double participation = algoOrder.getQuantity() / (double) historicalVolume;

    if (participation > MAX_PARTICIPATION) {
        throw new OrderValidationException("participation rate " + twoDigitFormat.format(participation * 100.0)
                + "% is above 50% of historical market volume for " + algoOrder);
    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.debug("participation of {} is {}%", algoOrder.getDescription(),
                twoDigitFormat.format(participation * 100.0));
    }

    return new VWAPOrderStateVO(participation, buckets);
}

From source file:org.powertac.customer.model.LiftTruckTest.java

@Test
public void BogusShiftConfig() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("customer.model.liftTruck.instances", "test1, test2, test3");
    // no block
    map.put("customer.model.liftTruck.test1.shiftData", "shift,8,10,8");
    // no shift//from   ww  w .  j  ava 2  s. c om
    map.put("customer.model.liftTruck.test3.shiftData", "block,1,2,3,4,5");
    // missing shift info
    map.put("customer.model.liftTruck.test3.shiftData", "block,1,2,3,4,5, shift,6,8");
    config = new MapConfiguration(map);
    Configurator configurator = new Configurator();
    configurator.setConfiguration(config);
    Collection<?> instances = configurator.configureInstances(LiftTruck.class);
    assertEquals("three instances", 3, instances.size());
    Map<String, LiftTruck> trucks = mapNames(instances);

    LiftTruck test1 = trucks.get("test1");
    assertNotNull("found test1", test1);
    Shift[] schedule = test1.getShiftSchedule();
    for (Shift shift : schedule) {
        if (null != shift)
            fail("test1 non-null entry");
    }

    LiftTruck test2 = trucks.get("test2");
    assertNotNull("found test2", test2);
    schedule = test2.getShiftSchedule();
    for (Shift shift : schedule) {
        if (null != shift)
            fail("test1 non-null entry");
    }

    LiftTruck test3 = trucks.get("test3");
    assertNotNull("found test3", test3);
    schedule = test3.getShiftSchedule();
    for (Shift shift : schedule) {
        if (null != shift)
            fail("test1 non-null entry");
    }
}

From source file:com.sfs.whichdoctor.dao.SupervisorDAOImpl.java

/**
 * Ordered supervisors.//w ww . ja v  a  2s  .  c o m
 *
 * @param supervisors the supervisors
 *
 * @return the collection< supervisor bean>
 */
private Collection<SupervisorBean> orderedSupervisors(final Collection<SupervisorBean> supervisors) {
    final Collection<SupervisorBean> ordered = new ArrayList<SupervisorBean>();

    TreeMap<String, SupervisorBean> orderMap = new TreeMap<String, SupervisorBean>();

    if (supervisors != null) {
        for (SupervisorBean supervisor : supervisors) {
            final String key = supervisor.getOrderId() + "_" + supervisor.getGUID();
            orderMap.put(key, supervisor);
        }
    }

    int orderId = 1;

    for (String key : orderMap.keySet()) {
        SupervisorBean supervisor = orderMap.get(key);

        supervisor.setOrderId(orderId);
        ordered.add(supervisor);

        orderId++;
    }
    return ordered;
}

From source file:com.sfs.whichdoctor.dao.ReceiptDAOImpl.java

/**
 * Load groups.//from w w w  .  ja  v a  2  s  . c  om
 *
 * @param guid the guid
 *
 * @return the array list< group bean>
 */
private ArrayList<GroupBean> loadGroups(final int guid) {

    // Create new SearchBean of type Receipt and default values
    SearchResultsBean results = new SearchResultsBean();
    SearchBean groupSearch = this.getSearchDAO().initiate("group", null);
    groupSearch.setLimit(0);

    GroupBean searchCriteria = (GroupBean) groupSearch.getSearchCriteria();
    searchCriteria.setObjectType("Receipts");
    ItemBean item = new ItemBean();
    item.setObject2GUID(guid);
    TreeMap<String, ItemBean> items = new TreeMap<String, ItemBean>();
    items.put("Receipt", item);
    searchCriteria.setItems(items);

    groupSearch.setSearchCriteria(searchCriteria);
    try {
        BuilderBean loadGroup = new BuilderBean();
        loadGroup.setParameter("ITEMS", true);
        loadGroup.setParameter("REFERENCEID", String.valueOf(guid));
        results = this.getSearchDAO().search(groupSearch, loadGroup);
    } catch (Exception e) {
        dataLogger.error("Error loading groups for receipt: " + e.getMessage());
    }

    ArrayList<GroupBean> groups = new ArrayList<GroupBean>();
    for (Object group : results.getSearchResults()) {
        groups.add((GroupBean) group);
    }

    return groups;
}

From source file:com.sfs.whichdoctor.analysis.GroupAnalysisDAOImpl.java

/**
 * Builds the order.//from   w  ww .j  av  a2 s. c o m
 *
 * @param referenceObjects the reference objects
 * @param groupClass the group class
 *
 * @return the tree map< string, integer>
 */
private TreeMap<String, Integer> buildOrder(final TreeMap<Integer, Object> referenceObjects,
        final String groupClass) {

    if (referenceObjects == null) {
        throw new NullPointerException("The reference objects map cannot be null");
    }
    if (groupClass == null) {
        throw new NullPointerException("The group class string cannot be null");
    }

    dataLogger.debug("Building order for " + groupClass + ", with a size of: " + referenceObjects.size());

    TreeMap<String, Integer> orderMap = new TreeMap<String, Integer>();

    for (Integer referenceGUID : referenceObjects.keySet()) {
        Object reference = referenceObjects.get(referenceGUID);
        String orderKey = GroupAnalysisBean.getOrderKey(reference, groupClass);
        orderMap.put(orderKey, referenceGUID);
    }

    return orderMap;
}

From source file:it.cnr.icar.eric.client.ui.thin.QueryBean.java

private Map<String, ParameterBean> parseParameters(String s) {
    TreeMap<String, ParameterBean> p = new TreeMap<String, ParameterBean>();
    s = s.trim();//  w  ww .  ja va 2s . c  om
    int index = s.lastIndexOf(';');
    if (index != -1) {
        s = s.substring(0, index);
    }
    String[] tokens = s.split("[ ,'()=%;]");
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].charAt(0) == '$') {
            // Assume trailing numbers indicate a multi value. Trim
            // them off and just create a single parameter.
            String[] arrayToken = tokens[i].split("[0-9]$");
            tokens[i] = arrayToken[0];
            p.put(tokens[i], new ParameterBean(tokens[i]));
        }
    }
    return p;
}