List of usage examples for java.util HashSet addAll
boolean addAll(Collection<? extends E> c);
From source file:com.iflytek.spider.crawl.CrawlDb.java
public int run(String[] args) throws Exception { if (args.length < 2) { System.err.println(/*from w w w .j a v a 2s . c om*/ "Usage: CrawlDb <crawldb> (-dir <segments> | <seg1> <seg2> ...) [-force] [-noAdditions]"); System.err.println("\tcrawldb\tCrawlDb to update"); System.err.println("\t-dir segments\tparent directory containing all segments to update from"); System.err.println("\tseg1 seg2 ...\tlist of segment names to update from"); System.err.println("\t-force\tforce update even if CrawlDb appears to be locked (CAUTION advised)"); System.err.println( "\t-noAdditions\tonly update already existing URLs, don't add any newly discovered URLs"); return -1; } boolean force = false; final FileSystem fs = FileSystem.get(getConf()); boolean additionsAllowed = getConf().getBoolean(CRAWLDB_ADDITIONS_ALLOWED, true); HashSet<Path> dirs = new HashSet<Path>(); for (int i = 1; i < args.length; i++) { if (args[i].equals("-force")) { force = true; } else if (args[i].equals("-noAdditions")) { additionsAllowed = false; } else if (args[i].equals("-dir")) { FileStatus[] paths = fs.listStatus(new Path(args[++i]), HadoopFSUtil.getPassDirectoriesFilter(fs)); dirs.addAll(Arrays.asList(HadoopFSUtil.getPaths(paths))); } else { dirs.add(new Path(args[i])); } } try { update(new Path(args[0]), dirs.toArray(new Path[dirs.size()]), additionsAllowed, force); return 0; } catch (Exception e) { LOG.fatal("CrawlDb update: " + StringUtils.stringifyException(e)); return -1; } }
From source file:com.izforge.izpack.core.rules.process.EmptyCondition.java
@Override public Set<String> getVarRefs() { HashSet<String> vars = new HashSet<String>(2); switch (contentType) { case VARIABLE: if (this.content != null) { // variable is used in this case vars.add(this.content); }//from ww w. j av a2 s .c om break; case STRING: case FILE: case DIR: if (this.content != null) { // variables are resolved here vars.addAll(ValueUtils.parseUnresolvedVariableNames(this.content)); } break; default: throw new CompilerException("Unimplemented contentType"); } return vars; }
From source file:org.alfresco.repo.security.authentication.AbstractChainingAuthenticationService.java
/** * {@inheritDoc}//from w w w. ja v a2 s.co m */ public Set<String> getDomains() { HashSet<String> domains = new HashSet<String>(); for (AuthenticationService authService : getUsableAuthenticationServices()) { domains.addAll(authService.getDomains()); } return domains; }
From source file:com.evolveum.midpoint.common.policy.PasswordPolicyUtils.java
/** * Check provided password against provided policy * // w ww . j av a2 s . co m * @param password * - password to check * @param pp * - Password policy used * @return - Operation result of this validation */ public static OperationResult validatePassword(String password, ValuePolicyType pp) { Validate.notNull(pp, "Password policy must not be null."); OperationResult ret = new OperationResult(OPERATION_PASSWORD_VALIDATION); ret.addParam("policyName", pp.getName()); normalize(pp); if (password == null && pp.getMinOccurs() != null && XsdTypeMapper.multiplicityToInteger(pp.getMinOccurs()) == 0) { // No password is allowed ret.recordSuccess(); return ret; } if (password == null) { password = ""; } LimitationsType lims = pp.getStringPolicy().getLimitations(); StringBuilder message = new StringBuilder(); // Test minimal length if (lims.getMinLength() == null) { lims.setMinLength(0); } if (lims.getMinLength() > password.length()) { String msg = "Required minimal size (" + lims.getMinLength() + ") of password is not met (password length: " + password.length() + ")"; ret.addSubresult( new OperationResult("Check global minimal length", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // ret.addSubresult(new OperationResult("Check global minimal length. Minimal length of password OK.", // OperationResultStatus.SUCCESS, "PASSED")); // } // Test maximal length if (lims.getMaxLength() != null) { if (lims.getMaxLength() < password.length()) { String msg = "Required maximal size (" + lims.getMaxLength() + ") of password was exceeded (password length: " + password.length() + ")."; ret.addSubresult( new OperationResult("Check global maximal length", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // ret.addSubresult(new OperationResult("Check global maximal length. Maximal length of password OK.", // OperationResultStatus.SUCCESS, "PASSED")); // } } // Test uniqueness criteria HashSet<String> tmp = new HashSet<String>(StringPolicyUtils.stringTokenizer(password)); if (lims.getMinUniqueChars() != null) { if (lims.getMinUniqueChars() > tmp.size()) { String msg = "Required minimal count of unique characters (" + lims.getMinUniqueChars() + ") in password are not met (unique characters in password " + tmp.size() + ")"; ret.addSubresult(new OperationResult("Check minimal count of unique chars", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // ret.addSubresult(new OperationResult( // "Check minimal count of unique chars. Password satisfies minimal required unique characters.", // OperationResultStatus.SUCCESS, "PASSED")); // } } // check limitation HashSet<String> allValidChars = new HashSet<String>(128); ArrayList<String> validChars = null; ArrayList<String> passwd = StringPolicyUtils.stringTokenizer(password); if (lims.getLimit() == null || lims.getLimit().isEmpty()) { if (message.toString() == null || message.toString().isEmpty()) { ret.computeStatus(); } else { ret.computeStatus(message.toString()); } return ret; } for (StringLimitType l : lims.getLimit()) { OperationResult limitResult = new OperationResult("Tested limitation: " + l.getDescription()); if (null != l.getCharacterClass().getValue()) { validChars = StringPolicyUtils.stringTokenizer(l.getCharacterClass().getValue()); } else { validChars = StringPolicyUtils.stringTokenizer(StringPolicyUtils.collectCharacterClass( pp.getStringPolicy().getCharacterClass(), l.getCharacterClass().getRef())); } // memorize validChars allValidChars.addAll(validChars); // Count how many character for this limitation are there int count = 0; for (String s : passwd) { if (validChars.contains(s)) { count++; } } // Test minimal occurrence if (l.getMinOccurs() == null) { l.setMinOccurs(0); } if (l.getMinOccurs() > count) { String msg = "Required minimal occurrence (" + l.getMinOccurs() + ") of characters (" + l.getDescription() + ") in password is not met (occurrence of characters in password " + count + ")."; limitResult.addSubresult(new OperationResult("Check minimal occurrence of characters", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // limitResult.addSubresult(new OperationResult("Check minimal occurrence of characters in password OK.", // OperationResultStatus.SUCCESS, "PASSED")); // } // Test maximal occurrence if (l.getMaxOccurs() != null) { if (l.getMaxOccurs() < count) { String msg = "Required maximal occurrence (" + l.getMaxOccurs() + ") of characters (" + l.getDescription() + ") in password was exceeded (occurrence of characters in password " + count + ")."; limitResult.addSubresult(new OperationResult("Check maximal occurrence of characters", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // limitResult.addSubresult(new OperationResult( // "Check maximal occurrence of characters in password OK.", OperationResultStatus.SUCCESS, // "PASSED")); // } } // test if first character is valid if (l.isMustBeFirst() == null) { l.setMustBeFirst(false); } // we check mustBeFirst only for non-empty passwords if (StringUtils.isNotEmpty(password) && l.isMustBeFirst() && !validChars.contains(password.substring(0, 1))) { String msg = "First character is not from allowed set. Allowed set: " + validChars.toString(); limitResult.addSubresult( new OperationResult("Check valid first char", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // limitResult.addSubresult(new OperationResult("Check valid first char in password OK.", // OperationResultStatus.SUCCESS, "PASSED")); // } limitResult.computeStatus(); ret.addSubresult(limitResult); } // Check if there is no invalid character StringBuilder sb = new StringBuilder(); for (String s : passwd) { if (!allValidChars.contains(s)) { // memorize all invalid characters sb.append(s); } } if (sb.length() > 0) { String msg = "Characters [ " + sb + " ] are not allowed in password"; ret.addSubresult(new OperationResult("Check if password does not contain invalid characters", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // ret.addSubresult(new OperationResult("Check if password does not contain invalid characters OK.", // OperationResultStatus.SUCCESS, "PASSED")); // } if (message.toString() == null || message.toString().isEmpty()) { ret.computeStatus(); } else { ret.computeStatus(message.toString()); } return ret; }
From source file:org.dspace.servicemanager.DSpaceServiceManager.java
public <T> List<T> getServicesByType(Class<T> type) { checkRunning();/*from w ww .ja v a 2s . c o m*/ if (type == null) { throw new IllegalArgumentException("type cannot be null"); } HashSet<T> set = new HashSet<T>(); for (ServiceManagerSystem sms : serviceManagers) { try { set.addAll(sms.getServicesByType(type)); } catch (Exception e) { // keep going } } // put the set into a list for easier access and sort it List<T> services = new ArrayList<T>(set); Collections.sort(services, new ServiceManagerUtils.ServiceComparator()); return services; }
From source file:com.tesora.dve.sql.expression.ScopeEntry.java
@Override public Set<String> getAllAliases() { HashSet<String> ret = new HashSet<String>(); ret.addAll(Functional.apply(tableNamespace.keySet(), buildUnquoted)); ret.addAll(Functional.apply(columnNamespace.keySet(), buildUnquoted)); return ret;/*from ww w.ja v a 2 s. com*/ }
From source file:org.jactr.core.module.declarative.search.local.DefaultSearchSystem.java
protected Collection<IChunk> not(ISlot slot) { /*// ww w . ja v a2 s.co m * return values are not only what the approriate typevalue map say they * are, but also all the other type value maps.all() we'll start with the * obvious part first */ HashSet<IChunk> rtn = new HashSet<IChunk>(); ITypeValueMap<?, IChunk> typeValueMap = getSlotNameTypeValueMap(slot.getName(), slot.getValue(), false); if (typeValueMap != null) rtn.addAll(typeValueMap.not(slot.getValue())); // now let's snag all the rest try { getLock().readLock().lock(); for (ITypeValueMap<?, IChunk> tvm : _slotMap.get(slot.getName().toLowerCase())) { if (tvm != typeValueMap && tvm != null) rtn.addAll(tvm.all()); } return rtn; } finally { getLock().readLock().unlock(); } }
From source file:org.eurekastreams.server.persistence.DomainGroupMapper.java
/** * Get a String representation the Person.id of all of the Person.ids for coordinators and followers of the input * group./*from www.jav a 2s. c om*/ * * @param domainGroup * the DomainGroup to find coordinators and followers for * @return an array of all of the Person.ids for coordinators and followers of the input group */ @SuppressWarnings("unchecked") public Long[] getFollowerAndCoordinatorPersonIds(final DomainGroup domainGroup) { // use a set to eliminate duplicates HashSet<Long> peopleIds = new HashSet<Long>(); Query q = getEntityManager() .createQuery("SELECT pk.followerId FROM GroupFollower WHERE followingId=:groupId") .setParameter("groupId", domainGroup.getId()); peopleIds.addAll(q.getResultList()); q = getEntityManager().createQuery( "SELECT p.id FROM Person p, DomainGroup g WHERE p MEMBER OF g.coordinators AND g.id=:groupId") .setParameter("groupId", domainGroup.getId()); peopleIds.addAll(q.getResultList()); return peopleIds.toArray(new Long[peopleIds.size()]); }
From source file:edu.uci.ics.jung.graph.impl.SimpleSparseVertex.java
/** * @see edu.uci.ics.jung.graph.impl.AbstractSparseVertex#getEdges_internal() *///from w ww . j av a2s . c o m protected Collection getEdges_internal() { HashSet edges = new HashSet(); Collection inEdges = getPredsToInEdges().values(); Collection outEdges = getSuccsToOutEdges().values(); Collection adjacentEdges = getNeighborsToEdges().values(); if (inEdges != null) edges.addAll(inEdges); if (outEdges != null) edges.addAll(outEdges); if (adjacentEdges != null) edges.addAll(adjacentEdges); return edges; }
From source file:com.redhat.victims.database.VictimsSqlDB.java
/** * Internal method implementing search for vulnerabilities checking if the * given {@link VictimsRecord}'s contents are a superset of a record in the * victims database.//w ww . j a v a 2s .co m * * @param vr * @return * @throws SQLException */ protected HashSet<String> getEmbeddedVulnerabilities(VictimsRecord vr) throws SQLException { HashSet<String> cves = new HashSet<String>(); Set<String> hashes = vr.getHashes(Algorithms.SHA512).keySet(); if (hashes.size() <= 0) { return cves; } for (Integer id : getEmbeddedRecords(hashes)) { cves.addAll(getVulnerabilities(id)); } return cves; }