List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:com.liangc.hq.base.utils.MonitorUtils.java
/** * Method findServiceTypes./*from ww w . j a va2s. c o m*/ * * Given a List of services associated with an application or server, * filter through them for the service types so we can link to showing * selections by type. The returned List has the ServiceTypeValue as * elements. * * This should eventually get pushed into the bizapp * * @param services * @return List */ public static List<ServiceTypeValue> findServiceTypes(List services, Boolean internal) { TreeMap<String, ServiceTypeValue> serviceTypeSet = new TreeMap<String, ServiceTypeValue>(); for (Iterator i = services.iterator(); i.hasNext();) { AppdefResourceValue svcCandidate = (AppdefResourceValue) i.next(); final AppdefEntityID aeid = svcCandidate.getEntityId(); if (aeid.isService() || aeid.isGroup()) { AppdefResourceValue service = (AppdefResourceValue) svcCandidate; if (service != null && service.getAppdefResourceTypeValue() != null) { // if we don't have a group that is a compat group of services, then this // better throw a ClassCastException ServiceTypeValue svcType = (ServiceTypeValue) service.getAppdefResourceTypeValue(); if (internal == null) { // if we're not discriminating between internal and deployed, we'll just // return them all serviceTypeSet.put(svcType.getName(), svcType); } else if (internal != null && new Boolean(svcType.getIsInternal()).equals(internal)) { serviceTypeSet.put(svcType.getName(), svcType); } } } else { throw new IllegalStateException("Did not get a valid service: " + svcCandidate); } } return new ArrayList(serviceTypeSet.values()); }
From source file:com.opengamma.analytics.math.statistics.descriptive.ModeCalculator.java
/** * @param x The array of data, not null or empty * @return The arithmetic mean/* w w w . ja va 2s .c o m*/ */ @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); Validate.isTrue(x.length > 0, "x cannot be empty"); if (x.length == 1) { return x[0]; } final double[] x1 = Arrays.copyOf(x, x.length); Arrays.sort(x1); final TreeMap<Integer, Double> counts = new TreeMap<Integer, Double>(); int count = 1; for (int i = 1; i < x1.length; i++) { if (Math.abs(x1[i] - x1[i - 1]) < EPS) { count++; } else { counts.put(count, x1[i - 1]); count = 1; } } if (counts.lastKey() == 1) { throw new MathException("Could not find mode for array; no repeated values"); } return counts.lastEntry().getValue(); }
From source file:module.entities.NameFinder.DB.java
public static TreeMap<Integer, String> getDemocracitArticles(int consId) throws SQLException { TreeMap<Integer, String> all = new TreeMap<>(); String sql = "SELECT id, body " + "FROM articles " + "WHERE consultation_id = " + consId + " AND id NOT IN (SELECT enhancedentities.article_id FROM enhancedentities);"; Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(sql); // PreparedStatement preparedStatement = connection.prepareStatement(sql); // preparedStatement.setInt(1, consId); // System.out.println(sql); // ResultSet rs = preparedStatement.executeQuery(); Document doc;//from ww w . j av a2 s . co m while (rs.next()) { int articleID = rs.getInt("id"); String article_text = rs.getString("body"); doc = Jsoup.parseBodyFragment(article_text); all.put(articleID, doc.text()); } return all; }
From source file:com.headstrong.npi.raas.Utils.java
public static TreeMap<String, String> stringArrayToTreeMap(String[] stringArray) { TreeMap<String, String> treeMap = new TreeMap<String, String>(); for (int i = 0; i < stringArray.length; i++) { treeMap.put(stringArray[i], stringArray[i]); }/*www .j av a 2 s. c om*/ return treeMap; }
From source file:org.powertac.genco.GencoTests.java
@Test public void testGenerateOrders2() { // set up the genco with commitment leadtime=3 TreeMap<String, String> map = new TreeMap<String, String>(); map.put("genco.genco.commitmentLeadtime", "3"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);//from w w w. ja va2 s.com serverConfig.configureMe(genco); // capture orders final ArrayList<Order> orderList = new ArrayList<Order>(); doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); orderList.add((Order) args[0]); return null; } }).when(mockProxy).routeMessage(isA(Order.class)); // set up some timeslots Timeslot ts0 = timeslotRepo.makeTimeslot(start); assertEquals("first ts has sn=24", 24, ts0.getSerialNumber()); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 2)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 3)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 4)); assertEquals("4 enabled timeslots", 4, timeslotRepo.enabledTimeslots().size()); // generate orders and check genco.generateOrders(start, timeslotRepo.enabledTimeslots()); assertEquals("two orders", 2, orderList.size()); Order first = orderList.get(0); assertEquals("first order for ts3", 27, first.getTimeslotIndex()); assertEquals("first order price", 1.0, first.getLimitPrice(), 1e-6); assertEquals("first order for 100 mwh", -100.0, first.getMWh(), 1e-6); Order second = orderList.get(1); assertEquals("second order for ts4", 28, second.getTimeslotIndex()); assertEquals("second order price", 1.0, second.getLimitPrice(), 1e-6); assertEquals("second order for 100 mwh", -100.0, second.getMWh(), 1e-6); }
From source file:edu.utexas.cs.tactex.tariffoptimization.TariffOptimizierTOUFixedMargin.java
@Override public TreeMap<Double, TariffSpecification> optimizeTariffs( HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions, HashMap<CustomerInfo, ArrayRealVector> customer2estimatedEnergy, List<TariffSpecification> competingTariffs, MarketManager marketManager, ContextManager contextManager, CostCurvesPredictor costCurvesPredictor, int currentTimeslot, Broker me) { // seed will be the best fixed-rate tariff TreeMap<Double, TariffSpecification> sortedTariffs = tariffOptimizerFixedRate.optimizeTariffs( tariffSubscriptions, customer2estimatedEnergy, competingTariffs, marketManager, contextManager, costCurvesPredictor, currentTimeslot, me); TariffSpecification fixedRateSeed = extractBestTariffSpec(sortedTariffs); TotalEnergyRecords energyRecords = sumTotalEnergy(customer2estimatedEnergy, tariffSubscriptions, currentTimeslot);//from ww w .j a va 2 s.c o m ArrayRealVector energyUnitCosts = computeEnergyUnitCosts(costCurvesPredictor, energyRecords.getMyCustomersEnergy(), energyRecords.getCompetitorCustomersEnergy(), currentTimeslot); double avgMargin = computeAvgMargin(energyUnitCosts, fixedRateSeed); TariffSpecification touSpec = createTOUFixedMargin(energyUnitCosts, avgMargin, currentTimeslot, me); // create a result map with 1 tariff TreeMap<Double, TariffSpecification> eval2spec = new TreeMap<Double, TariffSpecification>(); eval2spec.put(0.0, touSpec); return eval2spec; }
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.// ww w . j av a 2 s . c om * @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:org.powertac.genco.GencoTests.java
@Test public void testGenerateOrders3() { // set up the genco with commitment leadtime=3 TreeMap<String, String> map = new TreeMap<String, String>(); map.put("genco.genco.commitmentLeadtime", "3"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);//ww w. ja v a 2s. co m serverConfig.configureMe(genco); // capture orders final ArrayList<Order> orderList = new ArrayList<Order>(); doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); orderList.add((Order) args[0]); return null; } }).when(mockProxy).routeMessage(isA(Order.class)); // set up some timeslots Timeslot ts0 = timeslotRepo.makeTimeslot(start); assertEquals("first ts has sn=24", 24, ts0.getSerialNumber()); //timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR)); //timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 2)); //timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 3)); //timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 4)); assertEquals("4 enabled timeslots", 4, timeslotRepo.enabledTimeslots().size()); // 50 mwh already sold in ts2 Timeslot ts2 = timeslotRepo.findBySerialNumber(26); MarketPosition posn2 = new MarketPosition(genco, ts2, -50.0); genco.addMarketPosition(posn2, ts2.getSerialNumber()); // generate orders and check genco.generateOrders(start, timeslotRepo.enabledTimeslots()); assertEquals("three orders", 3, orderList.size()); Order order = orderList.get(0); assertEquals("first order for ts2", 26, order.getTimeslotIndex()); assertEquals("first order price", 1.0, order.getLimitPrice(), 1e-6); assertEquals("first order for 50 mwh", -50.0, order.getMWh(), 1e-6); order = orderList.get(1); assertEquals("second order for ts3", 27, order.getTimeslotIndex()); assertEquals("second order price", 1.0, order.getLimitPrice(), 1e-6); assertEquals("second order for 100 mwh", -100.0, order.getMWh(), 1e-6); order = orderList.get(2); assertEquals("third order for ts4", 28, order.getTimeslotIndex()); assertEquals("third order price", 1.0, order.getLimitPrice(), 1e-6); assertEquals("third order for 100 mwh", -100.0, order.getMWh(), 1e-6); }
From source file:module.entities.NameFinder.DB.java
public static TreeMap<Integer, String> getDemocracitConsultationBody() throws SQLException { TreeMap<Integer, String> cons_body = new TreeMap<>(); String sql = "SELECT id, short_description, completed_text " + "FROM consultation " + "WHERE id " // + "=3338;"; + "NOT IN (SELECT consultations_ner.id FROM consultations_ner);"; Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { int consID = rs.getInt("id"); String cons_desc = rs.getString("short_description"); // String cons_compl = rs.getString("completed_text"); // if (cons_compl != null) { // String cons_text = cons_compl + "\n" + cons_desc; // cons_body.put(consID, cons_text); // } else { cons_body.put(consID, cons_desc); // } }//w ww .j a v a 2s . c o m return cons_body; }
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./*w ww . ja v a 2 s.co m*/ * @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); }