List of usage examples for java.util Map size
int size();
From source file:kenh.xscript.ScriptUtils.java
/** * Debug method for <code>Element</code> * @param element//from w w w.j a va 2 s . c om * @param level * @param stream */ private static final void debug_(Element element, int level, PrintStream stream) { String repeatStr = " "; String prefix = StringUtils.repeat(repeatStr, level); stream.print(prefix + "<" + element.getClass().getCanonicalName()); // Attribute output Map<String, String> attributes = element.getAttributes(); if (attributes != null && attributes.size() > 0) { Set<String> keys = attributes.keySet(); for (String key : keys) { stream.print(" " + key + "=\"" + attributes.get(key) + "\""); } } Vector<Element> children = element.getChildren(); String text = element.getText(); if ((children == null || children.size() == 0) && StringUtils.isBlank(text)) { stream.println("/>"); return; } else { stream.println(">"); // child elements if (children != null && children.size() > 0) { for (Element child : children) { debug_(child, level + 1, stream); } } // text/context if (StringUtils.isNotBlank(text)) { stream.println(prefix + repeatStr + "<![CDATA[" + text + "]]>"); } stream.println(prefix + "</" + element.getClass().getCanonicalName() + ">"); } }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServices.java
static void waitForSchemaVersions(Cassandra.Client client, String tableName, int schemaTimeoutMillis) throws InvalidRequestException, TException { long start = System.currentTimeMillis(); long sleepTime = INITIAL_SLEEP_TIME; Map<String, List<String>> versions; do {/* w ww. j a v a 2s . c o m*/ versions = client.describe_schema_versions(); if (versions.size() <= 1) { return; } try { Thread.sleep(sleepTime); } catch (InterruptedException e) { throw Throwables.throwUncheckedException(e); } sleepTime = Math.min(sleepTime * 2, MAX_SLEEP_TIME); } while (System.currentTimeMillis() < start + schemaTimeoutMillis); StringBuilder sb = new StringBuilder(); sb.append(String.format( "Cassandra cluster cannot come to agreement on schema versions, after attempting to modify table %s.", tableName)); for (Entry<String, List<String>> version : versions.entrySet()) { sb.append(String.format("\nAt schema version %s:", version.getKey())); for (String node : version.getValue()) { sb.append(String.format("\n\tNode: %s", node)); } } sb.append("\nFind the nodes above that diverge from the majority schema " + "(or have schema 'UNKNOWN', which likely means they are down/unresponsive) " + "and examine their logs to determine the issue. Fixing the underlying issue and restarting Cassandra " + "should resolve the problem. You can quick-check this with 'nodetool describecluster'."); throw new IllegalStateException(sb.toString()); }
From source file:net.sf.groovyMonkey.dom.Utilities.java
public static boolean hasDOM(final String pluginID) { final Map<String, Object> dom = getDOM(pluginID); if (dom == null || dom.size() == 0) return false; return true;/* w w w .j a v a 2 s. c o m*/ }
From source file:org.springframework.xd.distributed.util.ServerProcessUtils.java
/** * Block the executing thread until all of the indicated process IDs * have been identified in the list of runtime containers as indicated * by the admin server. If an empty list is provided, the executing * thread will block until there are no containers running. * * @param template REST template used to communicate with the admin server * @param pids set of process IDs for the expected containers * @return map of process id to container id * @throws InterruptedException if the executing thread is interrupted * @throws java.lang.IllegalStateException if the number of containers identified * does not match the number of PIDs provided *//* w ww. jav a 2s. c o m*/ public static Map<Long, String> waitForContainers(SpringXDTemplate template, Set<Long> pids) throws InterruptedException, IllegalStateException { int pidCount = pids.size(); Map<Long, String> mapPidUuid = getRunningContainers(template); long expiry = System.currentTimeMillis() + 3 * 60000; while (mapPidUuid.size() != pidCount && System.currentTimeMillis() < expiry) { Thread.sleep(500); mapPidUuid = getRunningContainers(template); } if (mapPidUuid.size() == pidCount && mapPidUuid.keySet().containsAll(pids)) { return mapPidUuid; } Set<Long> missingPids = new HashSet<Long>(pids); missingPids.removeAll(mapPidUuid.keySet()); Set<Long> unexpectedPids = new HashSet<Long>(mapPidUuid.keySet()); unexpectedPids.removeAll(pids); StringBuilder builder = new StringBuilder(); if (!missingPids.isEmpty()) { builder.append("Admin server did not find the following container PIDs:").append(missingPids); } if (!unexpectedPids.isEmpty()) { if (builder.length() > 0) { builder.append("; "); } builder.append("Admin server found the following unexpected container PIDs:").append(unexpectedPids); } throw new IllegalStateException(builder.toString()); }
From source file:com.cloudant.sync.query.IndexCreator.java
/** * We don't support directions on field names, but they are an optimisation so * we can discard them safely.// ww w . j ava 2s . c o m */ protected static List<String> removeDirectionsFromFields(List<Object> fieldNames) { List<String> result = new ArrayList<String>(); for (Object field : fieldNames) { if (field instanceof Map) { Map specifier = (Map) field; if (specifier.size() == 1) { for (Object key : specifier.keySet()) { // This will iterate only once result.add((String) key); } } } else if (field instanceof String) { result.add((String) field); } } return result; }
From source file:gov.nih.nci.cabig.caaers.web.utils.WebUtils.java
public static void synchronzeErrorFields(Map<String, Boolean> m1, Map<String, Boolean> m2) { if (m1 == null || m2 == null) return;/*from w ww. ja v a2 s .c o m*/ if (m2.size() == 0) return; logger.debug("F: synchronzeErrorFields"); logger.debug("F: " + m1); logger.debug("F: " + m2); Iterator<String> it = m2.keySet().iterator(); while (it.hasNext()) { String key = it.next(); m1.put(key, Boolean.TRUE); logger.debug("F: This field copied from XML Rules Files to the Mandatory Fields Hashmap: " + key); } }
From source file:dm_p2.DBSCAN.java
public static void externalValidation(Map<Integer, Integer> givenMap, Map<Integer, Integer> ourMap) { int truthMatrix[][] = new int[givenMap.size()][givenMap.size()]; int clusterMatrix[][] = new int[givenMap.size()][givenMap.size()]; int SS = 0, SD = 0, DS = 0, DD = 0; for (int i = 0; i < truthMatrix.length; i++) { for (int j = 0; j < clusterMatrix.length; j++) { if (givenMap.get(i) == givenMap.get(j)) { truthMatrix[i][j] = truthMatrix[j][i] = 1; } else { truthMatrix[i][j] = truthMatrix[j][i] = 0; }//from ww w .ja v a 2s . co m if (ourMap.get(i) == ourMap.get(j)) { clusterMatrix[i][j] = clusterMatrix[j][i] = 1; } else { clusterMatrix[i][j] = clusterMatrix[j][i] = 0; } if (truthMatrix[i][j] == clusterMatrix[i][j] && truthMatrix[i][j] == 1) { SS++; } else if (truthMatrix[i][j] == clusterMatrix[i][j] && truthMatrix[i][j] == 0) { DD++; } else if ((truthMatrix[i][j] != clusterMatrix[i][j]) && (truthMatrix[i][j] == 0 && clusterMatrix[i][j] == 1)) { DS++; } else if ((truthMatrix[i][j] != clusterMatrix[i][j]) && (truthMatrix[i][j] == 1 && clusterMatrix[i][j] == 0)) { SD++; } } } System.out.println("External Index Validation : Rand Index = " + (SS + DD) / (double) (SS + SD + DS + DD)); System.out.println("External Index Validation : Jaccard Coefficient = " + (SS) / (double) (SS + SD + DS)); }
From source file:com.aol.advertising.qiao.util.ContextUtils.java
public static void resolvePropertyReferences(SingleSubnodeConfiguration singleNode) throws BeansException, ClassNotFoundException { Map<String, PropertyValue> map = singleNode.getProperties(); if (map == null || map.size() == 0) return;// w w w.j a va 2 s. c om ContextUtils.resolvePropertyReferences(map); }
From source file:edu.illinois.ncsa.springdata.Transaction.java
private static void getTransaction(StringBuilder sb, Thread thread) { Map<Transaction, Exception> transmap = transactions.get(thread); if (transmap == null) { sb.append("\tThere are no open transactions.\n"); } else {//from w w w .jav a 2 s . co m sb.append(String.format("\tThere are %d open transactions : \n", transmap.size())); int i = 1; for (Entry<Transaction, Exception> entry : transmap.entrySet()) { StackTraceElement[] elems = entry.getValue().getStackTrace(); for (int j = 0; j < elems.length; j++) { if (!elems[j].toString().startsWith("edu.illinois.ncsa.springdata.Transaction")) { sb.append(String.format("\t[%2d] created at %s\n", i++, elems[j].toString())); break; } } } } }
From source file:com.myGengo.alfresco.utils.MyGengoUtils.java
public static BatchProcessWorkProvider<MyGengoJobBatchEntry> getTranslationsProvider( final Map<MyGengoAccount, Collection<NodeRef>> myGengoJobs) { return new BatchProcessWorkProvider<MyGengoJobBatchEntry>() { private boolean done; public synchronized int getTotalEstimatedWorkSize() { return myGengoJobs.size(); }/*from w w w. j a v a 2 s. c o m*/ public synchronized Collection<MyGengoJobBatchEntry> getNextWork() { if (done) { // if our set was returned before then return an empty list to notify the batch processor/worker that we don't have any more nodes... return Collections.emptyList(); } else { done = true; Collection<MyGengoJobBatchEntry> entries = new ArrayList<MyGengoJobBatchEntry>( getTotalEstimatedWorkSize()); Set<MyGengoAccount> accounts = myGengoJobs.keySet(); for (MyGengoAccount myGengoAccount : accounts) { MyGengoJobBatchEntry entry = new MyGengoJobBatchEntry(myGengoAccount, myGengoJobs.get(myGengoAccount)); entries.add(entry); } return entries; } } }; }