List of usage examples for java.util Map size
int size();
From source file:fr.paris.lutece.portal.service.spring.SpringContextService.java
/** * Returns a list of bean among all that implements a given interface or extends a given class * @param <T> The class type/* ww w. j av a 2s . c o m*/ * @param classDef The class type * @return A list of beans */ public static <T> List<T> getBeansOfType(Class<T> classDef) { // Search the list in the cache List<T> list = _mapBeansOfType.get(classDef); if (list != null) { return new ArrayList<T>(list); } // The list is not in the cache, so we have to build it list = new ArrayList<T>(); Map<String, T> map = _context.getBeansOfType(classDef); String[] sBeanNames = map.keySet().toArray(new String[map.size()]); for (String strBeanName : sBeanNames) { String strPluginPrefix = getPrefix(strBeanName); if ((strPluginPrefix == null) || (isEnabled(strPluginPrefix))) { list.add(map.get(strBeanName)); } } _mapBeansOfType.put(classDef, new ArrayList<T>(list)); return list; }
From source file:com.baidu.qa.service.test.util.JdbcUtil.java
/** * /*from w w w. j a v a 2s. c o m*/ * @param sqlStr * @param replace_time * @return */ protected static String replaceTimeInSql(String sqlStr, Map<String, String> replace_time) { if (sqlStr == null || sqlStr.trim().length() == 0) { return sqlStr; } if (replace_time == null || replace_time.size() == 0) { return sqlStr; } for (Entry<String, String> entry : replace_time.entrySet()) { String fmStr = entry.getValue().trim(); String tablename = entry.getKey().trim(); SimpleDateFormat dateFm = new SimpleDateFormat(fmStr); String dateTime = dateFm.format(new java.util.Date()); if (sqlStr.indexOf(tablename) != -1) { int start = sqlStr.indexOf(tablename) + tablename.length(); sqlStr = sqlStr.replaceAll(tablename + sqlStr.substring(start, start + fmStr.length()), tablename + dateTime); } } log.debug("replaced:" + sqlStr); return sqlStr; }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.util.OffsetQueryUtil.java
public static String getSourceKeyOffsetsRepresentation(Map<String, String> offsets) { if (offsets == null || offsets.size() == 0) { return ""; }/*from w ww . j a v a 2 s.c o m*/ final StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : offsets.entrySet()) { if (sb.length() > 0) { sb.append(OFFSET_KEY_COLUMN_SEPARATOR); } sb.append(entry.getKey()); sb.append(OFFSET_KEY_COLUMN_NAME_VALUE_SEPARATOR); sb.append(entry.getValue()); } return sb.toString(); }
From source file:com.datumbox.framework.common.dataobjects.MatrixDataframe.java
/** * Parses a single Record and converts it to RealVector by using an already * existing mapping between feature names and column ids. * //from w w w.j a v a 2 s . c o m * @param r * @param featureIdsReference * @return */ public static RealVector parseRecord(Record r, Map<Object, Integer> featureIdsReference) { if (featureIdsReference.isEmpty()) { throw new IllegalArgumentException("The featureIdsReference map should not be empty."); } int d = featureIdsReference.size(); RealVector v = new ArrayRealVector(d); boolean addConstantColumn = featureIdsReference.containsKey(Dataframe.COLUMN_NAME_CONSTANT); if (addConstantColumn) { v.setEntry(0, 1.0); //add the constant column } for (Map.Entry<Object, Object> entry : r.getX().entrySet()) { Object feature = entry.getKey(); Double value = TypeInference.toDouble(entry.getValue()); if (value != null) { Integer featureId = featureIdsReference.get(feature); if (featureId != null) {//if the feature exists in our database v.setEntry(featureId, value); } } else { //else the X matrix maintains the 0.0 default value } } return v; }
From source file:com.googlecode.blaisemath.app.MenuConfig.java
/** Tests whether map is a singleton */ static boolean isSingletonMap(Map<String, ?> map) { return map != null && map.size() == 1; }
From source file:jfabrix101.lib.helper.NetworkHelper.java
/** * Make an http request using the POST protocol * @param url /*from w ww. java 2s. co m*/ * @param params - Maps with parameters * @return * @throws Exception */ public static String postUrl(String url, Map<String, String> params) throws Exception { HttpClient httpClient = getHttpClient(); HttpPost httpRequest = new HttpPost(url); // Add post data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(params.size()); for (Entry<String, String> entry : params.entrySet()) { String key = entry.getKey(); String val = entry.getValue(); nameValuePairs.add(new BasicNameValuePair(key, val)); } httpRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs)); return execHttpRequest(httpClient, httpRequest); }
From source file:com.hangum.tadpole.engine.sql.util.export.JsonExpoter.java
public static JsonArray makeContentArray(String tableName, QueryExecuteResultDTO rsDAO, int intLimitCnt) { List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData(); Map<Integer, String> mapLabelName = rsDAO.getColumnLabelName(); JsonArray jsonArry = new JsonArray(); for (int i = 0; i < dataList.size(); i++) { Map<Integer, Object> mapColumns = dataList.get(i); JsonObject jsonObj = new JsonObject(); for (int j = 1; j < mapLabelName.size(); j++) { String columnName = mapLabelName.get(j); jsonObj.addProperty(StringUtils.trimToEmpty(columnName), "" + mapColumns.get(j)); }/*w ww.j a v a 2s . c o m*/ jsonArry.add(jsonObj); if (i == intLimitCnt) break; } return jsonArry; }
From source file:com.netsteadfast.greenstep.bsc.util.PerformanceScoreChainUtils.java
public static void createOrUpdateMonitorItemScoreCurrentDateForOrganizations(String frequency) throws ServiceException, Exception { Map<String, String> organizationMap = organizationService.findForMap(false); if (null == organizationMap || organizationMap.size() < 1) { return;/*from ww w . j a v a2 s . c om*/ } Map<String, Object> paramMap = new HashMap<String, Object>(); for (Map.Entry<String, String> org : organizationMap.entrySet()) { OrganizationVO organization = BscBaseLogicServiceCommonSupport.findOrganizationData(organizationService, org.getKey()); paramMap.put("orgId", organization.getOrgId()); if (kpiOrgaService.countByParams(paramMap) < 1) { continue; } try { createOrUpdateMonitorItemScoreCurrentDate(frequency, "organization", organization.getOid(), ""); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.datumbox.common.dataobjects.MatrixDataset.java
/** * Parses a dataset and converts it to MatrixDataset by using an already * existing mapping between feature names and column ids. Typically used * to parse the testing or validation dataset. * //ww w . j av a 2 s. c o m * @param newDataset * @param featureIdsReference * @return */ public static MatrixDataset parseDataset(Dataset newDataset, Map<Object, Integer> featureIdsReference) { if (featureIdsReference.isEmpty()) { throw new RuntimeException("The featureIdsReference map should not be empty."); } int n = newDataset.size(); int d = featureIdsReference.size(); MatrixDataset m = new MatrixDataset(new ArrayRealVector(n), new BlockRealMatrix(n, d), featureIdsReference); if (newDataset.isEmpty()) { return m; } boolean extractY = (Dataset .value2ColumnType(newDataset.iterator().next().getY()) == Dataset.ColumnType.NUMERICAL); boolean addConstantColumn = m.feature2ColumnId.containsKey(Dataset.constantColumnName); for (Record r : newDataset) { int row = r.getId(); if (extractY) { m.Y.setEntry(row, Dataset.toDouble(r.getY())); } if (addConstantColumn) { m.X.setEntry(row, 0, 1.0); //add the constant column } for (Map.Entry<Object, Object> entry : r.getX().entrySet()) { Object feature = entry.getKey(); Double value = Dataset.toDouble(entry.getValue()); if (value != null) { Integer featureId = m.feature2ColumnId.get(feature); if (featureId != null) {//if the feature exists in our database m.X.setEntry(row, featureId, value); } } else { //else the X matrix maintains the 0.0 default value } } } return m; }
From source file:com.hangum.tadpole.sql.util.SQLUtil.java
/** * INSERT ? ?./* w ww . j a v a 2 s . co m*/ * * @param tableName * @param rs * @return * @throws Exception */ public static String makeInsertStatment(String tableName, ResultSet rs) throws Exception { StringBuffer result = new StringBuffer("INSERT INTO " + tableName + "("); Map<Integer, String> mapTable = ResultSetUtils.getColumnName(rs); for (int i = 0; i < mapTable.size(); i++) { if (i != (mapTable.size() - 1)) result.append(mapTable.get(i) + ","); else result.append(mapTable.get(i)); } result.append(") VALUES("); for (int i = 0; i < mapTable.size(); i++) { if (i != (mapTable.size() - 1)) result.append("?,"); else result.append('?'); } result.append(')'); if (logger.isDebugEnabled()) logger.debug("[make insert statment is " + result.toString()); return result.toString(); }