List of usage examples for java.util Map size
int size();
From source file:com.hisuntech.ArchOnlineSchoolAuth.test.aop.MyTest.java
/** * MAP??NameValuePair/* w ww .j av a2s . com*/ * @param properties MAP * @return NameValuePair */ private static NameValuePair[] generatNameValuePair(Map<String, String> properties) { NameValuePair[] nameValuePair = new NameValuePair[properties.size()]; int i = 0; for (Map.Entry<String, String> entry : properties.entrySet()) { nameValuePair[i++] = new NameValuePair(entry.getKey(), entry.getValue()); } return nameValuePair; }
From source file:Main.java
/** * Utility method for building up URL param string. * //from w ww . j av a2s . c om * @param params * @return URL parameter string */ private static String buildParamString(Map<String, String> params) { StringBuffer paramBuf = new StringBuffer(); if (params != null && params.size() > 0) { paramBuf.append('?'); Iterator<Map.Entry<String, String>> iter = params.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, String> param = (Map.Entry<String, String>) iter.next(); paramBuf.append(param.getKey() + "=" + param.getValue()); if (iter.hasNext()) { paramBuf.append('&'); } } } Log.i("PARAM STRING CHECK", paramBuf.toString()); return paramBuf.toString(); }
From source file:Main.java
public static String buildString(Map<String, String> params) { if (params == null || params.size() == 0) return null; StringBuilder sb = new StringBuilder(); Set<Entry<String, String>> setEntry = params.entrySet(); for (Entry<String, String> entry : setEntry) { sb.append(entry.getKey());//from w w w. j a v a 2s . c o m sb.append("="); try { sb.append(getUrlEncode(entry.getValue(), "utf-8") + "&"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
From source file:Main.java
/** * /*from www .j a va 2s . co m*/ * @param pressingLength length of pause between clicks * @return mathExpectation values list */ public static List<Double> mathExpectation(Map<String, Long> pressingLength) { List<Double> mathExpectation = new ArrayList<Double>(); int N = pressingLength.size() - 1; //math Expectation double expectation = 0.0; for (String key : pressingLength.keySet()) { for (String k : pressingLength.keySet()) { if (!k.equals(key)) { expectation += pressingLength.get(k); } } mathExpectation.add(expectation / N); expectation = 0.0; } return mathExpectation; }
From source file:Main.java
public static Process runWithEnv(String command, ArrayList<String> customAddedEnv, String baseDirectory) throws IOException { Map<String, String> environment = System.getenv(); String[] envArray = new String[environment.size() + (customAddedEnv != null ? customAddedEnv.size() : 0)]; int i = 0;//ww w . ja v a2 s . c o m for (Map.Entry<String, String> entry : environment.entrySet()) { envArray[i++] = entry.getKey() + "=" + entry.getValue(); } if (customAddedEnv != null) { for (String entry : customAddedEnv) { envArray[i++] = entry; } } Process process; if (baseDirectory == null) { process = Runtime.getRuntime().exec(command, envArray, null); } else { process = Runtime.getRuntime().exec(command, envArray, new File(baseDirectory)); } return process; }
From source file:org.eclipse.swordfish.core.configuration.xml.SaxParsingPrototype.java
private static Map<String, String> flatten(Map<String, List<String>> props) { Map<String, String> ret = new HashMap<String, String>(props.size()); for (String key : props.keySet()) { List<String> values = props.get(key); Assert.state(values.size() > 0); if (values.size() == 1) { ret.put(key, values.get(0)); } else {//from w w w . j a va 2s . c om for (int i = 0; i < values.size(); i++) { ret.put(key + "{" + (i + 1) + "}", values.get(i)); } } } return ret; }
From source file:com.datasalt.utils.commons.URLUtils.java
/** * build a url from a hashtable and a base. Not tested but may be useful for building urls from * other data. Also might be usefull for testing later on . * @param base//w w w . jav a 2 s .c om * @param pars */ @SuppressWarnings("rawtypes") public static String getUrlFromParameters(String base, Map pars) { StringBuffer s = new StringBuffer(base); if (pars.size() > 0) s.append("?"); for (Object k : pars.keySet()) { s.append(k); s.append("="); s.append(pars.get(k)); } return s.toString(); }
From source file:Maps.java
public static <K, V> Map<K, V> normalizeUnmodifiable(Map<K, V> map) { if (map.size() < 2) { return normalize(map); } else {/*from w w w . j a v a 2 s . co m*/ // TODO: implement an UnmodifiableHashMap? return Collections.unmodifiableMap(normalize(map)); } }
From source file:Main.java
public static void dumpWeightedGraph(Map<Integer, Map<Integer, Integer>> weightedGraph) { System.out.println("Start of dumping weighted graph... graphSize: " + weightedGraph.size()); for (int vertexId : weightedGraph.keySet()) { // System.out.println("vertexId: " + vertexId); Map<Integer, Integer> weightedNeighbors = weightedGraph.get(vertexId); for (int neighborId : weightedNeighbors.keySet()) { if (weightedNeighbors.get(neighborId) > 1) { System.out.println( "w(" + vertexId + ", " + neighborId + "): " + weightedNeighbors.get(neighborId)); }//from w w w .ja v a2 s .c o m } } System.out.println("End of dumping weighted graph..."); }
From source file:com.extjs.djn.spring.loader.SpringLoaderHelper.java
/** * Return the spring instance of a bean from is className. * //from w w w .ja v a 2 s.c o m * Return null if no bean found. * * @param instanceClass * * @return */ public static Object getBeanOfType(Class<?> instanceClass) { Object bean = null; Map<String, Object> beansMap = getBeansOfType(instanceClass); if (beansMap.size() > 1) { throw new IllegalStateException("Only one instance of " + instanceClass + "is expected"); } else if (beansMap.size() == 1) { bean = beansMap.values().iterator().next(); } return bean; }