List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:org.apache.drill.optiq.EnumerableDrill.java
private static SortedMap<String, Object> map(ObjectNode node) { // TreeMap makes the results deterministic. final TreeMap<String, Object> map = new TreeMap<>(); final Iterator<Map.Entry<String, JsonNode>> fields = node.fields(); while (fields.hasNext()) { Map.Entry<String, JsonNode> next = fields.next(); map.put(next.getKey(), wrapper(next.getValue())); }// w ww. j a va2s . com return Collections.unmodifiableSortedMap(map); }
From source file:api.Status.java
public static Result getStatus() { ObjectNode metrics = Json.newObject(); OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); TreeMap<String, Object> values = new TreeMap<String, Object>(); for (Method method : os.getClass().getDeclaredMethods()) { method.setAccessible(true);//from ww w .j av a2 s . c om if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) { Object value; try { value = method.invoke(os); values.put(method.getName(), value); } catch (Exception e) { Logger.warn("Error when invoking " + os.getClass().getName() + " (OperatingSystemMXBean) method " + method.getName() + ": " + e); } // try } // if } // for metrics.put("jvmLoad", (Double) values.get("getProcessCpuLoad")); metrics.put("cpuLoad", (Double) values.get("getSystemCpuLoad")); metrics.put("openFD", (Long) values.get("getOpenFileDescriptorCount")); metrics.put("maxFD", (Long) values.get("getMaxFileDescriptorCount")); metrics.put("freeMemory", (Long) values.get("getFreePhysicalMemorySize")); metrics.put("totalMemory", (Long) values.get("getTotalPhysicalMemorySize")); return ok(metrics.toString()); }
From source file:it.imtech.bookimporter.BookUtility.java
/** * Restituisce le lingue disponibili in ordine alfabetico * @param config/* w ww.j ava2s . com*/ * @param bundle * @return TreeMap<String, String> */ protected static TreeMap<String, String> getOrderedLanguages(XMLConfiguration config, ResourceBundle bundle) { TreeMap<String, String> ordered_res = new TreeMap<String, String>(); String lang_name; String key; java.util.List<HierarchicalConfiguration> resources = config.configurationsAt("resources.resource"); for (HierarchicalConfiguration resource : resources) { lang_name = resource.getString("[@descr]"); key = it.imtech.utility.Utility.getBundleString(lang_name, bundle); ordered_res.put(key, resource.getString("")); } return ordered_res; }
From source file:com.bluexml.tools.miscellaneous.Translate.java
protected static TreeMap<String, String> loadProperties(File input) throws FileNotFoundException, IOException { TreeMap<String, String> map = new TreeMap<String, String>(); Properties props = new Properties(); FileInputStream fin = new FileInputStream(input); props.load(fin);/*from ww w. j a va 2s. c om*/ Enumeration<Object> keys = props.keys(); while (keys.hasMoreElements()) { String nextElement = (String) keys.nextElement(); String property = props.getProperty(nextElement); map.put(nextElement, property); } return map; }
From source file:com.espertech.esper.core.start.EPStatementStartMethodHelperViewResources.java
public static ViewResourceDelegateVerified verifyPreviousAndPriorRequirements( ViewFactoryChain[] unmaterializedViewChain, ViewResourceDelegateUnverified delegate) throws ExprValidationException { boolean hasPriorNodes = !delegate.getPriorRequests().isEmpty(); boolean hasPreviousNodes = !delegate.getPreviousRequests().isEmpty(); int numStreams = unmaterializedViewChain.length; ViewResourceDelegateVerifiedStream[] perStream = new ViewResourceDelegateVerifiedStream[numStreams]; // verify "previous" List<ExprPreviousNode>[] previousPerStream = new List[numStreams]; for (ExprPreviousNode previousNode : delegate.getPreviousRequests()) { int stream = previousNode.getStreamNumber(); List<ViewFactory> factories = unmaterializedViewChain[stream].getViewFactoryChain(); boolean pass = inspectViewFactoriesForPrevious(factories); if (!pass) { throw new ExprValidationException( "Previous function requires a single data window view onto the stream"); }/*from ww w .ja v a 2 s . c o m*/ boolean found = false; for (ViewFactory factory : factories) { if (factory instanceof DataWindowViewWithPrevious) { found = true; break; } } if (!found) { throw new ExprValidationException( "Required data window not found for the 'prev' function, specify a data window for which previous events are retained"); } if (previousPerStream[stream] == null) { previousPerStream[stream] = new ArrayList<ExprPreviousNode>(); } previousPerStream[stream].add(previousNode); } // verify "prior" SortedMap<Integer, List<ExprPriorNode>>[] priorPerStream = new SortedMap[numStreams]; for (ExprPriorNode priorNode : delegate.getPriorRequests()) { int stream = priorNode.getStreamNumber(); if (priorPerStream[stream] == null) { priorPerStream[stream] = new TreeMap<Integer, List<ExprPriorNode>>(); } TreeMap<Integer, List<ExprPriorNode>> treemap = (TreeMap<Integer, List<ExprPriorNode>>) priorPerStream[stream]; List<ExprPriorNode> callbackList = treemap.get(priorNode.getConstantIndexNumber()); if (callbackList == null) { callbackList = new LinkedList<ExprPriorNode>(); treemap.put(priorNode.getConstantIndexNumber(), callbackList); } callbackList.add(priorNode); } // build per-stream info for (int i = 0; i < numStreams; i++) { if (previousPerStream[i] == null) { previousPerStream[i] = Collections.emptyList(); } if (priorPerStream[i] == null) { priorPerStream[i] = CollectionUtil.EMPTY_SORTED_MAP; } perStream[i] = new ViewResourceDelegateVerifiedStream(previousPerStream[i], priorPerStream[i]); } return new ViewResourceDelegateVerified(hasPriorNodes, hasPreviousNodes, perStream); }
From source file:com.wadpam.guja.oauth2.social.NetworkTemplate.java
public static Map<String, String> asMap(String... nameValues) { final TreeMap<String, String> map = new TreeMap<String, String>(); if (null != nameValues) { for (int i = 0; i + 1 < nameValues.length; i += 2) { map.put(nameValues[i], nameValues[i + 1]); }/*from w w w . ja v a 2s. co m*/ } return map; }
From source file:Main.java
/** * @param r// w w w . jav a 2 s . c o m * the original rectangle * @param includeReservedInsets * if taskbar and other windowing insets should be included in the * returned area * @return iff there are multiple monitors the other monitor than the * effective view of the monitor that the rectangle mostly coveres, or * null if there is just one screen */ public static Rectangle getOppositeFullScreenBoundsFor(Rectangle r, boolean includeReservedInsets) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); TreeMap<Integer, Rectangle> prioMap = new TreeMap<Integer, Rectangle>(); for (GraphicsDevice dev : ge.getScreenDevices()) { Rectangle bounds; if ((!includeReservedInsets) && dev == ge.getDefaultScreenDevice()) { bounds = ge.getMaximumWindowBounds(); } else { bounds = dev.getDefaultConfiguration().getBounds(); } Rectangle intersection = bounds.intersection(r); prioMap.put(intersection.width * intersection.height, bounds); } if (prioMap.size() <= 1) { return null; } else { return prioMap.get(prioMap.firstKey()); } }
From source file:com.data2semantics.yasgui.server.db.ConnectionFactory.java
private static void applyDeltas(Connection connect, File configDir) throws UnsupportedEncodingException, IOException, SQLException { @SuppressWarnings("unchecked") ArrayList<File> listFiles = new ArrayList<File>( FileUtils.listFiles(new File(configDir.getAbsolutePath() + "/config"), FileFilterUtils.prefixFileFilter("delta_"), null)); TreeMap<Integer, File> files = new TreeMap<Integer, File>(); for (File file : listFiles) { String basename = file.getName(); basename = basename.substring("delta_".length()); basename = basename.substring(0, basename.length() - ".sql".length()); int index = Integer.parseInt(basename); files.put(index, file); }/*from w w w. jav a2 s .co m*/ ArrayList<Integer> currentDeltas = getDeltas(connect); //treemap is naturally sorted, so just iterate through them for (Entry<Integer, File> entry : files.entrySet()) { if (!currentDeltas.contains(entry.getKey())) { ScriptRunner runner = new ScriptRunner(connect, false, true); FileInputStream fileStream = new FileInputStream(entry.getValue()); runner.runScript(new BufferedReader(new InputStreamReader(fileStream, "UTF-8"))); fileStream.close(); setDeltaApplied(connect, entry.getKey()); } } }
From source file:com.google.api.server.spi.discovery.DiscoveryGenerator.java
private static Map<String, JsonSchema> createStandardParameters() { TreeMap<String, JsonSchema> params = new TreeMap<>(); params.put(StandardParameters.ALT, new JsonSchema().setDefault("json").setDescription("Data format for the response.") .setEnum(Lists.newArrayList("json")) .setEnumDescriptions(Lists.newArrayList("Responses with Content-Type of application/json")) .setLocation("query").setType("string")); params.put(StandardParameters.FIELDS, new JsonSchema() .setDescription("Selector specifying which fields to include in a partial response.") .setLocation("query").setType("string")); params.put(StandardParameters.KEY, new JsonSchema() .setDescription("API key. Your API key identifies your project and provides you with " + "API access, quota, and reports. Required unless you provide an OAuth 2.0 " + "token.") .setLocation("query").setType("string")); params.put(StandardParameters.OAUTH_TOKEN, new JsonSchema() .setDescription("OAuth 2.0 token for the current user.").setLocation("query").setType("string")); params.put(StandardParameters.PRETTY_PRINT, new JsonSchema().setDefault("true") .setDescription("Returns response with indentations and line breaks.").setLocation("query") .setType("boolean")); params.put(StandardParameters.QUOTA_USER, new JsonSchema() .setDescription("Available to use for quota purposes for server-side applications. " + "Can be any arbitrary string assigned to a user, but should not exceed 40 " + "characters. Overrides userIp if both are provided.") .setLocation("query").setType("string")); params.put(StandardParameters.USER_IP, new JsonSchema().setDescription("IP address of the site where the request originates. Use this if " + "you want to enforce per-user limits.").setLocation("query").setType("string")); return params; }
From source file:cn.digirun.frame.payment.unionpay.util.SDKUtil.java
/** * /*from www. j a v a 2 s .c o m*/ * @param data * @return */ public static String genHtmlResult(Map<String, String> data) { TreeMap<String, String> tree = new TreeMap<String, String>(); Iterator<Entry<String, String>> it = data.entrySet().iterator(); while (it.hasNext()) { Entry<String, String> en = it.next(); tree.put(en.getKey(), en.getValue()); } it = tree.entrySet().iterator(); StringBuffer sf = new StringBuffer(); while (it.hasNext()) { Entry<String, String> en = it.next(); String key = en.getKey(); String value = en.getValue(); if ("respCode".equals(key)) { sf.append("<b>" + key + SDKConstants.EQUAL + value + "</br></b>"); } else sf.append(key + SDKConstants.EQUAL + value + "</br>"); } return sf.toString(); }