List of usage examples for java.util HashMap isEmpty
public boolean isEmpty()
From source file:Main.java
public static void main(String args[]) { HashMap<Integer, String> newmap = new HashMap<Integer, String>(); // populate hash map newmap.put(1, "tutorials"); newmap.put(2, "from"); newmap.put(3, "java2s.com"); // check if map is empty boolean val = newmap.isEmpty(); // check the boolean value System.out.println("Is hash map empty: " + val); }
From source file:it.univaq.incipict.profilemanager.common.utility.Utility.java
public static Profile getBestProfile(HashMap<Profile, Double> distancesMap) { if (distancesMap.isEmpty() || distancesMap == null) return null; // return the first element because the distances map is sorted by values // REF: getEuclideanDistances() method return distancesMap.keySet().iterator().next(); }
From source file:org.apache.hadoop.hive.ql.optimizer.IndexUtils.java
/** * check that every index table contains the given partition and is fresh *//*from w ww . ja v a2 s. c om*/ private static boolean containsPartition(Hive hive, Partition part, List<Index> indexes) throws HiveException { HashMap<String, String> partSpec = part.getSpec(); if (partSpec.isEmpty()) { // empty specs come from non-partitioned tables return isIndexTableFresh(hive, indexes, part.getTable()); } for (Index index : indexes) { // index.getDbName() is used as a default database, which is database of target table, // if index.getIndexTableName() does not contain database name String[] qualified = Utilities.getDbTableName(index.getDbName(), index.getIndexTableName()); Table indexTable = hive.getTable(qualified[0], qualified[1]); // get partitions that match the spec Partition matchingPartition = hive.getPartition(indexTable, partSpec, false); if (matchingPartition == null) { LOG.info("Index table " + indexTable + "did not contain built partition that matched " + partSpec); return false; } else if (!isIndexPartitionFresh(hive, index, part)) { return false; } } return true; }
From source file:it.univaq.incipict.profilemanager.common.utility.Utility.java
public static HashMap<Profile, Float> getPercentages(HashMap<Profile, Double> distances, int informationSetSize) { Map<Profile, Float> result = new HashMap<Profile, Float>(); if (distances.isEmpty() || distances == null) { return new HashMap<Profile, Float>(); } else {//from www .j a v a2 s .c o m for (Map.Entry<Profile, Double> entry : distances.entrySet()) { Profile profile = entry.getKey(); Double distance = entry.getValue(); // Calculate the percentage for the current distance // The maximum distance is sqrt(informationSetSize) because we have // 0-1 vectors // REMARK: Euclidean Distance Theory float maxDistance = (float) Math.sqrt(informationSetSize); float percentage = (float) (maxDistance - distance) * 100 / maxDistance; // put the percentage in Map formatted with two decimals. result.put(profile, (float) (Math.round(percentage * 100.0) / 100.0)); } } // return the HashMap sorted by value (DESC) return (HashMap<Profile, Float>) MapUtil.sortByValueDESC(result); }
From source file:com.github.sakserv.lslock.cli.LockListerCli.java
/** * Prints the final output for the locks * * @param lockDirectory Directory to recurse for lock files * @throws IOException If the lockdirectory is missing *///w w w . j a v a 2s . co m public static void printLocks(File lockDirectory, HashMap<Integer, Integer> procLocksContents) throws IOException { Collection<File> fileList = FileUtils.listFiles(lockDirectory, null, true); // If not locks are found, output no locks found if (procLocksContents.isEmpty() || fileList.isEmpty()) { System.out.println("No locks found for " + lockDirectory); } else { // Setup the header System.out.printf("%-15s %-5s %n", "PID", "PATH"); // Iterative the files and print the PID and PATH for the lock for (File file : fileList) { System.out.printf("%-15s %15s %n", procLocksContents.get(getInode(file)), file); } } System.out.println(); }
From source file:es.sm2.openppm.core.plugin.PluginTemplate.java
/** * Load template for plugin//from w w w.ja v a 2 s . c o m * * @param templateName * @param data * @return * @throws IOException * @throws TemplateException */ public static String getTemplate(String templateName, HashMap<String, Object> data) throws IOException, TemplateException { Logger log = LogManager.getLog(PluginTemplate.class); // Print data to logger if (log.isDebugEnabled()) { log.debug("Create Template: " + templateName); if (data != null && !data.isEmpty()) { for (String key : data.keySet()) { log.debug("Parameter: " + key + " Value: " + data.get(key)); } } } // Load template InputStream stream = PluginTemplate.class.getResourceAsStream(templateName); String teamplate = IOUtils.toString(stream); // Create loader StringTemplateLoader stringLoader = new StringTemplateLoader(); stringLoader.putTemplate("template", teamplate); // Create configuration Configuration cfg = new Configuration(); cfg.setTemplateLoader(stringLoader); Template template = cfg.getTemplate("template"); StringWriter writer = new StringWriter(); template.process(data, writer); return writer.toString(); }
From source file:fr.mixit.android.utils.NetworkUtils.java
static String buildParams(HashMap<String, String> args) { if (args != null && !args.isEmpty()) { final StringBuilder params = new StringBuilder(); final Set<String> keys = args.keySet(); for (final Iterator<String> iterator = keys.iterator(); iterator.hasNext();) { final String key = iterator.next(); final String value = args.get(key); params.append(key);// ww w. ja v a 2 s .c o m params.append(EQUAL); params.append(value); if (iterator.hasNext()) { params.append(AND); } } return params.toString(); } return null; }
From source file:org.apache.pig.impl.util.JarManager.java
public static File createPigScriptUDFJar(PigContext pigContext) throws IOException { File scriptUDFJarFile = File.createTempFile("PigScriptUDF", ".jar"); // ensure the scriptUDFJarFile is deleted on exit scriptUDFJarFile.deleteOnExit();/*from w w w .j a v a2s . c o m*/ FileOutputStream fos = new FileOutputStream(scriptUDFJarFile); HashMap<String, String> contents = new HashMap<String, String>(); createPigScriptUDFJar(fos, pigContext, contents); if (!contents.isEmpty()) { FileInputStream fis = null; String md5 = null; try { fis = new FileInputStream(scriptUDFJarFile); md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis); } finally { if (fis != null) { fis.close(); } } File newScriptUDFJarFile = new File(scriptUDFJarFile.getParent(), "PigScriptUDF-" + md5 + ".jar"); scriptUDFJarFile.renameTo(newScriptUDFJarFile); return newScriptUDFJarFile; } return null; }
From source file:org.aselect.server.utils.Utils.java
/** * Serialize attributes contained in a HashMap. <br> * <br>// w ww . ja v a 2 s. c o m * <b>Description:</b> <br> * This method serializes attributes contained in a HashMap: * <ul> * <li>They are formatted as attr1=value1&attr2=value2;... * <li>If a "&" or a "=" appears in either the attribute name or value, they are transformed to %26 or %3d * respectively. * <li>The end result is base64 encoded. * </ul> * <br> * * @param htAttributes - HashMap containing all attributes * @return Serialized representation of the attributes * @throws ASelectException - If serialization fails. */ public static String serializeAttributes(HashMap htAttributes) throws ASelectException { final String sMethod = "serializeAttributes"; try { if (htAttributes == null || htAttributes.isEmpty()) return null; StringBuffer sb = new StringBuffer(); Set keys = htAttributes.keySet(); for (Object s : keys) { String sKey = (String) s; // for (Enumeration e = htAttributes.keys(); e.hasMoreElements(); ) { // String sKey = (String)e.nextElement(); Object oValue = htAttributes.get(sKey); if (oValue instanceof Vector) {// it's a multivalue attribute Vector vValue = (Vector) oValue; sKey = URLEncoder.encode(sKey + "[]", "UTF-8"); Enumeration eEnum = vValue.elements(); while (eEnum.hasMoreElements()) { String sValue = (String) eEnum.nextElement(); // add: key[]=value sb.append(sKey).append("=").append(URLEncoder.encode(sValue, "UTF-8")); if (eEnum.hasMoreElements()) sb.append("&"); } } else if (oValue instanceof String) {// it's a single value attribute String sValue = (String) oValue; sb.append(URLEncoder.encode(sKey, "UTF-8")).append("=") .append(URLEncoder.encode(sValue, "UTF-8")); } // if (e.hasMoreElements()) sb.append("&"); } int len = sb.length(); String result = sb.substring(0, len - 1); BASE64Encoder b64enc = new BASE64Encoder(); return b64enc.encode(result.getBytes("UTF-8")); } catch (Exception e) { ASelectSystemLogger logger = ASelectSystemLogger.getHandle(); logger.log(Level.WARNING, MODULE, sMethod, "Could not serialize attributes", e); throw new ASelectException(Errors.ERROR_ASELECT_INTERNAL_ERROR); } }
From source file:eu.europa.ec.fisheries.uvms.exchange.search.SearchFieldMapper.java
/** * Created the complete search SQL with joins and sets the values based on * the criterias/*from w w w.ja v a 2 s . c o m*/ * * @param criterias * @param dynamic * @return * @throws ParseException */ private static String createSearchSql(List<SearchValue> criterias, boolean dynamic) throws ParseException { String OPERATOR = " OR "; if (dynamic) { OPERATOR = " AND "; } StringBuilder builder = new StringBuilder(); HashMap<ExchangeSearchField, List<SearchValue>> orderedValues = combineSearchFields(criterias); if (!orderedValues.isEmpty()) { builder.append("WHERE "); boolean first = true; for (Map.Entry<ExchangeSearchField, List<SearchValue>> criteria : orderedValues.entrySet()) { if (first) { first = false; } else { builder.append(OPERATOR); } if (criteria.getValue().size() == 1) { SearchValue searchValue = criteria.getValue().get(0); builder.append(" ( ").append(buildTableAliasname(searchValue.getField())) .append(setParameter(searchValue)) // .append(" OR ").append(buildTableAliasname(searchValue.getField())).append(" IS NULL ") .append(" ) "); } else if (criteria.getValue().size() > 1) { builder.append(" ( ").append(buildTableAliasname(criteria.getKey())).append(" IN (:") .append(criteria.getKey().getSQLReplacementToken()).append(") ") // .append(" OR ").append(buildTableAliasname(criteria.getKey())).append(" IS NULL ") .append(" ) "); } } } return builder.toString(); }