List of usage examples for java.util TreeMap TreeMap
public TreeMap()
From source file:Main.java
public static Window getOwnerForChildWindow() { Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); if (w != null) { return w; }// w w w . j ava 2s . c o m w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); if (w != null) { return w; } /* * Priority level1 * modal dialog: +200 * non-modal dialog: +100 * frame: +0 * * Priority level2 * no owned windows: +10 */ TreeMap<Integer, Window> prioMap = new TreeMap<Integer, Window>(); for (Window cand : Window.getWindows()) { if (cand == null) { continue; } if (!cand.isVisible()) { continue; } if (!cand.isShowing()) { continue; } int prio = 0; Window[] children = cand.getOwnedWindows(); if (children == null || children.length == 0) { prio += 10; } if (cand instanceof Dialog) { Dialog dlg = (Dialog) cand; if (dlg.isModal()) { prio += 200; } else { prio += 100; } prioMap.put(prio, cand); } else if (cand instanceof Frame) { if (!prioMap.containsKey(prio)) { prioMap.put(prio, cand); } } } if (prioMap.size() > 0) { return prioMap.get(prioMap.lastKey()); } //last line of defense if (prioMap.size() == 0) { for (Window cand : Window.getWindows()) { if (cand == null) { continue; } if (cand.isVisible()) { return cand; } } } return null; }
From source file:Main.java
public static <K, V> Map<K, V> putAndCreateTreeMapIfAbsent(Map<K, V> map, K key, V value) { if (map == null) { map = new TreeMap<K, V>(); map.put(key, value);/*from ww w . ja v a 2 s .co m*/ } else if (!map.containsKey(key)) { map.put(key, value); } return map; }
From source file:com.cloudant.mazha.json.JSONHelperTest.java
@BeforeClass public static void beforeClass() throws Exception { expectedJSONMap = new TreeMap<String, Object>(); expectedJSONMap.put("Sunrise", true); expectedJSONMap.put("Sunset", false); expectedJSONMap.put("Data", "A run to the head of the blood"); TreeMap<String, Object> organizer = new TreeMap<String, Object>(); organizer.put("Name", "Tom"); organizer.put("Sex", "Male"); expectedJSONMap.put("Organizer", organizer); ArrayList<Number> fullhours = new ArrayList<Number>(); fullhours.add(1);//ww w .j a va 2 s.c o m fullhours.add(2); fullhours.add(3); fullhours.add(4); fullhours.add(5); fullhours.add(6); fullhours.add(7); fullhours.add(8); fullhours.add(9); fullhours.add(10); expectedJSONMap.put("FullHours", fullhours); TreeMap<String, Object> football = new TreeMap<String, Object>(); football.put("Name", "Football"); football.put("Duration", 2); football.put("DurationUnit", "Hours"); TreeMap<String, Object> breakfast = new TreeMap<String, Object>(); breakfast.put("Name", "Breakfast"); breakfast.put("Duration", 40); breakfast.put("DurationUnit", "Minutes"); ArrayList<String> attendees = new ArrayList<String>(); attendees.add("Jan"); attendees.add("Damien"); attendees.add("Laura"); attendees.add("Gwendolyn"); attendees.add("Roseanna"); breakfast.put("Attendees", attendees); ArrayList<TreeMap> activities = new ArrayList<TreeMap>(); activities.add(football); activities.add(breakfast); expectedJSONMap.put("Activities", activities); expectedJson = FileUtils.readFileToString(TestUtils.loadFixture("fixture/json_helper_compacted.json")); }
From source file:Main.java
public static <K, V> Map<K, V> conditionalPutAndCreateTreeMapIfAbsent(Map<K, V> map, boolean cond, K key, V value) {/* w ww . j a va 2s . co m*/ if (cond) { if (map == null) { map = new TreeMap<K, V>(); map.put(key, value); } else if (!map.containsKey(key)) { map.put(key, value); } } return map; }
From source file:com.insightml.evaluation.simulation.BasicSimulationResult.java
public static SimulationResult of(final String learner, final ISimulationResults<?, ?> performance) { final StatisticalSummary[] results = performance.getResults(); final ObjectiveFunction<?, ?>[] metrics = performance.getObjectives(); final Map<String, Float> metric = new TreeMap<>(); for (int i = 0; i < metrics.length; ++i) { metric.put(metrics[i].getName(), (float) results[i].getMean()); }/*from ww w. j a v a 2s . co m*/ return new BasicSimulationResult(learner, metric); }
From source file:edu.northwestern.bioinformatics.studycalendar.domain.Gender.java
public static Map<String, String> getGenderMap() { Map<String, String> genders = new TreeMap<String, String>(); genders.put(Gender.MALE.getCode(), Gender.MALE.getDisplayName()); genders.put(Gender.FEMALE.getCode(), Gender.FEMALE.getDisplayName()); genders.put(Gender.NOT_REPORTED.getCode(), Gender.NOT_REPORTED.getDisplayName()); genders.put(Gender.UNKNOWN.getCode(), Gender.UNKNOWN.getDisplayName()); return genders; }
From source file:annis.WekaHelper.java
public static String exportAsArff(List<AnnotatedMatch> annotatedMatches) { StringBuilder sb = new StringBuilder(); // header: relation name (unused) sb.append("@relation name\n"); sb.append("\n"); // figure out what annotations are used at each match position SortedMap<Integer, SortedSet<String>> columnsByNodePos = new TreeMap<Integer, SortedSet<String>>(); for (int i = 0; i < annotatedMatches.size(); ++i) { AnnotatedMatch match = annotatedMatches.get(i); for (int j = 0; j < match.size(); ++j) { AnnotatedSpan span = match.get(j); if (columnsByNodePos.get(j) == null) { columnsByNodePos.put(j, new TreeSet<String>()); }/*from w w w . j a v a2 s . co m*/ for (Annotation annotation : span.getAnnotations()) { columnsByNodePos.get(j).add("anno_" + annotation.getQualifiedName()); } for (Annotation meta : span.getMetadata()) { columnsByNodePos.get(j).add("meta_" + meta.getQualifiedName()); } } } // print column names and data types int count = columnsByNodePos.keySet().size(); for (int j = 0; j < count; ++j) { sb.append("@attribute ").append(fullColumnName(j + 1, "id")).append(" string\n"); sb.append("@attribute ").append(fullColumnName(j + 1, "span")).append(" string\n"); SortedSet<String> annotationNames = columnsByNodePos.get(j); for (String name : annotationNames) { sb.append("@attribute ").append(fullColumnName(j + 1, name)).append(" string\n"); } } sb.append("\n@data\n\n"); // print values for (AnnotatedMatch match : annotatedMatches) { List<String> line = new ArrayList<String>(); int k = 0; for (; k < match.size(); ++k) { AnnotatedSpan span = match.get(k); Map<String, String> valueByName = new HashMap<String, String>(); if (span != null) { if (span.getAnnotations() != null) { for (Annotation annotation : span.getAnnotations()) { valueByName.put("anno_" + annotation.getQualifiedName(), annotation.getValue()); } } 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("'", "\\'") + "'"); } for (String name : columnsByNodePos.get(k)) { if (valueByName.containsKey(name)) { line.add("'" + valueByName.get(name).replace("'", "\\'") + "'"); } 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'"); } } sb.append(StringUtils.join(line, ",")); sb.append("\n"); } return sb.toString(); }
From source file:com.microsoft.azure.engagement.shared.EngagementDataPushReceiver.java
@TargetApi(9) public static Map<String, String> getPendingDataPushes(Context context) { Map<String, String> smap = new TreeMap<String, String>(); SharedPreferences settings = context.getSharedPreferences(ENGAGEMENT_PREFERENCES, 0/*MODE_PRIVATE*/); Map<String, ?> m = settings.getAll(); // convert to treemap to keep the order by timestamp for (Map.Entry<String, ?> entry : m.entrySet()) { smap.put(entry.getKey(), entry.getValue().toString()); }/*from w w w . ja v a 2 s. co m*/ // remove all settings.edit().clear().apply(); return smap; }
From source file:com.glaf.core.util.Tools.java
@SuppressWarnings("unchecked") public static Map<String, Object> getDataMap(Object target) { Map<String, Object> dataMap = new TreeMap<String, Object>(); if (Map.class.isAssignableFrom(target.getClass())) { Map<String, Object> map = (Map<String, Object>) target; Set<Entry<String, Object>> entrySet = map.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); if (key != null && value != null) { dataMap.put(key.toString(), value); }//w w w.j a va 2s .c o m } } else { PropertyDescriptor[] propertyDescriptor = BeanUtils.getPropertyDescriptors(target.getClass()); for (int i = 0; i < propertyDescriptor.length; i++) { PropertyDescriptor descriptor = propertyDescriptor[i]; String propertyName = descriptor.getName(); if (propertyName.equalsIgnoreCase("class")) { continue; } try { Object value = PropertyUtils.getProperty(target, propertyName); dataMap.put(propertyName, value); } catch (Exception ex) { } } } return dataMap; }
From source file:org.smigo.user.Language.java
public static Map<String, String> getLanguagesForDisplay(Enumeration<Locale> locales, Locale additionalLocale) { SortedMap<String, String> ret = new TreeMap<>(); for (Language t : Language.values()) { ret.put(t.locale.toString(), StringUtils.capitalize(t.locale.getDisplayName(t.locale))); }/*from ww w. j a va 2 s.c o m*/ while (locales.hasMoreElements()) { Locale locale = locales.nextElement(); ret.put(locale.toString(), StringUtils.capitalize(locale.getDisplayName(locale))); } ret.put(additionalLocale.toString(), StringUtils.capitalize(additionalLocale.getDisplayName(additionalLocale))); return ret; }