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:org.spirit.spring.BotListRubyController.java

protected ModelAndView getModelAndView(Object rubyResult, String defaultView) {
    String viewName = null;//from ww w. ja  va2 s .c o m
    if (Map.class.isAssignableFrom(rubyResult.getClass())) {
        Map map = (Map) rubyResult;
        // look for an embedded view name in the model
        viewName = (String) map.get("viewName");

    } else if (BotListBaseForm.class.isAssignableFrom(rubyResult.getClass())) {

        // Or use the Base Class Form to get the view name.
        BotListBaseForm form = (BotListBaseForm) rubyResult;
        if (form.getViewName() != null) {
            viewName = form.getViewName();
        }
    }
    if (viewName == null) {
        viewName = defaultView;
    }
    TreeMap result = new TreeMap();
    result.put(getCommandName(), rubyResult);

    // keep record of processing time
    scriptEndTime = System.currentTimeMillis();
    long diff = scriptEndTime - scriptStartTime;
    double diffS = diff / 1000.0d;
    result.put(PROCESSING_TIME, "" + diffS);
    return new ModelAndView(viewName, result);
}

From source file:com.edgenius.wiki.render.handler.TOCHandler.java

@SuppressWarnings("unchecked")
public List<RenderPiece> handle(RenderContext renderContext, Map<String, String> values) {
    TreeMap<Integer, HeadingModel> tree = new TreeMap<Integer, HeadingModel>(new CompareToComparator());

    List<HeadingModel> list = (List<HeadingModel>) renderContext.getGlobalParam(TOCMacro.class.getName());
    //hi, here cannot simple return even list is null because the TOCMacro place holder need remove in following code.
    if (list != null) {
        for (HeadingModel headingModel : list) {
            //OK, find heading model, then put it into sorted list
            tree.put(headingModel.getOrder(), headingModel);
        }//from w w  w . j  a v  a 2  s . c  o  m
        //in buildTOCHTML() method, {toc} will replace to "no head exist" string
    }

    Collection<HeadingModel> headTree = tree.values();
    //replace all TOCMacro(GlobalFilter) object in renderPiece by TOC HTML string.
    int deep = 3;
    String align = null;
    boolean ordered = true;
    Map<String, String> map = new HashMap<String, String>();
    if (values != null) {
        //get back deep, order and align value.
        String deepStr = values.get(NameConstants.DEEP);
        String orderStr = values.get(NameConstants.ORDERED);
        align = values.get(NameConstants.ALIGN);
        map.put(NameConstants.DEEP, deepStr);
        map.put(NameConstants.ALIGN, align);
        map.put(NameConstants.ORDERED, orderStr);

        deep = NumberUtils.toInt(deepStr, 3);
        if (orderStr == null) {
            //default value is true! show ordered list
            ordered = true;
        } else {
            ordered = BooleanUtils.toBoolean(values.get(NameConstants.ORDERED));
        }
    }
    String wajax = "";
    if (map.size() > 0)
        wajax = RichTagUtil.buildWajaxAttributeString(this.getClass().getName(), map);

    List<RenderPiece> pieces = new ArrayList<RenderPiece>();
    pieces.addAll(buildTOCHTML(renderContext, headTree, deep, align, !ordered, wajax));
    return pieces;
}

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

@Test
public void testValidateChargers2() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("customer.model.liftTruck.instances", "c5");
    map.put("customer.model.liftTruck.c5.nChargers", "5");
    config = new MapConfiguration(map);
    Configurator configurator = new Configurator();
    configurator.setConfiguration(config);
    Collection<?> instances = configurator.configureInstances(LiftTruck.class);
    Map<String, LiftTruck> trucks = mapNames(instances);
    LiftTruck c5 = trucks.get("c5");
    c5.ensureShifts();//from  ww w. ja v  a 2 s.  c o m
    assertEquals("5 chargers c5", 5, c5.getNChargers());
    c5.validateChargers();
    assertEquals("5 after c5 validation", 5, c5.getNChargers());
}

From source file:com.mycompany.task1.Chart.java

private void group(TreeMap<Double, Integer> groupedMap, Map<Double, Integer> mapa) {
    // przejdz przez pogrupowana mape i zwieksz wartosc jezeli wartosc klucza z niepogrupowanej mapy 
    //znajduje sie w przedziale
    for (Map.Entry<Double, Integer> entry : mapa.entrySet()) {
        double prevRange = 0;
        for (Map.Entry<Double, Integer> entryGroupedMap : groupedMap.entrySet()) {

            if (prevRange <= entry.getKey() && entry.getKey() <= entryGroupedMap.getKey()) {

                int numberOfAccurence = entryGroupedMap.getValue();
                numberOfAccurence++;//w w  w.ja v a  2  s.  c  o m
                groupedMap.put(entryGroupedMap.getKey(), numberOfAccurence);
            }

            prevRange = entryGroupedMap.getKey();
        }

    }

}

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

