List of usage examples for java.util Map size
int size();
From source file:de.micromata.tpsb.doc.parser.JavaDocUtil.java
public static JavaDocInfo parseJavaDoc(String cleanedContent) { JavaDocInfo javaDocInfo = new JavaDocInfo(); Pair<String, String> titleAndDesc = extractTitleAndDescription(cleanedContent); if (StringUtils.isNotBlank(titleAndDesc.getFirst())) { javaDocInfo.setTitle(titleAndDesc.getFirst()); }/* w w w . j ava2s. c o m*/ if (StringUtils.isNotBlank(titleAndDesc.getSecond())) { javaDocInfo.setDescription(titleAndDesc.getSecond()); } Map<String, List<Pair<String, String>>> tags = extractTags(cleanedContent); if (tags != null && tags.size() != 0) { javaDocInfo.setTags(tags); } return javaDocInfo; }
From source file:org.fusesource.meshkeeper.util.internal.IntrospectionSupport.java
public static Map<String, Object> extractProperties(Map<String, Object> props, String optionPrefix) { if (props == null) { throw new IllegalArgumentException("props was null."); }/*from w w w . j a v a 2 s . c o m*/ HashMap<String, Object> rc = new HashMap<String, Object>(props.size()); for (Iterator<String> iter = props.keySet().iterator(); iter.hasNext();) { String name = iter.next(); if (name.startsWith(optionPrefix)) { Object value = props.get(name); name = name.substring(optionPrefix.length()); rc.put(name, value); iter.remove(); } } return rc; }
From source file:org.fcrepo.client.utils.HttpHelper.java
/** * Encode URL parameters as a query string. * @param params Query parameters/*from w ww . java2 s .c om*/ **/ private static String queryString(final Map<String, List<String>> params) { final StringBuilder builder = new StringBuilder(); if (params != null && params.size() > 0) { for (final Iterator<String> it = params.keySet().iterator(); it.hasNext();) { final String key = it.next(); final List<String> values = params.get(key); for (final String value : values) { try { builder.append(key + "=" + URLEncoder.encode(value, "UTF-8") + "&"); } catch (final UnsupportedEncodingException e) { builder.append(key + "=" + value + "&"); } } } return builder.length() > 0 ? "?" + builder.substring(0, builder.length() - 1) : ""; } return ""; }
From source file:com.segment.analytics.internal.Utils.java
/** * Transforms the given map by replacing the keys mapped by {@code mapper}. Any keys not in the * mapper preserve their original keys. If a key in the mapper maps to null or a blank string, * that value is dropped./*from ww w . ja va 2s.c om*/ * * e.g. transform({a: 1, b: 2, c: 3}, {a: a, c: ""}) -> {$a: 1, b: 2} * - transforms a to $a * - keeps b * - removes c */ public static <T> Map<String, T> transform(Map<String, T> in, Map<String, String> mapper) { Map<String, T> out = new LinkedHashMap<>(in.size()); for (Map.Entry<String, T> entry : in.entrySet()) { String key = entry.getKey(); if (!mapper.containsKey(key)) { out.put(key, entry.getValue()); // keep the original key. continue; } String mappedKey = mapper.get(key); if (!isNullOrEmpty(mappedKey)) { out.put(mappedKey, entry.getValue()); } } return out; }
From source file:com.alibaba.dubbo.governance.web.common.pulltool.Tool.java
public static int countMapValues(Map<?, ?> map) { int total = 0; if (map != null && map.size() > 0) { for (Object value : map.values()) { if (value != null) { if (value instanceof Number) { total += ((Number) value).intValue(); } else if (value.getClass().isArray()) { total += Array.getLength(value); } else if (value instanceof Collection) { total += ((Collection<?>) value).size(); } else if (value instanceof Map) { total += ((Map<?, ?>) value).size(); } else { total += 1;/* w w w. j a va2s .c o m*/ } } } } return total; }
From source file:org.openremote.android.console.net.ORControllerServerSwitcher.java
/** * Get the groupmembers from the file group_members.xml . * * @param context global Android application context * * @return list of controller URLs// w w w.j a v a 2 s . c om */ @SuppressWarnings("unchecked") public static List<String> findAllGroupMembersFromFile(Context context) { // TODO: Use URL in the API instead of strings List<String> groupMembers = new ArrayList<String>(); Map<String, String> groupMembersMap = (Map<String, String>) context .getSharedPreferences(SERIALIZE_GROUP_MEMBERS_FILE_NAME, 0).getAll(); for (int i = 0; i < groupMembersMap.size(); i++) { groupMembers.add(groupMembersMap.get(i + "")); } return groupMembers; }
From source file:dao.MetricsDAO.java
public static String watchMetric(int metricId, Map<String, String[]> params, String user) { String message = "Internal error"; if (params == null || params.size() == 0) { return "Empty post body"; }//w w w . j a v a 2 s . c o m String type = "metric"; String notificationType = ""; if (params.containsKey("notification_type")) { String[] notificationTypeArray = params.get("notification_type"); if (notificationTypeArray != null && notificationTypeArray.length > 0) { notificationType = notificationTypeArray[0]; } } if (StringUtils.isBlank(notificationType)) { return "notification_type is missing"; } Integer userId = UserDAO.getUserIDByUserName(user); if (userId != null && userId != 0) { List<Map<String, Object>> rows = null; rows = getJdbcTemplate().queryForList(GET_WATCHED_METRIC_ID, userId, metricId); if (rows != null && rows.size() > 0) { message = "watch item is already exist"; } else { int row = getJdbcTemplate().update(WATCH_METRIC, userId, metricId, notificationType); if (row > 0) { message = ""; } } } else { message = "User not found"; } return message; }
From source file:de.tudarmstadt.ukp.dkpro.core.mallet.internal.wordembeddings.MalletEmbeddingsUtils.java
/** * Read embeddings in text format from an InputStream. * Each line is expected to have a whitespace-separated list {@code <token> <value1> <value2> ...}. * * @param inputStream an {@link InputStream} * @param hasHeader if true, read size and dimensionality from the first line * @return a {@code Map<String, double[]>} mapping each token to a vector. * @throws IOException if the input file cannot be read *///w w w . j a va2 s. c o m public static Map<String, double[]> readEmbeddingFileTxt(InputStream inputStream, boolean hasHeader) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); final int dimensions; final int size; if (hasHeader) { String[] header = reader.readLine().split(" "); assert header.length == 2; size = Integer.parseInt(header[0]); dimensions = Integer.parseInt(header[1]); } else { dimensions = -1; size = -1; } Map<String, double[]> embeddings = reader.lines().map(MalletEmbeddingsUtils::lineToEmbedding) .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); reader.close(); /* assert size and dimension */ if (hasHeader) { /* check that size read matches header information */ LOG.debug("Checking number and vector sizes for all embeddings."); assert size == embeddings.size(); assert embeddings.values().stream().allMatch(vector -> dimensions == vector.length); } else { LOG.debug("Checking vector sizes for all embeddings."); int firstLength = embeddings.values().stream().findAny().get().length; assert embeddings.values().stream().allMatch(vector -> firstLength == vector.length); } return embeddings; }
From source file:com.hangum.tadpole.engine.sql.util.export.SQLExporter.java
public static String makeFileInsertStatment(String tableName, QueryExecuteResultDTO rsDAO, int intLimitCnt, int commit) throws Exception { String strTmpDir = PublicTadpoleDefine.TEMP_DIR + tableName + System.currentTimeMillis() + PublicTadpoleDefine.DIR_SEPARATOR; String strFile = tableName + ".sql"; String strFullPath = strTmpDir + strFile; final String INSERT_INTO_STMT = "INSERT INTO " + tableName + " (%s) VALUES (%S);" + PublicTadpoleDefine.LINE_SEPARATOR; // ?./*from w ww.j a v a 2 s . c om*/ String strColumns = ""; Map<Integer, String> mapTable = rsDAO.getColumnLabelName(); for (int i = 1; i < mapTable.size(); i++) { if (i != (mapTable.size() - 1)) strColumns += mapTable.get(i) + ","; else strColumns += mapTable.get(i); } // ?? . StringBuffer sbInsertInto = new StringBuffer(); int DATA_COUNT = 1000; List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData(); Map<Integer, Integer> mapColumnType = rsDAO.getColumnType(); String strResult = new String(); for (int i = 0; i < dataList.size(); i++) { Map<Integer, Object> mapColumns = dataList.get(i); strResult = ""; for (int j = 1; j < mapColumnType.size(); j++) { Object strValue = mapColumns.get(j); strValue = strValue == null ? "" : strValue; if (!RDBTypeToJavaTypeUtils.isNumberType(mapColumnType.get(j))) { strValue = StringEscapeUtils.escapeSql(strValue.toString()); strValue = StringHelper.escapeSQL(strValue.toString()); strValue = SQLUtil.makeQuote(strValue.toString()); } if (j != (mapTable.size() - 1)) strResult += strValue + ","; else strResult += strValue; } sbInsertInto.append(String.format(INSERT_INTO_STMT, strColumns, strResult)); if (intLimitCnt == i) { return sbInsertInto.toString(); } if (commit > 0 && (i % commit) == 0) { sbInsertInto .append("COMMIT" + PublicTadpoleDefine.SQL_DELIMITER + PublicTadpoleDefine.LINE_SEPARATOR); } if ((i % DATA_COUNT) == 0) { FileUtils.writeStringToFile(new File(strFullPath), sbInsertInto.toString(), true); sbInsertInto.setLength(0); } } if (sbInsertInto.length() > 0) { if (commit > 0) { sbInsertInto .append("COMMIT" + PublicTadpoleDefine.SQL_DELIMITER + PublicTadpoleDefine.LINE_SEPARATOR); } FileUtils.writeStringToFile(new File(strFullPath), sbInsertInto.toString(), true); } return strFullPath; }
From source file:net.sourceforge.fenixedu.presentationTier.docs.academicAdministrativeOffice.ApprovementInfoForEquivalenceProcess.java
static protected String getAcademicUnitIdentifier(final Map<Unit, String> academicUnitIdentifiers, final Unit academicUnit) { if (!academicUnitIdentifiers.containsKey(academicUnit)) { academicUnitIdentifiers.put(academicUnit, identifiers[academicUnitIdentifiers.size()]); }//from w w w . j av a2s . co m return academicUnitIdentifiers.get(academicUnit); }