List of usage examples for java.util TreeMap remove
public V remove(Object key)
From source file:Main.java
public static void main(String[] args) { TreeMap<String, String> treeMap = new TreeMap<String, String>(); treeMap.put("1", "One"); treeMap.put("2", "Two"); treeMap.put("3", "Three"); Object obj = treeMap.remove("2"); System.out.println(obj + " Removed from TreeMap"); }
From source file:Main.java
public static void main(String[] args) { TreeMap<String, String> treeMap = new TreeMap<String, String>(); System.out.println("Size of TreeMap : " + treeMap.size()); treeMap.put("1", "One"); treeMap.put("2", "Two"); treeMap.put("3", "Three"); System.out.println("Size of TreeMap after addition : " + treeMap.size()); treeMap.remove("2"); System.out.println("Size of TreeMap after removal : " + treeMap.size()); }
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); // populating tree map treemap.put(2, "two"); treemap.put(1, "one"); treemap.put(3, "three"); treemap.put(6, "six"); treemap.put(5, "from java2s.com"); System.out.println("Value before modification: " + treemap); // removing value at key 5 System.out.println("Removed value: " + treemap.remove(5)); System.out.println("Value after modification: " + treemap); }
From source file:com.kaikoda.cah.CardGenerator.java
/** * Generates a printable deck of Cards Against Humanity. * /*from w w w . jav a 2 s . c om*/ * @param args where to find the data file and optionally the dictionary and * target language if translation is required. * @throws CardGeneratorConfigurationException when it's not possible to * construct a usable instance of CardGenerator. * @throws IOException * @throws SAXException * @throws ParserConfigurationException * @throws ParseException if there are any problems encountered while * parsing the command line tokens. */ public static void main(String[] args) throws CardGeneratorConfigurationException, ParseException, SAXException, IOException, ParserConfigurationException { ProgressReporterMode verbosity = ProgressReporterMode.NORMAL; CardGenerator generator = new CardGenerator(); generator.setVerbosity(verbosity); // Configure valid options accepted from the command-line CardGeneratorOptions options = new CardGeneratorOptions(); // Interpret the arguments supplied at runtime. TreeMap<String, String> params = options.parse(args); // Check whether a level of verbosity has been specified. if (params.containsKey("verbosity")) { verbosity = ProgressReporterMode.valueOf(params.get("verbosity").toUpperCase()); generator.setVerbosity(verbosity); } // Check whether help has been requested. if (params.containsKey("help")) { if (verbosity.equals(ProgressReporterMode.NORMAL)) { // Print a list of the options that can be used with // CardGenerator. System.out.println("\n" + params.get("help")); } } else { File data = new File(params.remove("path-to-data")); CardGeneratorProduct product = CardGeneratorProduct.HTML; if (params.containsKey("product")) { product = CardGeneratorProduct.valueOf(params.remove("product").toUpperCase()); } Locale targetLanguage = null; if (params.containsKey("output-language")) { targetLanguage = Locale.forLanguageTag(params.remove("output-language")); } File dictionary = null; if (params.containsKey("path-to-dictionary")) { dictionary = new File(params.remove("path-to-dictionary")); } generator.generate(data, targetLanguage, dictionary, product); } }
From source file:com.eucalyptus.objectstorage.pipeline.handlers.S3Authentication.java
/** * Query params are included in cases of Query-String/Presigned-url auth where they are considered just like headers * /*from w w w . j a v a 2s . co m*/ * @param httpRequest * @param includeQueryParams * @return */ private static String getCanonicalizedAmzHeaders(MappingHttpRequest httpRequest, boolean includeQueryParams) { String result = ""; Set<String> headerNames = httpRequest.getHeaderNames(); TreeMap<String, String> amzHeaders = new TreeMap<String, String>(); for (String headerName : headerNames) { String headerNameString = headerName.toLowerCase().trim(); if (headerNameString.startsWith("x-amz-")) { String value = httpRequest.getHeader(headerName).trim(); String[] parts = value.split("\n"); value = ""; for (String part : parts) { part = part.trim(); value += part + " "; } value = value.trim(); if (amzHeaders.containsKey(headerNameString)) { String oldValue = (String) amzHeaders.remove(headerNameString); oldValue += "," + value; amzHeaders.put(headerNameString, oldValue); } else { amzHeaders.put(headerNameString, value); } } } if (includeQueryParams) { // For query-string auth, header values may include 'x-amz-*' that need to be signed for (String paramName : httpRequest.getParameters().keySet()) { processHeaderValue(paramName, httpRequest.getParameters().get(paramName), amzHeaders); } } // Build the canonical string Iterator<String> iterator = amzHeaders.keySet().iterator(); while (iterator.hasNext()) { String key = iterator.next(); String value = (String) amzHeaders.get(key); result += key + ":" + value + "\n"; } return result; }
From source file:br.edimarmanica.trinity.extract.Extract.java
private void train(File fPage) throws IOException { String sPage = UTF8FileUtil.readStrippedHTML(fPage.toURI()); TreeMap<Integer, Token> tokensPages = tokeniser.tokenise(sPage).getTokensMap(); tokensPages.remove(tokensPages.lastKey()); Text textPage = new Text(fPage, tokensPages.values()); root.add(textPage);/*from ww w. j a va2s.c om*/ }
From source file:org.j2free.util.ServletUtils.java
/** * Returns true if the parameter string prior to the "sig" parameter match the "sig" * parameter when combined with the key and hashed. For post requests, the parameter * order is not guaranteed and so is assumed to be sorted alphabetically by key. * * @param req/*from w ww. j av a 2 s. c o m*/ * @param secret * @return */ public static boolean isAuthenticatedRequest(HttpServletRequest req, String secret) { String query, sig = getStringParameter(req, "sig"), method = req.getMethod(); if (method.equalsIgnoreCase("GET")) { query = req.getQueryString(); if (StringUtils.isBlank(query) || StringUtils.isBlank(sig)) return false; query = query.replace("&sig=" + sig, EMPTY); } else if (method.equalsIgnoreCase("POST")) { TreeMap<String, String[]> params = new TreeMap(req.getParameterMap()); params.remove("sig"); // remove the signature StringBuilder buf = new StringBuilder(); for (Map.Entry<String, String[]> entry : params.entrySet()) { if (buf.length() > 0) buf.append("&"); buf.append(entry.getKey()); buf.append('='); buf.append(entry.getValue()[0]); } query = buf.toString(); } else // We're not supporting auth on non GET or POST requests return false; return signQueryString(query, secret).equals(sig); }
From source file:com.heliosapm.tsdblite.metric.Metric.java
public ObjectName toHostObjectName() { final StringBuilder b = new StringBuilder("metrics."); TreeMap<String, String> tgs = new TreeMap<String, String>(tags); String h = tgs.remove("host"); String a = tgs.remove("app"); final String host = h == null ? "unknownhost" : h; final int segIndex = metricName.indexOf('.'); final String seg = segIndex == -1 ? metricName : metricName.substring(0, segIndex); b.append(host).append(".").append(seg).append(":"); if (segIndex != -1) { tgs.put("app", metricName.substring(segIndex + 1)); }/*w ww . j ava 2 s .c o m*/ for (Map.Entry<String, String> entry : tgs.entrySet()) { b.append(entry.getKey()).append("=").append(entry.getValue()).append(","); } b.deleteCharAt(b.length() - 1); return JMXHelper.objectName(b); }
From source file:eu.freme.broker.tools.internationalization.BodySwappingServletRequest.java
@Override public Map<String, String[]> getParameterMap() { TreeMap<String, String[]> map = new TreeMap<String, String[]>(); map.putAll(super.getParameterMap()); map.put("informat", new String[] { "turtle" }); map.remove("input"); if (changeResponse) { map.put("outformat", new String[] { "turtle" }); }//from w w w . j a va 2 s .c o m return Collections.unmodifiableMap(map); }
From source file:com.heliosapm.tsdblite.handlers.json.SplitTraceInputHandler.java
public String toHostObjectNameName(final ObjectName on) { final StringBuilder b = new StringBuilder("meta."); TreeMap<String, String> tgs = new TreeMap<String, String>(on.getKeyPropertyList()); final String metricName = on.getDomain(); String h = tgs.remove("host"); String a = tgs.remove("app"); final String host = h; //==null ? "*" : h; final String app = a == null ? "ANYAPP" : a; final int segIndex = metricName.indexOf('.'); final String seg = segIndex == -1 ? metricName : metricName.substring(0, segIndex); if (host != null) { b.append(host).append(".").append(seg).append(":"); }/*from w w w . j av a 2 s . c o m*/ if (app != null) { tgs.put("app", app); // b.append(app).append(".").append(seg).append(":"); } // if(segIndex!=-1) { // tgs.put("app", metricName.substring(segIndex+1)); // } for (Map.Entry<String, String> entry : tgs.entrySet()) { b.append(entry.getKey()).append("=").append(entry.getValue()).append(","); } b.deleteCharAt(b.length() - 1); return b.toString(); }