List of usage examples for java.util Map size
int size();
From source file:com.linecorp.armeria.server.docs.Specification.java
static Specification forServiceClasses(Map<Class<?>, Iterable<EndpointInfo>> map, Map<Class<?>, ? extends TBase<?, ?>> sampleRequests) { requireNonNull(map, "map"); final List<ServiceInfo> services = new ArrayList<>(map.size()); final Set<ClassInfo> classes = new HashSet<>(); map.forEach((serviceClass, endpoints) -> { try {//w ww .java 2s .c o m final ServiceInfo service = ServiceInfo.of(serviceClass, endpoints, sampleRequests); services.add(service); classes.addAll(service.classes().values()); } catch (ClassNotFoundException e) { throw new RuntimeException("unable to initialize Specification", e); } }); return new Specification(services, classes); }
From source file:Main.java
/** * Safely calculates a map length./* w w w . j a v a 2 s. c om*/ * * @param map * map to check * @return real map length or <code>0</code> if reference is <code>null</code> */ public static int length(final Map<?, ?> map) { return map != null ? map.size() : 0; }
From source file:com.ykun.commons.utils.http.HttpClientUtils.java
/** * ??//w w w .java2s. com */ private static List<NameValuePair> map2List(Map<String, String> params) { List<NameValuePair> list = new ArrayList<NameValuePair>(); if (params != null && params.size() > 0) { Iterator<String> it = params.keySet().iterator(); while (it.hasNext()) { String name = it.next(); list.add(new BasicNameValuePair(name, params.get(name) == null ? EMPTY_STRING : params.get(name))); } } return list; }
From source file:org.vader.common.spring.TransactionScope.java
private static void registerSynchronization() { LOG.debug("Registers transaction synchronization"); TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { @Override/*from w w w . j av a2 s . com*/ public void suspend() { LOG.debug("Push new transaction scope"); SCOPES.get().push(new HashMap<String, ScopeEntry>()); } @Override public void resume() { LOG.debug("Pop old transaction scope"); SCOPES.get().pop(); } @Override public void afterCompletion(int status) { final Map<String, ScopeEntry> scope = getCurrentScope(); LOG.debug("Destroying {} beans", scope.size()); for (Map.Entry<String, ScopeEntry> entry : scope.entrySet()) { for (Runnable runnable : entry.getValue().getCallbacks()) { LOG.debug("Executes destruction callback for bean={}", entry.getKey()); runnable.run(); } } scope.clear(); LOG.debug("Destruction completed"); } }); }
From source file:net.ontopia.topicmaps.utils.ltm.LTMTemplateImporter.java
/** * PUBLIC: Imports an LTM fragment with references to parameter values * specified externally.// ww w.j av a 2 s . c o m * @param topicmap The topic map to import the LTM into. * @param ltm The LTM fragment. * @param parameters The %foo% parameters referenced from the LTM. * @return A Map containing references to the %new% topics created. */ public static Map<String, TopicIF> read(TopicMapIF topicmap, String ltm, Map<String, Object> parameters) throws IOException { // wrap parameters with translation/quoting/ID-creating map ParameterWrapper parawrapper = new ParameterWrapper(parameters, topicmap); // produce the full LTM using the wrapper and parameters String tmp = StringTemplateUtils.replace(ltm, parawrapper); // then do the actual import LocatorIF base = topicmap.getStore().getBaseAddress(); LTMTopicMapReader reader = new LTMTopicMapReader(new StringReader(tmp), base); reader.importInto(topicmap); // turn ID map into topic map Map<String, String> newids = parawrapper.getNewIds(); Map<String, TopicIF> newtopics = new HashMap<String, TopicIF>(newids.size()); Iterator<String> it = newids.keySet().iterator(); while (it.hasNext()) { String key = it.next(); String id = newids.get(key); newtopics.put(key, (TopicIF) topicmap.getObjectByItemIdentifier(base.resolveAbsolute("#" + id))); } return newtopics; }
From source file:com.glaf.activiti.util.ExecutionUtils.java
public static void executeUpdate(DelegateExecution execution, Expression sql) { CommandContext commandContext = Context.getCommandContext(); ExecutionEntity executionEntity = commandContext.getExecutionEntityManager() .findExecutionById(execution.getId()); String processDefinitionId = executionEntity.getProcessDefinitionId(); ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessDefinitionEntityManager() .findProcessDefinitionById(processDefinitionId); String processName = processDefinitionEntity.getKey(); Map<String, Object> params = new java.util.HashMap<String, Object>(); Map<String, Object> variables = execution.getVariables(); if (variables != null && variables.size() > 0) { Iterator<String> iterator = variables.keySet().iterator(); while (iterator.hasNext()) { String variableName = iterator.next(); if (params.get(variableName) == null) { Object value = execution.getVariable(variableName); params.put(variableName, value); }// w w w .jav a2 s .com } } params.put(Constants.BUSINESS_KEY, execution.getProcessBusinessKey()); params.put("processInstanceId", execution.getProcessInstanceId()); params.put("processDefinitionId", processDefinitionEntity.getId()); params.put("processName", processName); if (sql != null) { String sqlx = sql.getExpressionText(); if (sqlx.indexOf("#{tableName}") != -1) { String tableName = (String) execution.getVariable("tableName"); if (StringUtils.isNotEmpty(tableName)) { sqlx = StringTools.replace(sqlx, "#{tableName}", tableName); } } else if (sqlx.indexOf("${tableName}") != -1) { String tableName = (String) execution.getVariable("tableName"); if (StringUtils.isNotEmpty(tableName)) { sqlx = StringTools.replace(sqlx, "${tableName}", tableName); } } sqlx = StringTools.replaceIgnoreCase(sqlx, "${", "#{"); logger.debug(sqlx); logger.debug(params); params.put("updateSql", sqlx); try { commandContext.getDbSqlSession().getSqlSession().update("updateSql", params); } catch (Exception ex) { logger.error(sqlx); logger.error(params); throw new RuntimeException(ex.getMessage()); } } }
From source file:RenderingUtils.java
private static Map installDesktopHints(Graphics2D g2) { Map oldRenderingHints = null; Map desktopHints = desktopHints(g2); if (desktopHints != null && !desktopHints.isEmpty()) { oldRenderingHints = new HashMap(desktopHints.size()); RenderingHints.Key key; for (Iterator i = desktopHints.keySet().iterator(); i.hasNext();) { key = (RenderingHints.Key) i.next(); oldRenderingHints.put(key, g2.getRenderingHint(key)); }//from ww w . j av a2 s .com g2.addRenderingHints(desktopHints); } return oldRenderingHints; }
From source file:io.apiman.cli.util.DeclarativeUtil.java
/** * Load the Declaration from the given Path, using the mapper provided. * * @param path the Path to the declaration * @param mapper the Mapper to use//from ww w . j a va2 s. com * @param properties property placeholders to resolve * @return the Declaration */ public static Declaration loadDeclaration(Path path, ObjectMapper mapper, Collection<String> properties) { final Map<String, String> parsedProperties = BeanUtil.parseReplacements(properties); try (InputStream is = Files.newInputStream(path)) { String fileContents = CharStreams.toString(new InputStreamReader(is)); LOGGER.trace("Declaration file raw: {}", fileContents); Declaration declaration = loadDeclaration(mapper, fileContents, parsedProperties); // check for the presence of shared properties in the declaration final Map<String, String> sharedProperties = ofNullable(declaration.getShared()) .map(SharedItems::getProperties).orElse(Collections.emptyMap()); if (sharedProperties.size() > 0) { LOGGER.trace("Resolving {} shared placeholders", sharedProperties.size()); parsedProperties.putAll(sharedProperties); // this is not very efficient, as it requires parsing the declaration twice declaration = loadDeclaration(mapper, fileContents, parsedProperties); } return declaration; } catch (IOException e) { throw new DeclarativeException(e); } }
From source file:com.volley.air.toolbox.HttpClientStack.java
@SuppressWarnings("unused") private static List<NameValuePair> getPostParameterPairs(Map<String, String> postParams) { List<NameValuePair> result = new ArrayList<>(postParams.size()); for (Map.Entry<String, String> entry : postParams.entrySet()) { result.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); }// w w w . jav a 2s . c o m return result; }
From source file:fr.liglab.jlcm.RunPLCM.java
public static void standalone(CommandLine cmd) { String[] args = cmd.getArgs(); int minsup = Integer.parseInt(args[1]); MemoryPeakWatcherThread memoryWatch = null; String outputPath = null;/* w ww. ja va 2 s . c o m*/ if (args.length >= 3) { outputPath = args[2]; } if (cmd.hasOption('m')) { memoryWatch = new MemoryPeakWatcherThread(); memoryWatch.start(); } chrono = System.currentTimeMillis(); ExplorationStep initState; Map<Integer, String> itemsIdMap = null; if (cmd.hasOption('S')) { FileWithStringIDsIterable reader = new FileWithStringIDsIterable(args[0]); initState = new ExplorationStep(minsup, reader); reader.close(); Map<String, Integer> rawMap = reader.getMap(); itemsIdMap = new HashMap<Integer, String>(rawMap.size()); for (Entry<String, Integer> entry : rawMap.entrySet()) { itemsIdMap.put(entry.getValue(), entry.getKey()); } } else { initState = new ExplorationStep(minsup, args[0]); } long loadingTime = System.currentTimeMillis() - chrono; System.err.println("Dataset loaded in " + loadingTime + "ms"); if (cmd.hasOption('V')) { ExplorationStep.verbose = true; ExplorationStep.ultraVerbose = true; } else if (cmd.hasOption('v')) { ExplorationStep.verbose = true; } int nbThreads = Runtime.getRuntime().availableProcessors(); if (cmd.hasOption('t')) { nbThreads = Integer.parseInt(cmd.getOptionValue('t')); } PatternsCollector collector = instanciateCollector(cmd, outputPath, nbThreads, itemsIdMap); PLCM miner = new PLCM(collector, nbThreads, new ProgressWatcherThread()); chrono = System.currentTimeMillis(); miner.lcm(initState); chrono = System.currentTimeMillis() - chrono; Map<String, Long> additionalCounters = new HashMap<String, Long>(); additionalCounters.put("miningTime", chrono); additionalCounters.put("outputtedPatterns", collector.close()); additionalCounters.put("loadingTime", loadingTime); additionalCounters.put("avgPatternLength", (long) collector.getAveragePatternLength()); if (memoryWatch != null) { memoryWatch.interrupt(); additionalCounters.put("maxUsedMemory", memoryWatch.getMaxUsedMemory()); } System.err.println(miner.toString(additionalCounters)); }