@Test
public void testValidateChargers3() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("customer.model.liftTruck.instances", "c5");
    map.put("customer.model.liftTruck.c5.nChargers", "5");
    map.put("customer.model.liftTruck.c5.shiftData", "block,1,2,3,4,5, shift,6,8,8, shift,14,8,6");
    config = new MapConfiguration(map);
    Configurator configurator = new Configurator();
    configurator.setConfiguration(config);
    Collection<?> instances = configurator.configureInstances(LiftTruck.class);
    Map<String, LiftTruck> trucks = mapNames(instances);
    LiftTruck c5 = trucks.get("c5");
    c5.ensureShifts();/*from w  w w.  j a v  a 2s  . c o  m*/
    assertEquals("5 chargers c5", 5, c5.getNChargers());
    c5.validateChargers();
    assertEquals("5 after c5 validation", 5, c5.getNChargers());
}

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

@Test
public void rolloverShiftConfig() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("customer.model.liftTruck.instances", "test");
    map.put("customer.model.liftTruck.test.shiftData",
            "block,1,2,3,4,5, shift,8,10,8, shift,18,10,6," + "block,6, shift,8,10,3, block,7, shift,18,10,2");
    config = new MapConfiguration(map);
    Configurator configurator = new Configurator();
    configurator.setConfiguration(config);
    Collection<?> instances = configurator.configureInstances(LiftTruck.class);
    assertEquals("one instance", 1, instances.size());
    Map<String, LiftTruck> trucks = mapNames(instances);

    LiftTruck test = trucks.get("test");
    assertNotNull("found uut", test);
    test.ensureShifts();//  w w  w  .  j a  v  a  2  s.com
    Shift[] schedule = test.getShiftSchedule();
    assertNotNull("schedule exists", schedule);
    assertEquals("correct size", 168, schedule.length);
    Shift s4 = schedule[0];
    assertEquals("Mon 0:00 start", 18, s4.getStart());
    assertEquals("Mon 0:00 dur", 10, s4.getDuration());
    assertEquals("Mon 0:00 trucks", 2, s4.getTrucks());
    assertEquals("Mon 3:00", s4, schedule[3]);
    assertNull("idle Mon 4:00", schedule[4]);
}

From source file:edu.isi.wings.portal.controllers.PlanController.java

private ArrayList<TreeMap<String, Binding>> getParameterBindings(ArrayList<Template> cts) {
    ArrayList<TreeMap<String, Binding>> bindings_b = new ArrayList<TreeMap<String, Binding>>();
    for (Template bt : cts) {
        TreeMap<String, Binding> binding_b = new TreeMap<String, Binding>();
        for (Variable v : bt.getInputVariables()) {
            if (v.isParameterVariable() && v.getBinding() != null) {
                binding_b.put(v.getName(), v.getBinding());
            }//from  ww  w.  j a v  a  2 s.  c  om
        }
        bindings_b.add(binding_b);
    }

    // Expanding collections into multiple configurations
    // FIXME: Cannot handle parameter collections right now
    ArrayList<TreeMap<String, Binding>> bindings = new ArrayList<TreeMap<String, Binding>>();
    HashMap<String, Boolean> bstrs = new HashMap<String, Boolean>();
    while (!bindings_b.isEmpty()) {
        boolean hasSets = false;
        TreeMap<String, Binding> binding_b = bindings_b.remove(0);
        TreeMap<String, Binding> binding = new TreeMap<String, Binding>();

        for (String v : binding_b.keySet()) {
            Binding b = binding_b.get(v);
            if (b.isSet() && b.size() > 1) {
                for (WingsSet cb : b) {
                    TreeMap<String, Binding> binding_x = new TreeMap<String, Binding>();
                    for (String v1 : binding_b.keySet()) {
                        Binding b1 = binding_b.get(v1);
                        binding_x.put(v1, b1);
                    }
                    binding_x.put(v, (Binding) cb);
                    bindings_b.add(binding_x);
                }
                hasSets = true;
            } else if (b.isSet() && b.size() == 1) {
                Binding tmpb = (Binding) b.get(0);
                while (tmpb.isSet() && tmpb.size() == 1) {
                    tmpb = (Binding) tmpb.get(0);
                }
                ValueBinding vb = (ValueBinding) tmpb;
                binding.put(v, new ValueBinding(vb.getValue(), vb.getDatatype()));
            } else if (!b.isSet()) {
                ValueBinding vb = (ValueBinding) b;
                binding.put(v, new ValueBinding(vb.getValue(), vb.getDatatype()));
            }
        }
        if (!hasSets) {
            String bstr = "";
            for (String v : binding.keySet()) {
                bstr += binding.get(v).toString() + ",";
            }
            if (!bstrs.containsKey(bstr)) {
                bstrs.put(bstr, true);
                bindings.add(binding);
            }
        }
    }

    return bindings;
}

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

