List of usage examples for java.util Map size
int size();
From source file:com.surfs.storage.common.util.HttpUtils.java
public static String getUrlForParams(String ip, String port, String servicePath, String serviceName, Map<String, String> args) throws UnsupportedEncodingException { StringBuilder params = new StringBuilder(); params.append("http://"); params.append(ip);/*from w w w . ja va 2 s. c om*/ params.append(":"); params.append(port); params.append(servicePath); params.append(serviceName); params.append("?"); int size = args.size(); // args for (Entry<String, String> arg : args.entrySet()) { --size; params.append(arg.getKey() + "="); params.append(URLEncoder.encode(arg.getValue(), "UTF-8")); if (size != 0) params.append("&"); } return params.toString(); }
From source file:com.p5solutions.core.utils.Comparison.java
/** * Checks if a map is empty or null./*from w w w . ja va 2 s. co m*/ * * @param map the map * @return true, if is empty or null */ public static boolean isEmptyOrNull(Map<?, ?> map) { if (isNull(map)) { return true; } if (map.size() == 0) { return true; } return false; }
From source file:org.jhk.pulsing.web.service.prod.helper.PulseServiceUtil.java
public static Map<Long, String> processTrendingPulseSubscribe(Set<String> tps, ObjectMapper objMapper) { @SuppressWarnings("unchecked") Map<Long, String> tpSubscriptions = Collections.EMPTY_MAP; final Map<String, Integer> count = new HashMap<>(); tps.parallelStream().forEach(tpsIdValueCounts -> { try {/*from w w w . ja va2 s . com*/ _LOGGER.debug( "PulseServiceUtil.processTrendingPulseSubscribe: trying to convert " + tpsIdValueCounts); Map<String, Integer> converted = objMapper.readValue(tpsIdValueCounts, _TRENDING_PULSE_SUBSCRIPTION_TYPE_REF); _LOGGER.debug("PulseServiceUtil.processTrendingPulseSubscribe: sucessfully converted " + converted.size()); //Structure is <id>0x07<value>0x13<timestamp> -> count; i.e. {"10020x07Mocked 10020x13<timestamp>" -> 1} //Need to split the String content, gather the count for the searched interval //and return the sorted using Java8 stream //TODO impl better Map<String, Integer> computed = converted.entrySet().stream().reduce(new HashMap<String, Integer>(), (Map<String, Integer> mapped, Entry<String, Integer> entry) -> { String[] split = entry.getKey() .split(CommonConstants.TIME_INTERVAL_PERSIST_TIMESTAMP_DELIM); Integer value = entry.getValue(); mapped.compute(split[0], (key, val) -> { return val == null ? value : val + value; }); return mapped; }, (Map<String, Integer> result, Map<String, Integer> aggregated) -> { result.putAll(aggregated); return result; }); computed.entrySet().parallelStream().forEach(entry -> { Integer value = entry.getValue(); count.compute(entry.getKey(), (key, val) -> { return val == null ? value : val + value; }); }); } catch (Exception cException) { cException.printStackTrace(); } }); if (count.size() > 0) { tpSubscriptions = count.entrySet().stream() .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) .collect(Collectors.toMap( entry -> Long.parseLong( entry.getKey().split(CommonConstants.TIME_INTERVAL_ID_VALUE_DELIM)[0]), entry -> entry.getKey().split(CommonConstants.TIME_INTERVAL_ID_VALUE_DELIM)[1], (x, y) -> { throw new AssertionError(); }, LinkedHashMap::new)); } return tpSubscriptions; }
From source file:org.springframework.data.solr.server.support.SolrServerUtils.java
private static LBHttpSolrServer cloneSolr4LBHttpServer(SolrServer solrServer, String core) throws MalformedURLException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Map<String, ?> map = readField(solrServer, "aliveServers"); String[] servers = new String[map.size()]; int i = 0;// w ww . j ava2s.co m for (String key : map.keySet()) { servers[i] = appendCoreToBaseUrl(key, core); i++; } Boolean isInternalCient = readField(solrServer, "clientIsInternal"); if (isInternalCient != null && !isInternalCient) { HttpClient clientToUse = readAndCloneHttpClient(solrServer); return new LBHttpSolrServer(clientToUse, servers); } return new LBHttpSolrServer(servers); }
From source file:com.adaptris.core.RetryMessageErrorHandlerImp.java
protected static Map<String, Workflow> filterStarted(Map<String, Workflow> workflows) { Map<String, Workflow> result = new HashMap<>(workflows.size()); for (Map.Entry<String, Workflow> entry : workflows.entrySet()) { if (StartedState.getInstance().equals(entry.getValue().retrieveComponentState())) { result.put(entry.getKey(), entry.getValue()); }/*from w w w.j a v a 2 s .com*/ } return result; }
From source file:com.google.appengine.tools.mapreduce.impl.ShardStateEntity.java
/** * Gets all shard states corresponding to a particular Job ID *///from w ww . jav a 2s. c o m public static <K, V, OK, OV> List<ShardStateEntity<K, V, OK, OV>> getShardStates( MapperStateEntity<K, V, OK, OV> mapperState) { Collection<Key> keys = new ArrayList<Key>(); for (int i = 0; i < mapperState.getShardCount(); ++i) { keys.add(createKey(mapperState.getJobID(), i)); } Map<Key, Entity> map = getDatastoreService().get(keys); List<ShardStateEntity<K, V, OK, OV>> shardStates = new ArrayList<ShardStateEntity<K, V, OK, OV>>( map.size()); for (Key key : keys) { Entity entity = map.get(key); if (entity != null) { ShardStateEntity<K, V, OK, OV> shardState = new ShardStateEntity<K, V, OK, OV>(entity); shardStates.add(shardState); } } return shardStates; }
From source file:com.linkedin.pinot.controller.helix.core.UAutoRebalancer.java
public static boolean isTheSameMapping(Map oldMapping, Map nMapping) { if (oldMapping.size() != nMapping.size()) return false; Map<String, Object> total = new HashedMap(oldMapping); total.putAll(nMapping);/*from ww w . j a v a2s .com*/ if (total.size() != oldMapping.size()) return false; Set<Boolean> result = new HashSet<Boolean>(); for (Object oKey : oldMapping.keySet()) { Object oValue = oldMapping.get(oKey); if (oValue instanceof String) { result.add(oValue.equals(nMapping.get(oValue))); } else if (oValue instanceof Map) { result.add(isTheSameMapping((Map) oValue, (Map) nMapping.get(oKey))); } } if (result.size() != 1) return false; return true; }
From source file:com.langnatech.util.AssertUtil.java
/** * Assert that a Map has entries; that is, it must not be {@code null} and must have at least one entry. <pre * class="code">Assert.notEmpty(map, "Map must have entries");</pre> * /*from www. j a va 2s. co m*/ * @param map the map to check * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the map is {@code null} or has no entries */ public static void notEmpty(Map<?, ?> map, String message) { if (map == null || map.size() == 0) { throw new IllegalArgumentException(message); } }
From source file:com.microsoft.azure.shortcuts.resources.samples.ProvidersSample.java
public static void test(Subscription subscription) throws Exception { // List provider namespaces Map<String, Provider> providers = subscription.providers().asMap(); System.out//from ww w. j av a 2s.c om .println(String.format("Provider namespaces: %s\t", StringUtils.join(providers.keySet(), "\n\t"))); // List providers for (Provider provider : providers.values()) { System.out.println(provider.id() + " - " + provider.registrationState()); } if (providers.size() > 0) { // Get information about a specific provider Provider provider = subscription.providers("microsoft.classicstorage"); System.out.println(String.format( "Found provider: %s\n" + "\tRegistration State: %s\n" + "\tAPI versions for resource types:", provider.id(), provider.registrationState())); for (ResourceType t : provider.resourceTypes().values()) { System.out.println(String.format("\t\t%s: %s", t.id(), StringUtils.join(t.apiVersions(), ", "))); } // Get latest API version for a specific resource type String resourceType = "storageAccounts"; System.out.println(String.format("\n\t\tLatest version for type %s: %s", resourceType, provider.resourceTypes().get(resourceType).latestApiVersion())); // Get latest API version for a specific resource type - shortcut System.out.println(String.format("\n\t\tLatest version for type %s: %s", resourceType, provider.resourceTypes(resourceType).latestApiVersion())); } }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo.java
public static Map<String, String> getSortedMap(Map<String, String> hmap, Comparator<String[]> comparator, VitroRequest vreq) {// w ww . j a v a 2 s . c o m // first make temporary list of String arrays holding both the key and its corresponding value, so that the list can be sorted with a decent comparator List<String[]> objectsToSort = new ArrayList<String[]>(hmap.size()); for (String key : hmap.keySet()) { String[] x = new String[2]; x[0] = key; x[1] = hmap.get(key); objectsToSort.add(x); } //if no comparator is passed in, utilize MapPairsComparator if (comparator == null) { comparator = new MapPairsComparator(vreq); } Collections.sort(objectsToSort, comparator); HashMap<String, String> map = new LinkedHashMap<String, String>(objectsToSort.size()); for (String[] pair : objectsToSort) { map.put(pair[0], pair[1]); } return map; }