List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:Main.java
/** * Gather all the namespaces defined on a node * * @return//w w w . j a va 2 s. c o m */ public static Iterable<Entry<String, String>> getNamespaces(Element element) { TreeMap<String, String> map = new TreeMap<String, String>(); do { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); final String name = attr.getLocalName(); if (attr.getPrefix() != null) { if ("xmlns".equals(attr.getPrefix())) if (!map.containsKey(name)) map.put(name, attr.getValue()); } else if ("xmlns".equals(name)) { if (!map.containsKey("")) map.put("", attr.getValue()); } } if (element.getParentNode() == null || element.getParentNode().getNodeType() != Node.ELEMENT_NODE) break; element = (Element) element.getParentNode(); } while (true); return map.entrySet(); }
From source file:cfappserver.Bot.java
public static TreeMap<String, Integer> addToTree(String a, TreeMap<String, Integer> tm){ if(tm.containsKey(a))tm.put(a, 1+tm.get(a)); else tm.put(a, 1); return tm;// w w w . j a v a 2 s . c o m }
From source file:com.ettoremastrogiacomo.sktradingjava.starters.Temp.java
public static java.util.ArrayList<TreeSet<UDate>> timesegments(java.util.TreeSet<UDate> dates, long maxgapmsec) { java.util.TreeMap<Integer, TreeSet<UDate>> rank = new java.util.TreeMap<>(); java.util.TreeSet<UDate> t = new TreeSet<>(); java.util.ArrayList<TreeSet<UDate>> list = new ArrayList<>(); for (UDate d : dates) { if (t.isEmpty()) { t.add(d);//from ww w. j ava 2 s . co m } else if (d.diffmills(t.last()) > maxgapmsec) { rank.put(t.size(), t); list.add(t); t = new TreeSet<>(); } else { t.add(d); } } return list; }
From source file:cn.edu.sdnu.i.util.xauth.Xauth.java
public static String doMethod(String url) { // ?TreeMapparameters?????url? TreeMap<String, String> parameters = new TreeMap<String, String>(); // 1.consumerkeyapp???keykey??app?key parameters.put(Constants.ConsumerKeyParameter, consumerKey); Log.d("test1", "1.consumerKey:" + consumerKey); // 2.UUID??????? /*/*w ww . ja va 2 s. co m*/ * ?GUID * * * ??GUID???????10GUID? * ??? FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF */ UUID uuid = UUID.randomUUID(); // ????ws? String guid = uuid.toString(); // nonce parameters.put(Constants.NonceParameter, guid); Log.d("test1", "2.guid:" + guid); // 3.?Hmacsha1 parameters.put(Constants.SignatureMethodParameter, HMACSHA1SignatureType); Log.d("test1", "3.SignatureMethodParameter:" + HMACSHA1SignatureType); // 4. /* * * * * Unix???UTC??197011000??? ?2014/1/29 * 16:56:58UTC+8UTC2014/1/29 * 8:56:58?Unix160998565813909858181390985818 * ??60? */ parameters.put(Constants.TimestampParameter, Long.toString(System.currentTimeMillis() / 1000)); Log.d("test1", "4.TimestampParameter:" + Long.toString(System.currentTimeMillis() / 1000)); // 5.TokenKey parameters.put(Constants.TokenParameter, token); Log.d("test", "5.TokenKey:" + token); // 6.XAuth??1.0? parameters.put(Constants.VersionParameter, OAuthVersion); Log.d("test1", "6.VersionParameter:" + OAuthVersion); // ???? // ??StringBuffer?String??result StringBuffer resultBuffer = new StringBuffer(""); // http?statusresult Boolean status = TryRequestRemote(url, tokenSecret, parameters, resultBuffer); Log.d("test1", "7.http?statusresult:" + resultBuffer.toString()); return resultBuffer.toString(); }
From source file:io.fabric8.maven.core.config.ProcessorConfig.java
private static Map<String, TreeMap> mergeConfig(ProcessorConfig... processorConfigs) { Map<String, TreeMap> ret = new HashMap<>(); if (processorConfigs.length > 0) { // Reverse iteration order so that earlier entries have a higher precedence for (int i = processorConfigs.length - 1; i >= 0; i--) { ProcessorConfig processorConfig = processorConfigs[i]; if (processorConfig != null) { Map<String, TreeMap> config = processorConfig.config; if (config != null) { for (Map.Entry<String, TreeMap> entry : config.entrySet()) { TreeMap newValues = entry.getValue(); if (newValues != null) { TreeMap existing = ret.get(entry.getKey()); if (existing == null) { ret.put(entry.getKey(), new TreeMap(newValues)); } else { for (Map.Entry newValue : (Set<Map.Entry>) newValues.entrySet()) { existing.put(newValue.getKey(), newValue.getValue()); }//ww w. j a v a2s . c om } } } } } } } return ret.size() > 0 ? ret : null; }
From source file:cooccurrence.Omer_Levy.java
/** * Method that will extract top D singular values from CoVariance Matrix * It will then identify the corresponding columns from U and V and add it to new matrices * @param U/* ww w . j av a2s . c om*/ * @param V * @param coVariance * @param matrixUd * @param matrixVd * @param coVarD * @param indicesD */ private static void getTopD(RealMatrix U, RealMatrix V, RealMatrix coVariance, RealMatrix matrixUd, RealMatrix matrixVd, RealMatrix coVarD, ArrayList<Integer> indicesD) { TreeMap<Double, Set<Integer>> tmap = new TreeMap<>(); for (int i = 0; i < coVariance.getRowDimension(); i++) { double val = coVariance.getEntry(i, i); if (tmap.containsKey(val)) { Set<Integer> temp = tmap.get(val); temp.add(i); } else { Set<Integer> temp = new HashSet<>(); temp.add(i); tmap.put(val, temp); } } Iterator iter = tmap.keySet().iterator(); while (iter.hasNext()) { Double val = (Double) iter.next(); Set<Integer> indices = tmap.get(val); for (int i = 0; i < indices.size(); i++) { Iterator iterIndices = indices.iterator(); while (iterIndices.hasNext()) { int index = (Integer) iterIndices.next(); indicesD.add(index); coVarD.addToEntry(index, index, val); matrixUd.setColumnVector(index, U.getColumnVector(index)); matrixVd.setColumnVector(index, V.getColumnVector(index)); } } } }
From source file:net.sf.keystore_explorer.crypto.signing.MidletSigner.java
/** * Sign a JAD file outputting the modified JAD to a different file. * * @param jadFile//from w ww. j a v a 2 s. co m * JAD file * @param outputJadFile * Output JAD file * @param jarFile * JAR file * @param privateKey * Private RSA key to sign with * @param certificateChain * Certificate chain for private key * @param certificateNumber * Certificate number * @throws IOException * If an I/O problem occurs while signing the MIDlet * @throws CryptoException * If a crypto problem occurs while signing the MIDlet */ public static void sign(File jadFile, File outputJadFile, File jarFile, RSAPrivateKey privateKey, X509Certificate[] certificateChain, int certificateNumber) throws IOException, CryptoException { Properties jadProperties = readJadFile(jadFile); Properties newJadProperties = new Properties(); // Copy over existing attrs (excepting digest and any certificates at // provided number) for (Enumeration enumPropNames = jadProperties.propertyNames(); enumPropNames.hasMoreElements();) { String propName = (String) enumPropNames.nextElement(); // Ignore digest attr if (propName.equals(MIDLET_JAR_RSA_SHA1_ATTR)) { continue; } // Ignore certificates at provided number if (propName.startsWith(MessageFormat.format(SUB_MIDLET_CERTIFICATE_ATTR, certificateNumber))) { continue; } newJadProperties.put(propName, jadProperties.getProperty(propName)); } // Get certificate attrs for (int i = 0; i < certificateChain.length; i++) { X509Certificate certificate = certificateChain[i]; String base64Cert = null; try { base64Cert = new String(Base64.encode(certificate.getEncoded())); } catch (CertificateEncodingException ex) { throw new CryptoException(res.getString("Base64CertificateFailed.exception.message"), ex); } String midletCertificateAttr = MessageFormat.format(MIDLET_CERTIFICATE_ATTR, certificateNumber, (i + 1)); newJadProperties.put(midletCertificateAttr, base64Cert); } // Get signed Base 64 SHA-1 digest of JAR file as attr byte[] signedJarDigest = signJarDigest(jarFile, privateKey); String base64SignedJarDigest = new String(Base64.encode(signedJarDigest)); newJadProperties.put(MIDLET_JAR_RSA_SHA1_ATTR, base64SignedJarDigest); // Sort properties alphabetically TreeMap<String, String> sortedJadProperties = new TreeMap<String, String>(); for (Enumeration names = newJadProperties.propertyNames(); names.hasMoreElements();) { String name = (String) names.nextElement(); String value = newJadProperties.getProperty(name); sortedJadProperties.put(name, value); } // Write out new JAD properties to JAD file FileWriter fw = null; try { fw = new FileWriter(outputJadFile); for (Iterator itrSorted = sortedJadProperties.entrySet().iterator(); itrSorted.hasNext();) { Map.Entry property = (Map.Entry) itrSorted.next(); fw.write(MessageFormat.format(JAD_ATTR_TEMPLATE, property.getKey(), property.getValue())); fw.write(CRLF); } } finally { IOUtils.closeQuietly(fw); } }
From source file:it.marcoberri.mbmeteo.action.Commons.java
public static TreeMap<String, Date> getDistinctTime() { final Datastore ds = MongoConnectionHelper.ds; final List<Date> datesResult = ds.getDB().getCollection("Meteolog").distinct("time"); final TreeMap<String, Date> dates = new TreeMap<String, Date>(); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); for (Date d : datesResult) { try {/*from www. j a v a 2s. com*/ dates.put(df.format(d), d); } catch (Exception e) { continue; } } return dates; }
From source file:io.fabric8.kit.enricher.api.EnrichersConfig.java
@SafeVarargs private static <P extends ProjectContext> Map<String, TreeMap<String, String>> mergeConfig( EnrichersConfig<P>... enrichersConfigs) { Map<String, TreeMap<String, String>> ret = new HashMap<>(); if (enrichersConfigs.length > 0) { // Reverse iteration order so that earlier entries have a higher precedence for (int i = enrichersConfigs.length - 1; i >= 0; i--) { EnrichersConfig<P> enrichersConfig = enrichersConfigs[i]; if (enrichersConfig != null) { if (enrichersConfig.config != null) { for (Map.Entry<String, TreeMap<String, String>> entry : enrichersConfig.config.entrySet()) { TreeMap<String, String> newValues = entry.getValue(); if (newValues != null) { TreeMap<String, String> existing = ret.get(entry.getKey()); if (existing == null) { ret.put(entry.getKey(), new TreeMap<>(newValues)); } else { for (Map.Entry<String, String> newValue : newValues.entrySet()) { existing.put(newValue.getKey(), newValue.getValue()); }// w ww .j a v a 2 s.c o m } } } } } } } return ret.size() > 0 ? ret : null; }
From source file:acp.sdk.SDKUtil.java
/** * Map???Keyascii???key1=value1&key2=value2? ????signature * /*from w ww . j a v a 2 s . c o m*/ * @param data * Map? * @return ? */ public static String coverMap2String(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(); if (SDKConstants.param_signature.equals(en.getKey().trim())) { continue; } tree.put(en.getKey(), en.getValue()); } it = tree.entrySet().iterator(); StringBuffer sf = new StringBuffer(); while (it.hasNext()) { Entry<String, String> en = it.next(); sf.append(en.getKey() + SDKConstants.EQUAL + en.getValue() + SDKConstants.AMPERSAND); } return sf.substring(0, sf.length() - 1); }