List of usage examples for java.util HashMap isEmpty
public boolean isEmpty()
From source file:net.di2e.ecdr.search.transform.atom.response.security.SecurityMarkingParser.java
public static SecurityDataImpl getFeedSecurityMarkings(Feed feed) { List<QName> attributes = feed.getAttributes(); if (attributes != null) { HashMap<String, List<String>> securityProps = new HashMap<String, List<String>>(); String feedNamespace = null; for (QName qName : attributes) { String namespace = qName.getNamespaceURI(); if (NAMESPACES.contains(namespace)) { String value = feed.getAttributeValue(qName); if (StringUtils.isNotBlank(value)) { securityProps.put(qName.getLocalPart(), getValues(value)); if (feedNamespace == null) { feedNamespace = namespace; }//from w ww . j a v a 2s .co m } } } if (!securityProps.isEmpty()) { return new SecurityDataImpl(securityProps, feedNamespace); } } return null; }
From source file:at.treedb.jslib.JsLib.java
/** * Unloads a <code>JsLib</code> object. * /*from ww w . ja v a 2s . c o m*/ * @param name * name of the * @param version * @throws IOException */ public static void unloadLib(String name, String version) throws IOException { if (jsLibs == null) { return; } synchronized (lockObj) { HashMap<Version, JsLib> v = jsLibs.get(name); if (v != null) { JsLib lib = v.remove(new Version(version)); if (lib != null) { if (lib.inChannel != null) { lib.inChannel.close(); lib.dumpFile.delete(); } // free file cache for the GC lib.fileCache = null; if (v.isEmpty()) { jsLibs.remove(name); } } ArchiveClassLoader.clearCache(name, version); } } }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
/** * Check the state of a newly constructed, empty HashMap. * * @param hashMap//from ww w .j av a 2 s . co m */ private static void checkEmptyHashMapAssumptions(HashMap<?, ?> hashMap) { assertNotNull(hashMap); assertTrue(hashMap.isEmpty()); assertNotNull(hashMap.values()); assertTrue(hashMap.values().isEmpty()); assertTrue(hashMap.values().size() == 0); assertNotNull(hashMap.keySet()); assertTrue(hashMap.keySet().isEmpty()); assertTrue(hashMap.keySet().size() == 0); assertNotNull(hashMap.entrySet()); assertTrue(hashMap.entrySet().isEmpty()); assertTrue(hashMap.entrySet().size() == 0); assertEmptyIterator(hashMap.entrySet().iterator()); }
From source file:com.yahoo.ycsb.db.couchbase2.Couchbase2Client.java
/** * Helper method to turn the values into a String, used with {@link #upsertN1ql(String, HashMap)}. * * @param values the values to encode./*from w ww . j a v a 2 s . c o m*/ * @return the encoded string. */ private static String encodeN1qlFields(final HashMap<String, ByteIterator> values) { if (values.isEmpty()) { return ""; } StringBuilder sb = new StringBuilder(); for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { String raw = entry.getValue().toString(); String escaped = raw.replace("\"", "\\\"").replace("\'", "\\\'"); sb.append(entry.getKey()).append("=\"").append(escaped).append("\" "); } String toReturn = sb.toString(); return toReturn.substring(0, toReturn.length() - 1); }
From source file:com.evolveum.midpoint.common.policy.ValuePolicyGenerator.java
public static String generate(StringPolicyType policy, int defaultLength, boolean generateMinimalSize, OperationResult inputResult) {/*www. j av a 2 s . c om*/ if (null == policy) { throw new IllegalArgumentException("Provided password policy can not be null."); } if (null == inputResult) { throw new IllegalArgumentException("Provided operation result cannot be null"); } // Define result from generator OperationResult generatorResult = new OperationResult( "Password generator running policy :" + policy.getDescription()); inputResult.addSubresult(generatorResult); // if (policy.getLimitations() != null && // policy.getLimitations().getMinLength() != null){ // generateMinimalSize = true; // } // setup default values where missing // PasswordPolicyUtils.normalize(pp); // Optimize usage of limits ass hashmap of limitas and key is set of // valid chars for each limitation HashMap<StringLimitType, ArrayList<String>> lims = new HashMap<StringLimitType, ArrayList<String>>(); for (StringLimitType l : policy.getLimitations().getLimit()) { if (null != l.getCharacterClass().getValue()) { lims.put(l, StringPolicyUtils.stringTokenizer(l.getCharacterClass().getValue())); } else { lims.put(l, StringPolicyUtils.stringTokenizer(StringPolicyUtils .collectCharacterClass(policy.getCharacterClass(), l.getCharacterClass().getRef()))); } } // Get global limitations int minLen = policy.getLimitations().getMinLength() == null ? 0 : policy.getLimitations().getMinLength().intValue(); if (minLen != 0 && minLen > defaultLength) { defaultLength = minLen; } int maxLen = (policy.getLimitations().getMaxLength() == null ? 0 : policy.getLimitations().getMaxLength().intValue()); int unique = policy.getLimitations().getMinUniqueChars() == null ? minLen : policy.getLimitations().getMinUniqueChars().intValue(); // test correctness of definition if (unique > minLen) { minLen = unique; OperationResult reportBug = new OperationResult("Global limitation check"); reportBug.recordWarning( "There is more required uniq characters then definied minimum. Raise minimum to number of required uniq chars."); } if (minLen == 0 && maxLen == 0) { minLen = defaultLength; maxLen = defaultLength; generateMinimalSize = true; } if (maxLen == 0) { if (minLen > defaultLength) { maxLen = minLen; } else { maxLen = defaultLength; } } // Initialize generator StringBuilder password = new StringBuilder(); /* ********************************** * Try to find best characters to be first in password */ HashMap<StringLimitType, ArrayList<String>> mustBeFirst = new HashMap<StringLimitType, ArrayList<String>>(); for (StringLimitType l : lims.keySet()) { if (l.isMustBeFirst() != null && l.isMustBeFirst()) { mustBeFirst.put(l, lims.get(l)); } } // If any limitation was found to be first if (!mustBeFirst.isEmpty()) { HashMap<Integer, ArrayList<String>> posibleFirstChars = cardinalityCounter(mustBeFirst, null, false, false, generatorResult); int intersectionCardinality = mustBeFirst.keySet().size(); ArrayList<String> intersectionCharacters = posibleFirstChars.get(intersectionCardinality); // If no intersection was found then raise error if (null == intersectionCharacters || intersectionCharacters.size() == 0) { generatorResult .recordFatalError("No intersection for required first character sets in password policy:" + policy.getDescription()); // Log error if (LOGGER.isErrorEnabled()) { LOGGER.error( "Unable to generate password: No intersection for required first character sets in password policy: [" + policy.getDescription() + "] following character limitation and sets are used:"); for (StringLimitType l : mustBeFirst.keySet()) { StrBuilder tmp = new StrBuilder(); tmp.appendSeparator(", "); tmp.appendAll(mustBeFirst.get(l)); LOGGER.error("L:" + l.getDescription() + " -> [" + tmp + "]"); } } // No more processing unrecoverable conflict return null; // EXIT } else { if (LOGGER.isDebugEnabled()) { StrBuilder tmp = new StrBuilder(); tmp.appendSeparator(", "); tmp.appendAll(intersectionCharacters); LOGGER.trace("Generate first character intersection items [" + tmp + "] into password."); } // Generate random char into password from intersection password.append(intersectionCharacters.get(rand.nextInt(intersectionCharacters.size()))); } } /* ************************************** * Generate rest to fulfill minimal criteria */ boolean uniquenessReached = false; // Count cardinality of elements HashMap<Integer, ArrayList<String>> chars; for (int i = 0; i < minLen; i++) { // Check if still unique chars are needed if (password.length() >= unique) { uniquenessReached = true; } // Find all usable characters chars = cardinalityCounter(lims, StringPolicyUtils.stringTokenizer(password.toString()), false, uniquenessReached, generatorResult); // If something goes badly then go out if (null == chars) { return null; } if (chars.isEmpty()) { LOGGER.trace("Minimal criterias was met. No more characters"); break; } // Find lowest possible cardinality and then generate char for (int card = 1; card < lims.keySet().size(); card++) { if (chars.containsKey(card)) { ArrayList<String> validChars = chars.get(card); password.append(validChars.get(rand.nextInt(validChars.size()))); // LOGGER.trace(password.toString()); break; } } } // test if maximum is not exceeded if (password.length() > maxLen) { generatorResult .recordFatalError("Unable to meet minimal criteria and not exceed maximxal size of password."); return null; } /* *************************************** * Generate chars to not exceed maximal */ for (int i = 0; i < minLen; i++) { // test if max is reached if (password.length() == maxLen) { // no more characters maximal size is reached break; } if (password.length() >= minLen && generateMinimalSize) { // no more characters are needed break; } // Check if still unique chars are needed if (password.length() >= unique) { uniquenessReached = true; } // find all usable characters chars = cardinalityCounter(lims, StringPolicyUtils.stringTokenizer(password.toString()), true, uniquenessReached, generatorResult); // If something goes badly then go out if (null == chars) { // we hope this never happend. generatorResult .recordFatalError("No valid characters to generate, but no all limitation are reached"); return null; } // if selection is empty then no more characters and we can close // our work if (chars.isEmpty()) { if (i == 0) { password.append(RandomStringUtils.randomAlphanumeric(minLen)); } break; // if (!StringUtils.isBlank(password.toString()) && password.length() >= minLen) { // break; // } // check uf this is a firs cycle and if we need to user some // default (alphanum) character class. } // Find lowest possible cardinality and then generate char for (int card = 1; card <= lims.keySet().size(); card++) { if (chars.containsKey(card)) { ArrayList<String> validChars = chars.get(card); password.append(validChars.get(rand.nextInt(validChars.size()))); // LOGGER.trace(password.toString()); break; } } } if (password.length() < minLen) { generatorResult.recordFatalError( "Unable to generate password and meet minimal size of password. Password lenght: " + password.length() + ", required: " + minLen); LOGGER.trace( "Unable to generate password and meet minimal size of password. Password lenght: {}, required: {}", password.length(), minLen); return null; } generatorResult.recordSuccess(); // Shuffle output to solve pattern like output StrBuilder sb = new StrBuilder(password.substring(0, 1)); ArrayList<String> shuffleBuffer = StringPolicyUtils.stringTokenizer(password.substring(1)); Collections.shuffle(shuffleBuffer); sb.appendAll(shuffleBuffer); return sb.toString(); }
From source file:net.di2e.ecdr.search.transform.atom.response.security.SecurityMarkingParser.java
public static Metacard addSecurityToMetacard(Metacard metacard, Entry entry) { HashMap<String, List<String>> securityProps = new HashMap<String, List<String>>(); CDRMetacard metacardImpl = new CDRMetacard(metacard); List<QName> attributes = entry.getAttributes(); if (attributes != null) { String metacardSecurityNamespace = null; for (QName qName : attributes) { String namespace = qName.getNamespaceURI(); if (NAMESPACES.contains(namespace)) { String value = entry.getAttributeValue(qName); if (StringUtils.isNotBlank(value)) { securityProps.put(qName.getLocalPart(), getValues(value)); if (metacardSecurityNamespace == null) { metacardSecurityNamespace = namespace; }/*from ww w.j av a2 s .co m*/ } } } if (!securityProps.isEmpty()) { metacardImpl.setSecurity(securityProps); metacardImpl.setAttribute(SecurityConstants.SECURITY_NAMESPACE, metacardSecurityNamespace); } } return metacardImpl; }
From source file:com.netease.hearttouch.hthotfix.patch.PatchSoHelper.java
/** * ??so?hash/*from w ww . jav a 2 s. co m*/ * @param project * @param soDir */ public static void hashSoFiles(final Project project, ArrayList<String> soDir) { final HashMap<String, String> hashMap = new HashMap<>(); final String projectDir = project.getProjectDir().toString(); try { for (String dirPath : soDir) { File dir = new File(dirPath); if (!dir.exists()) continue; Files.walkFileTree(dir.toPath(), new SopathVisitor() { @Override protected void visitSo(Path path, byte[] bytecode) { String soFilePath = path.toString(); soFilePath = soFilePath.replace(projectDir, ""); String sha1Hex = DigestUtils.shaHex(bytecode); hashMap.put(soFilePath, sha1Hex); } }); } if (!hashMap.isEmpty()) { isSoExist = true; HashFileHelper.generate(hashMap, Constants.getHotfixPath(project, Constants.HOTFIX_SO_HASH), project.getLogger(), "PatchSoHelper generate error"); } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.noshufou.android.su.util.Util.java
public static boolean deleteStoreFile(Context context, int uid, int execUid, String cmd) { File storeFile = getStoreFile(context, uid, execUid); if (!storeFile.exists()) return true; HashMap<String, String> cmds = readStoreFile(storeFile); cmds.remove(cmd);/*from w w w. j a v a 2s. c o m*/ if (cmds.isEmpty() || cmds.containsKey("any")) { return storeFile.delete(); } else { return writeStoreFile(storeFile, cmds); } }
From source file:org.rhq.plugins.database.ComponentTest.java
/** * Asserts that all measurements in the report are present * according to the resource descriptor. * * @see #getResourceDescriptor(String) for obtaining this. * @param report/* w ww . j av a2s.com*/ */ public static void assertAll(MeasurementReport report, ResourceDescriptor l) { HashMap<String, MetricDescriptor> map = new HashMap<String, MetricDescriptor>(); for (MetricDescriptor md : l.getMetric()) { map.put(md.getProperty(), md); } for (MeasurementDataNumeric n : report.getNumericData()) { map.remove(n.getName()); } for (MeasurementDataTrait n : report.getTraitData()) { map.remove(n.getName()); } assertTrue("Measurements not found " + map.keySet(), map.isEmpty()); }
From source file:it.unibas.spicygui.controllo.mapping.ActionExportAppendInstancesCsv.java
@Override public void performAction() { Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); IDataSourceProxy dataSource = mappingTask.getTargetProxy(); AppendCsvInstancesMainFrame appendFrame = new AppendCsvInstancesMainFrame(dataSource); //jd.getResponse() returns the table name (key) and the file path (value) HashMap<String, String> absolutePaths = appendFrame.getResponse(); if (!absolutePaths.isEmpty()) { try {/*from www . j a v a 2s . c om*/ DAOCsv daoCsv = new DAOCsv(); daoCsv.appendTranslatedCSVinstances(mappingTask, absolutePaths, scenario.getNumber()); //daoCsv.appendTranslatedCSVinstances(mappingTask.getMappingData().getSolution().getDataSource(), absolutePaths); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.EXPORT_COMPLETED_OK))); //StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(Costanti.class, Costanti.EXPORT_COMPLETED_OK)); } catch (DAOException ex) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.EXPORT_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); logger.error(ex); } } }