List of usage examples for java.util Map size
int size();
From source file:de.tudarmstadt.ukp.clarin.webanno.brat.curation.AgreementUtils.java
public static AgreementResult getCohenKappaAgreement(DiffResult aDiff, String aType, String aFeature, Map<String, List<JCas>> aCasMap) { if (aCasMap.size() != 2) { throw new IllegalArgumentException("CAS map must contain exactly two CASes"); }/* w w w . j a v a2s .co m*/ AgreementResult agreementResult = AgreementUtils.makeStudy(aDiff, aType, aFeature, aCasMap); try { IAgreementMeasure agreement = new CohenKappaAgreement(agreementResult.study); if (agreementResult.study.getItemCount() > 0) { agreementResult.setAgreement(agreement.calculateAgreement()); } else { agreementResult.setAgreement(Double.NaN); } return agreementResult; } catch (RuntimeException e) { // FIXME AgreementUtils.dumpAgreementStudy(System.out, agreementResult); throw e; } }
From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java
public static URI appendQueryParameters(URI uri, Map<String, String> parameters) { Validate.notNull(uri, "uri"); Validate.notNull(parameters, "parameters"); List<NameValuePair> pairs = new ArrayList<NameValuePair>(parameters.size()); for (Map.Entry<String, String> entry : parameters.entrySet()) { pairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); }// www . j a va 2 s. c o m URIBuilder uriBuilder = new URIBuilder(uri); uriBuilder.addParameters(pairs); try { return uriBuilder.build(); } catch (URISyntaxException e) { throw new IllegalArgumentException("failed to add parameters to uri", e); } }
From source file:com.glaf.core.entity.mybatis.MyBatisSessionFactory.java
protected static void reloadSessionFactory() { long start = System.currentTimeMillis(); Set<String> mappers = new HashSet<String>(); Configuration configuration = new Configuration(); String path = SystemProperties.getConfigRootPath() + "/conf/mapper"; try {/* www .j a v a 2 s. c om*/ Map<String, byte[]> dataMap = getLibMappers(); for (int i = 0; i < dataMap.size(); i++) { Set<Entry<String, byte[]>> entrySet = dataMap.entrySet(); for (Entry<String, byte[]> entry : entrySet) { String key = entry.getKey(); if (key.indexOf("/") != -1) { key = key.substring(key.lastIndexOf("/"), key.length()); } byte[] bytes = entry.getValue(); String filename = path + "/" + key; try { FileUtils.save(filename, bytes); } catch (Exception ex) { ex.printStackTrace(); } } } List<String> list = getClassPathMappers(); for (int i = 0; i < list.size(); i++) { Resource mapperLocation = new FileSystemResource(list.get(i)); try { XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(), configuration, mapperLocation.toString(), configuration.getSqlFragments()); xmlMapperBuilder.parse(); mappers.add(mapperLocation.getFilename()); } catch (Exception ex) { ex.printStackTrace(); throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", ex); } finally { ErrorContext.instance().reset(); } } File dir = new File(path); if (dir.exists() && dir.isDirectory()) { File contents[] = dir.listFiles(); if (contents != null) { for (int i = 0; i < contents.length; i++) { if (contents[i].isFile() && contents[i].getName().endsWith("Mapper.xml")) { if (mappers.contains(contents[i].getName())) { continue; } Resource mapperLocation = new FileSystemResource(contents[i]); try { XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder( mapperLocation.getInputStream(), configuration, mapperLocation.toString(), configuration.getSqlFragments()); xmlMapperBuilder.parse(); } catch (Exception ex) { ex.printStackTrace(); throw new NestedIOException( "Failed to parse mapping resource: '" + mapperLocation + "'", ex); } finally { ErrorContext.instance().reset(); } } } } } sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); } catch (Exception ex) { ex.printStackTrace(); } long time = System.currentTimeMillis() - start; System.out.println("SessionFactory" + (time)); }
From source file:org.apache.gobblin.utils.HttpUtils.java
/** * Given a url template, interpolate with keys and build the URI after adding query parameters * * <p>/*from w w w . j a v a 2 s . com*/ * With url template: http://test.com/resource/(urn:${resourceId})/entities/(entity:${entityId}), * keys: { "resourceId": 123, "entityId": 456 }, queryParams: { "locale": "en_US" }, the outpuT URI is: * http://test.com/resource/(urn:123)/entities/(entity:456)?locale=en_US * </p> * * @param urlTemplate url template * @param keys data map to interpolate url template * @param queryParams query parameters added to the url * @return a uri */ public static URI buildURI(String urlTemplate, Map<String, String> keys, Map<String, String> queryParams) { // Compute base url String url = urlTemplate; if (keys != null && keys.size() != 0) { url = StrSubstitutor.replace(urlTemplate, keys); } try { URIBuilder uriBuilder = new URIBuilder(url); // Append query parameters if (queryParams != null && queryParams.size() != 0) { for (Map.Entry<String, String> entry : queryParams.entrySet()) { uriBuilder.addParameter(entry.getKey(), entry.getValue()); } } return uriBuilder.build(); } catch (URISyntaxException e) { throw new RuntimeException("Fail to build uri", e); } }
From source file:hr.fer.tel.rovkp.homework03.task01.JokesCollection.java
private static float[][] createMatrix(Map<Integer, String> entries, StandardAnalyzer analyzer, Directory index) throws NumberFormatException, IOException, ParseException { int hitsNo = entries.size(); float[][] similarityMatrix = new float[hitsNo][hitsNo]; int i = 0;/* w w w . j a va 2 s .co m*/ for (Entry<Integer, String> entry : entries.entrySet()) { Query query = new QueryParser("text", analyzer).parse(QueryParser.escape(entry.getValue())); IndexReader reader = DirectoryReader.open(index); IndexSearcher searcher = new IndexSearcher(reader); TopDocs docs = searcher.search(query, hitsNo); for (ScoreDoc hit : docs.scoreDocs) { Document document = reader.document(hit.doc); int docId = Integer.parseInt(document.get("ID")); int docIndex = docId - 1; similarityMatrix[i][docIndex] = hit.score; } i++; } return similarityMatrix; }
From source file:com.hurence.logisland.plugin.PluginManager.java
private static void listPlugins() { Map<ModuleInfo, List<String>> moduleMapping = findPluginMeta(); System.out.println();/*from ww w . j av a 2 s .c o m*/ System.out.println("Listing details for " + moduleMapping.size() + " installed modules."); System.out.println("=============================================================="); System.out.println(); moduleMapping.forEach((c, l) -> { System.out.println("Artifact: " + c.getArtifact()); System.out.println("Name: " + c.getName()); System.out.println("Version: " + c.getVersion()); System.out.println("Location: " + c.getSourceArchive()); System.out.println("Components provided:"); l.forEach(ll -> System.out.println("\t" + ll)); System.out.println("\n-----------------------------------------------------------\n"); }); }
From source file:com.ms.commons.summer.web.handler.DataBinderUtil.java
protected static Map<String, String> getPathValues(String[] patterns, String path) { BasePathMatcher matcher = new BasePathMatcher(); Map<String, String> pathValues = null; for (String pattern : patterns) { pathValues = matcher.extractUriTemplateVariables(pattern, path); if (pathValues.size() > 0) { return pathValues; }/*from w ww.j a v a 2s . com*/ } return pathValues; }
From source file:com.cws.esolutions.core.listeners.CoreServiceInitializer.java
/** * Shuts down the running core service process. *///from w ww .ja va 2s . c o m public static void shutdown() { final String methodName = CoreServiceInitializer.CNAME + "#shutdown()"; if (DEBUG) { DEBUGGER.debug(methodName); } final Map<String, DataSource> datasources = CoreServiceInitializer.appBean.getDataSources(); try { if ((datasources != null) && (datasources.size() != 0)) { for (String key : datasources.keySet()) { if (DEBUG) { DEBUGGER.debug("Key: {}", key); } BasicDataSource dataSource = (BasicDataSource) datasources.get(key); if (DEBUG) { DEBUGGER.debug("BasicDataSource: {}", dataSource); } if ((dataSource != null) && (!(dataSource.isClosed()))) { dataSource.close(); } } } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); } }
From source file:com.ephesoft.gxt.batchinstance.client.shared.BatchInstanceProgressConvertor.java
public static final WorkflowDetailDTO getWorkflowDetailDTO(final WorkflowDetail workflowDetail, final String batchInstanceIdentifier) { WorkflowDetailDTO workflowDetailDTO = new WorkflowDetailDTO(); if (null != workflowDetail) { workflowDetailDTO.setCurrentExecutingModule(workflowDetail.getCurrentExecutingModule()); workflowDetailDTO.setCurrentExecutingPlugin(workflowDetail.getCurrentExecutingPlugin()); List<String> executedModules = workflowDetail.getExecutedModuleList(); if (CollectionUtils.isNotEmpty(executedModules)) { List<String> executedModuleDTOList = new ArrayList<String>(executedModules.size()); executedModuleDTOList.addAll(executedModules); workflowDetailDTO.setExecutedModuleList(executedModuleDTOList); LOGGER.debug("Executed modules are set for batch instance: ", batchInstanceIdentifier); }/*from www. jav a 2s . c o m*/ List<String> unexecutedModules = workflowDetail.getUnexecutedModuleList(); if (CollectionUtils.isNotEmpty(unexecutedModules)) { List<String> unexecutedModuleDTOList = new ArrayList<String>(unexecutedModules.size()); unexecutedModuleDTOList.addAll(unexecutedModules); workflowDetailDTO.setNonExecutedModuleList(unexecutedModuleDTOList); LOGGER.debug("Unexecuted modules are set for batch instance: ", batchInstanceIdentifier); } List<String> executedPlugins = workflowDetail.getExecutedPluginList(); if (CollectionUtils.isNotEmpty(executedPlugins)) { List<String> executedPluginDTOList = new ArrayList<String>(executedPlugins.size()); executedPluginDTOList.addAll(executedPlugins); workflowDetailDTO.setExecutedPluginList(executedPluginDTOList); LOGGER.debug("Executed plugins are set for batch instance: ", batchInstanceIdentifier); } List<String> unexecutedPlugins = workflowDetail.getUnexecutedPluginList(); if (CollectionUtils.isNotEmpty(unexecutedPlugins)) { List<String> unexecutedPluginDTOList = new ArrayList<String>(unexecutedPlugins.size()); unexecutedPluginDTOList.addAll(unexecutedPlugins); workflowDetailDTO.setNonExecutedPluginList(unexecutedPluginDTOList); LOGGER.debug("Unexecuted plugins are set for batch instance: ", batchInstanceIdentifier); } Map<String, List<String>> modulePluginMap = workflowDetail.getModulePluginMap(); if (null != modulePluginMap) { Map<String, List<String>> modulePluginMapDTO = new HashMap<String, List<String>>( modulePluginMap.size()); modulePluginMapDTO.putAll(modulePluginMap); workflowDetailDTO.setModulePluginMap(modulePluginMapDTO); LOGGER.debug("Module-plugin map is set for batch instance: ", batchInstanceIdentifier); } } return workflowDetailDTO; }
From source file:com.sugaronrest.restapicalls.ModuleInfoExt.java
/** * Gets modules linked information.//from w ww . ja va2s . c o m * * @param linkedModules The module linked info list. * @return Dictionary map of linked modules. */ private static Map<String, List<String>> getLinkedInfo(Map<Object, List<String>> linkedModules) throws Exception { if ((linkedModules == null) || (linkedModules.size() == 0)) { return null; } Map<String, List<String>> jsonLinkedInfo = new HashMap<String, List<String>>(); for (Map.Entry<Object, List<String>> entry : linkedModules.entrySet()) { Object key = entry.getKey(); List<String> jsonPropertyNames = entry.getValue(); ModuleInfo linkedModuleInfo = null; String jsonModuleName = StringUtils.EMPTY; if (key instanceof String) { linkedModuleInfo = ModuleInfo.create(null, key.toString()); if (linkedModuleInfo != null) { if ((jsonPropertyNames == null) || (jsonPropertyNames.size() == 0)) { jsonPropertyNames = linkedModuleInfo.getJsonPropertyNames(); } jsonModuleName = linkedModuleInfo.jsonName; } if (!StringUtils.isNotBlank(jsonModuleName)) { jsonModuleName = ModuleMapper.getInstance().getTablename(key.toString()); } } else if (key instanceof Type) { // This key is a class type (e.g Accounts.class) linkedModuleInfo = ModuleInfo.create((Type) key, null); if (linkedModuleInfo != null) { if ((jsonPropertyNames == null) || (jsonPropertyNames.size() == 0)) { jsonPropertyNames = linkedModuleInfo.getJsonPropertyNames(); } jsonModuleName = linkedModuleInfo.jsonName; } if (!StringUtils.isNotBlank(jsonModuleName)) { String className = ModuleInfo.getClassName((Type) key); jsonModuleName = ModuleMapper.getInstance().getTablename(className); } } else { continue; } jsonLinkedInfo.put(jsonModuleName, jsonPropertyNames); } return jsonLinkedInfo; }