@Test
public void testValidateBatteries() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("customer.model.liftTruck.instances", "short,long");
    map.put("customer.model.liftTruck.short.shiftData",
            "block,1,2,3,4,5, shift,6,8,8, shift,14,8,6, shift,22,8,4,"
                    + "block,6,7, shift,6,8,3, shift,14,8,2");
    map.put("customer.model.liftTruck.short.nBatteries", "6");
    map.put("customer.model.liftTruck.long.batteryCapacity", "24.0");
    map.put("customer.model.liftTruck.long.shiftData",
            "block,1,2,3,4,5, shift,6,8,5, shift,14,8,3, shift,22,8,7,"
                    + "block,6,7, shift,6,8,3, shift,14,8,2");
    map.put("customer.model.liftTruck.long.nBatteries", "10");
    config = new MapConfiguration(map);
    Configurator configurator = new Configurator();
    configurator.setConfiguration(config);
    Collection<?> instances = configurator.configureInstances(LiftTruck.class);
    assertEquals("two instances", 2, instances.size());
    Map<String, LiftTruck> trucks = mapNames(instances);

    LiftTruck shortTruck = trucks.get("short");
    assertEquals("short before validation", 6, shortTruck.getNBatteries());
    shortTruck.validateBatteries();//from   w  ww . j  a  va  2  s  .  com
    assertEquals("short after validation", 14, shortTruck.getNBatteries());

    LiftTruck longTruck = trucks.get("long");
    assertEquals("long before validation", 10, longTruck.getNBatteries());
    longTruck.validateBatteries();
    assertEquals("long after validation", 16, longTruck.getNBatteries());
}

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

@Test
public void testValidateChargers1() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("customer.model.liftTruck.instances", "truck_kw, charge_kw, ncharge");
    map.put("customer.model.liftTruck.truck_kw.truckKW", "10.0");
    map.put("customer.model.liftTruck.charge_kw.maxChargeKW", "2.0");
    map.put("customer.model.liftTruck.ncharge.nChargers", "3");
    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 tkw = trucks.get("truck_kw");
    tkw.ensureShifts();/*from   ww  w  .  j a  v  a2 s . c o m*/
    assertEquals("8 chargers tkw", 8, tkw.getNChargers());
    tkw.validateChargers();
    assertEquals("10 after tkw validation", 10, tkw.getNChargers());

    LiftTruck ckw = trucks.get("charge_kw");
    ckw.ensureShifts();
    assertEquals("8 chargers", 8, ckw.getNChargers());
    ckw.validateChargers();
    assertEquals("12 after validation", 12, ckw.getNChargers());

    LiftTruck nc = trucks.get("ncharge");
    nc.ensureShifts();
    assertEquals("3 chargers", 3, nc.getNChargers());
    nc.validateChargers();
    assertEquals("4 after validation", 4, nc.getNChargers());
}

From source file:com.wattzap.view.graphs.DistributionGraph.java

public void updateValues(int scale, boolean keepZeroes) {
    da.setBucketSize(scale);/*w  ww. java2  s.  co  m*/
    da.setKeepZeroes(keepZeroes);

    long totalTime = 0;
    TreeMap<Integer, Long> data = new TreeMap<Integer, Long>();
    for (int i = 0; i < telemetry.length; i++) {
        Telemetry last = null;
        for (Telemetry t : telemetry[i]) {

            if (last == null) {
                // first time through
                last = t;
            } else {
                int key = da.getKey(t);
                if (key != -1) {
                    if (data.containsKey(key)) {
                        // add time to current key
                        long time = data.get(key);
                        data.put(key, time + (t.getTime() - last.getTime()));
                    } else {
                        data.put(key, t.getTime() - last.getTime());
                    }
                    totalTime += t.getTime() - last.getTime();

                }
                last = t;
            }
        } // for
    } // for

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Entry<Integer, Long> entry : data.entrySet()) {
        int key = entry.getKey();
        double p = ((double) entry.getValue() * 100 / totalTime);
        if (p > 0.5) {
            dataset.addValue(p, "", da.getValueLabel(key));
        }

    } // for

    plot.setDataset(dataset);
    chartPanel.revalidate();
}