List of usage examples for java.util SortedMap get
V get(Object key);
From source file:org.runnerup.export.format.RunKeeper.java
private static SortedMap<Long, HashMap<String, String>> createPointsMap(JSONArray distance, JSONArray path, JSONArray hr) throws JSONException { SortedMap<Long, HashMap<String, String>> result = new TreeMap<Long, HashMap<String, String>>(); if (distance != null && distance.length() > 0) { for (int i = 0; i < distance.length(); i++) { JSONObject o = distance.getJSONObject(i); Long key = TimeUnit.SECONDS.toMillis((long) Float.parseFloat(o.getString("timestamp"))); HashMap<String, String> value = new HashMap<String, String>(); String valueMapKey = "distance"; String valueMapValue = o.getString(valueMapKey); value.put(valueMapKey, valueMapValue); result.put(key, value);//from www. j av a 2 s. c om } } if (path != null && path.length() > 0) { for (int i = 0; i < path.length(); i++) { JSONObject o = path.getJSONObject(i); Long key = TimeUnit.SECONDS.toMillis((long) Float.parseFloat(o.getString("timestamp"))); HashMap<String, String> value = result.get(key); if (value == null) { value = new HashMap<String, String>(); } String[] attrs = new String[] { "latitude", "longitude", "altitude", "type" }; for (String valueMapKey : attrs) { String valueMapValue = o.getString(valueMapKey); value.put(valueMapKey, valueMapValue); } result.put(key, value); } } if (hr != null && hr.length() > 0) { for (int i = 0; i < hr.length(); i++) { JSONObject o = hr.getJSONObject(i); Long key = TimeUnit.SECONDS.toMillis((long) Float.parseFloat(o.getString("timestamp"))); HashMap<String, String> value = result.get(key); if (value == null) { value = new HashMap<String, String>(); } String valueMapKey = "heart_rate"; String valueMapValue = o.getString(valueMapKey); value.put(valueMapKey, valueMapValue); result.put(key, value); } } return result; }
From source file:org.motrice.jmx.BasicAppManagement.java
/** * Get the log level of a named logger.// w w w . j a va 2s. c o m * The first logger ending with the name is chosen. */ @ManagedOperation(description = "Get the log level of a specific logger", currencyTimeLimit = 10) @ManagedOperationParameters({ @ManagedOperationParameter(name = "logger", description = "(Last part of) logger name") }) public String getLogLevel(String logger) { // Note that getLogger returns a new logger if the name is undefined SortedMap<String, Logger> map = doGetLoggers(); String level = "*Unknown*"; if (notBlank(logger)) { for (String key : map.keySet()) { if (key.endsWith(logger.trim())) { Logger log = map.get(key); if (log != null) level = log.getLevel().toString(); } } } return level; }
From source file:playground.sergioo.facilitiesGenerator2012.WorkFacilitiesGeneration.java
private static Map<String, PointPerson> getWorkActivityTimes() throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NoConnectionException { DataBaseAdmin dataBaseHits = new DataBaseAdmin(new File("./data/hits/DataBase.properties")); Map<String, PersonSchedule> times; ResultSet timesResult = dataBaseHits.executeQuery( "SELECT pax_idx,trip_id,t6_purpose,t3_starttime,t4_endtime,p6_occup,t5_placetype FROM hits.hitsshort"); times = new HashMap<String, PersonSchedule>(); while (timesResult.next()) { PersonSchedule timesPerson = times.get(timesResult.getString(1)); if (timesPerson == null) { timesPerson = new PersonSchedule(timesResult.getString(1), timesResult.getString(6)); times.put(timesResult.getString(1), timesPerson); }// w w w . j ava 2 s . c om if (timesResult.getInt(2) != 0) { Iterator<Entry<Integer, Trip>> timesPersonI = timesPerson.getTrips().entrySet().iterator(); Entry<Integer, Trip> last = null; while (timesPersonI.hasNext()) last = timesPersonI.next(); if (last == null || last.getKey() != timesResult.getInt(2)) { int startTime = (timesResult.getInt(4) % 100) * 60 + (timesResult.getInt(4) / 100) * 3600; int endTime = (timesResult.getInt(5) % 100) * 60 + (timesResult.getInt(5) / 100) * 3600; if (last != null && last.getKey() < timesResult.getInt(2) && last.getValue().getEndTime() > startTime) { startTime += 12 * 3600; endTime += 12 * 3600; } if (last != null && last.getKey() < timesResult.getInt(2) && last.getValue().getEndTime() > startTime) { startTime += 12 * 3600; endTime += 12 * 3600; } timesPerson.getTrips().put(timesResult.getInt(2), new Trip(timesResult.getString(3), startTime, endTime, timesResult.getString(7))); } } } timesResult.close(); Map<String, PointPerson> points = new HashMap<String, PointPerson>(); for (PersonSchedule timesPerson : times.values()) { SortedMap<Integer, Trip> tripsPerson = timesPerson.getTrips(); boolean startTimeSaved = false; double startTime = -1, endTime = -1; String placeType = null; if (tripsPerson.size() > 0) { for (int i = tripsPerson.keySet().iterator().next(); i <= tripsPerson.size(); i++) { if (!startTimeSaved && tripsPerson.get(i).getPurpose() != null && tripsPerson.get(i).getPurpose().equals("work")) { startTime = tripsPerson.get(i).getEndTime(); startTimeSaved = true; } if (i > tripsPerson.keySet().iterator().next() && tripsPerson.get(i - 1).getPurpose().equals("work")) { endTime = tripsPerson.get(i).getStartTime(); placeType = tripsPerson.get(i - 1).getPlaceType(); } } } if (startTime != -1 && endTime != -1 && endTime - startTime >= 7 * 3600 && endTime - startTime <= 16 * 3600) if (startTime > 24 * 3600) points.put(timesPerson.getId(), new PointPerson( timesPerson.getId(), timesPerson.getOccupation(), new Double[] { startTime - 24 * 3600, endTime - 24 * 3600 - (startTime - 24 * 3600) }, placeType)); else points.put(timesPerson.getId(), new PointPerson(timesPerson.getId(), timesPerson.getOccupation(), new Double[] { startTime, endTime - startTime }, placeType)); } Map<String, Double> weights; try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(WEIGHTS2_MAP_FILE)); weights = (Map<String, Double>) ois.readObject(); ois.close(); } catch (EOFException e) { weights = new HashMap<String, Double>(); ResultSet weightsR = dataBaseHits.executeQuery("SELECT pax_idx,hipf10 FROM hits.hitsshort_geo_hipf"); while (weightsR.next()) weights.put(weightsR.getString(1), weightsR.getDouble(2)); for (PointPerson pointPerson : points.values()) { if (weights.get(pointPerson.getId()) != null) pointPerson.setWeight(weights.get(pointPerson.getId())); else pointPerson.setWeight(100); } ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(WEIGHTS2_MAP_FILE)); oos.writeObject(weights); oos.close(); } dataBaseHits.close(); /*points.clear(); double a=Math.PI/6; double dx=3; double dy=7; double sx=4; double sy=0.5; for(int i=0; i<1000; i++) { double x=Math.random(); double y=Math.random(); points.put(i+"", new PointPerson(i+"", "any", new Double[]{Math.cos(a)*sx*x-Math.sin(a)*sy*y+dx, Math.sin(a)*sx*x+Math.cos(a)*sy*y+dy})); }*/ return points; }
From source file:org.codetrack.database.file.FileProject.java
/** * Find an ProjectItem instance by name//from ww w . j av a2 s . c o m * @param id String of ProjectItem * @return ProjectItem instance. Null if not found */ //@Override public ProjectItem findById(Class clazz, String id) { if (itemsMap.containsKey(clazz)) { SortedMap<String, ProjectItem> map = itemsMap.get(clazz); if (map.containsKey(id)) return map.get(id); } return null; }
From source file:gov.nih.nci.cabig.ctms.web.WebToolsTest.java
public void testSessionAttributesToMap() { session.setAttribute("jimmy", "james"); session.setAttribute("johnny", "johnson"); session.setAttribute("wnyx", 585); SortedMap<String, Object> map = WebTools.sessionAttributesToMap(session); Set<String> keys = map.keySet(); assertContains(keys, "jimmy"); assertContains(keys, "johnny"); assertContains(keys, "wnyx"); assertEquals(map.get("jimmy"), "james"); assertEquals(map.get("johnny"), "johnson"); assertEquals(map.get("wnyx"), 585); // test order Iterator<String> keysIt = keys.iterator(); assertEquals("jimmy", keysIt.next()); assertEquals("johnny", keysIt.next()); assertEquals("wnyx", keysIt.next()); }
From source file:gov.nih.nci.cabig.ctms.web.WebToolsTest.java
public void testRequestAttributesToMap() { request.setAttribute("wnyx", 585); request.setAttribute("jimmy", "james"); request.setAttribute("johnny", "johnson"); SortedMap<String, Object> map = WebTools.requestAttributesToMap(request); Set<String> keys = map.keySet(); assertContains(keys, "jimmy"); assertContains(keys, "johnny"); assertContains(keys, "wnyx"); assertEquals(map.get("jimmy"), "james"); assertEquals(map.get("johnny"), "johnson"); assertEquals(map.get("wnyx"), 585); // test order Iterator<String> keysIt = keys.iterator(); assertEquals("jimmy", keysIt.next()); assertEquals("johnny", keysIt.next()); assertEquals("wnyx", keysIt.next()); }
From source file:org.archive.crawler.processor.LexicalCrawlMapper.java
/** * Look up the crawler node name to which the given CrawlURI * should be mapped. /*from ww w. ja v a2 s .co m*/ * * @param cauri CrawlURI to consider * @return String node name which should handle URI */ protected String map(CrawlURI cauri) { // get classKey, via frontier to generate if necessary String classKey = frontier.getClassKey(cauri); SortedMap<String, String> tail = map.tailMap(classKey); if (tail.isEmpty()) { // wraparound tail = map; } // target node is value of nearest subsequent key return (String) tail.get(tail.firstKey()); }
From source file:annis.CSVHelper.java
public static void exportCSVData(Iterator<AnnotatedMatch> matches, SortedMap<Integer, SortedSet<String>> columnsByNodePos, PrintWriter w) { int count = columnsByNodePos.keySet().size(); // print values while (matches.hasNext()) { AnnotatedMatch match = matches.next(); List<String> line = new ArrayList<>(); int k = 0; for (; k < match.size(); ++k) { AnnotatedSpan span = match.get(k); Map<String, String> valueByName = new HashMap<>(); if (span != null) { if (span.getAnnotations() != null) { for (Annotation annotation : span.getAnnotations()) { valueByName.put("anno_" + annotation.getQualifiedName(), annotation.getValue()); }//www. ja v a 2 s . c o m } if (span.getMetadata() != null) { for (Annotation meta : span.getMetadata()) { valueByName.put("meta_" + meta.getQualifiedName(), meta.getValue()); } } line.add("" + span.getId()); line.add(span.getCoveredText().replace("\t", "\\t")); } for (String name : columnsByNodePos.get(k)) { if (valueByName.containsKey(name)) { line.add(valueByName.get(name).replace("\t", "\\t")); } else { line.add("'NULL'"); } } } for (int l = k; l < count; ++l) { line.add("'NULL'"); for (int m = 0; m <= columnsByNodePos.get(l).size(); ++m) { line.add("'NULL'"); } } w.append(StringUtils.join(line, "\t")); w.append("\n"); } }
From source file:org.lmnl.AbstractTest.java
/** * Prints the given {@link OverlapIndexer range index} to the log. * //ww w . j a va2 s. c o m * @param index * the range index to output */ protected void printDebugMessage(SortedMap<Range, List<Annotation>> index) { if (LOG.isDebugEnabled()) { final StringBuilder str = new StringBuilder(); for (Range segment : index.keySet()) { str.append("[" + segment + ": { "); boolean first = true; for (Annotation annotation : index.get(segment)) { if (first) { first = false; } else { str.append(", "); } str.append(annotation.toString()); } str.append(" }]\n"); } LOG.debug(str.toString()); } }
From source file:FocusTraversalExample.java
public Component getComponentAfter(Container focusCycleRoot, Component aComponent) { if (!(aComponent instanceof JButton)) { return null; }/*from ww w. ja va 2 s .com*/ SortedMap buttons = getSortedButtons(focusCycleRoot); // Find all buttons after the current one. String nextName = ((JButton) aComponent).getText() + "\0"; SortedMap nextButtons = buttons.tailMap(nextName); if (nextButtons.isEmpty()) { // Wrapped back to beginning if (!buttons.isEmpty()) { return (Component) buttons.get(buttons.firstKey()); } return null; // Degenerate case of no buttons. } return (Component) nextButtons.get(nextButtons.firstKey()); }