List of usage examples for java.util HashSet addAll
boolean addAll(Collection<? extends E> c);
From source file:com.healthcit.cacure.businessdelegates.QuestionAnswerManager.java
public DuplicateResultBean hasShortNameDuplicates(List<String> collectedShortNames) { HashSet<String> uniqShortnamesSet = new HashSet<String>(collectedShortNames); HashSet<String> duplShortnamesSet = new HashSet<String>(); if (uniqShortnamesSet.size() != collectedShortNames.size()) { for (String uniqSn : uniqShortnamesSet) { collectedShortNames.remove(uniqSn); }/*from w w w. j a v a 2 s. c o m*/ duplShortnamesSet.addAll(collectedShortNames); } Set<String> exactQuestionsShortNames = qstDao.getQuestionsShortNamesLike(uniqShortnamesSet, true); duplShortnamesSet.addAll(exactQuestionsShortNames); Set<String> exactTableShortNames = teDao.getTableShortNamesLike(uniqShortnamesSet, true); duplShortnamesSet.addAll(exactTableShortNames); if (duplShortnamesSet.isEmpty()) { return new DuplicateResultBean(DuplicateResultType.OK, null); } else { return new DuplicateResultBean(DuplicateResultType.NOT_UNIQUE, duplShortnamesSet.toArray(new String[0])); } }
From source file:org.apache.olingo.fit.utils.AbstractUtilities.java
public void putLinksInMemory(final String basePath, final String entitySetName, final String entityKey, final String linkName, final Collection<String> links) throws Exception { final HashSet<String> uris = new HashSet<String>(); final Map<String, NavigationProperty> navigationProperties = metadata .getNavigationProperties(entitySetName); // check for nullability in order to support navigation property on open types if (navigationProperties.get(linkName) != null && navigationProperties.get(linkName).isEntitySet()) { try {//w w w . j ava 2 s .c om final Map.Entry<String, List<String>> currents = extractLinkURIs(entitySetName, entityKey, linkName); uris.addAll(currents.getValue()); } catch (Exception ignore) { // Expected exception } } uris.addAll(links); putLinksInMemory(basePath, entitySetName, linkName, uris); }
From source file:org.alfresco.repo.solr.SOLRTrackingComponentTest.java
private List<Transaction> checkTransactions(List<Transaction> txns, List<Long> createdTransaction, int[] updates, int[] deletes) { ArrayList<Transaction> matchedTransactions = new ArrayList<Transaction>(); HashSet<Long> toMatch = new HashSet<Long>(); toMatch.addAll(createdTransaction); for (Transaction found : txns) { if (found != null) { if (toMatch.contains(found.getId())) { matchedTransactions.add(found); }// w w w.j av a 2 s . com } } assertEquals("Number of transactions is incorrect", createdTransaction.size(), matchedTransactions.size()); int i = 0; for (Transaction txn : matchedTransactions) { assertEquals("Number of deletes is incorrect", deletes[i], txn.getDeletes()); assertEquals("Number of updates is incorrect", updates[i], txn.getUpdates()); i++; } return matchedTransactions; }
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.PropertyDaoJena.java
/** * Find named classes to which a restriction "applies" * @param resourceURI identifier of a class * @return set of class URIs/*from w w w. ja v a 2 s .com*/ * * Note: this method assumes that the caller holds a read lock on * the ontology model. */ public HashSet<String> getRestrictedClasses(OntClass ontClass) { HashSet<String> classSet = new HashSet<String>(); List<OntClass> classList = ontClass.listEquivalentClasses().toList(); classList.addAll(ontClass.listSubClasses().toList()); Iterator<OntClass> it = classList.iterator(); while (it.hasNext()) { OntClass oc = it.next(); if (!oc.isAnon()) { classSet.add(oc.getURI()); } else { classSet.addAll(getRestrictedClasses(oc)); } } return classSet; }
From source file:org.apache.pig.backend.hadoop.executionengine.MRExecutionEngine.java
@SuppressWarnings("unchecked") public PhysicalPlan compile(LogicalPlan plan, Properties properties) throws FrontendException { if (plan == null) { int errCode = 2041; String msg = "No Plan to compile"; throw new FrontendException(msg, errCode, PigException.BUG); }//from www. j a v a 2 s . c o m newPreoptimizedPlan = new LogicalPlan(plan); if (pigContext.inIllustrator) { // disable all PO-specific optimizations POOptimizeDisabler pod = new POOptimizeDisabler(plan); pod.visit(); } UidResetter uidResetter = new UidResetter(plan); uidResetter.visit(); SchemaResetter schemaResetter = new SchemaResetter(plan, true /* * skip * duplicate * uid check */); schemaResetter.visit(); HashSet<String> disabledOptimizerRules; try { disabledOptimizerRules = (HashSet<String>) ObjectSerializer .deserialize(pigContext.getProperties().getProperty(PigImplConstants.PIG_OPTIMIZER_RULES_KEY)); } catch (IOException ioe) { int errCode = 2110; String msg = "Unable to deserialize optimizer rules."; throw new FrontendException(msg, errCode, PigException.BUG, ioe); } if (disabledOptimizerRules == null) { disabledOptimizerRules = new HashSet<String>(); } String pigOptimizerRulesDisabled = this.pigContext.getProperties() .getProperty(PigConstants.PIG_OPTIMIZER_RULES_DISABLED_KEY); if (pigOptimizerRulesDisabled != null) { disabledOptimizerRules.addAll(Lists.newArrayList((Splitter.on(",").split(pigOptimizerRulesDisabled)))); } if (pigContext.inIllustrator) { disabledOptimizerRules.add("MergeForEach"); disabledOptimizerRules.add("PartitionFilterOptimizer"); disabledOptimizerRules.add("LimitOptimizer"); disabledOptimizerRules.add("SplitFilter"); disabledOptimizerRules.add("PushUpFilter"); disabledOptimizerRules.add("MergeFilter"); disabledOptimizerRules.add("PushDownForEachFlatten"); disabledOptimizerRules.add("ColumnMapKeyPrune"); disabledOptimizerRules.add("AddForEach"); disabledOptimizerRules.add("GroupByConstParallelSetter"); } StoreAliasSetter storeAliasSetter = new StoreAliasSetter(plan); storeAliasSetter.visit(); // run optimizer LogicalPlanOptimizer optimizer = new LogicalPlanOptimizer(plan, 100, disabledOptimizerRules); optimizer.optimize(); // compute whether output data is sorted or not SortInfoSetter sortInfoSetter = new SortInfoSetter(plan); sortInfoSetter.visit(); if (!pigContext.inExplain) { // Validate input/output file. Currently no validation framework in // new logical plan, put this validator here first. // We might decide to move it out to a validator framework in future InputOutputFileValidator validator = new InputOutputFileValidator(plan, pigContext); validator.validate(); } // translate new logical plan to physical plan LogToPhyTranslationVisitor translator = new LogToPhyTranslationVisitor(plan); translator.setPigContext(pigContext); translator.visit(); newLogToPhyMap = translator.getLogToPhyMap(); return translator.getPhysicalPlan(); }
From source file:aml.match.CompoundAlignment.java
/** * @param id: the index of the class to check in the alignment * @return the list of all classes mapped to the given class *//*from ww w .j a v a 2 s.c om*/ public Set<Integer> getMappingsBidirectional(int id) { HashSet<Integer> mappings = new HashSet<Integer>(); if (sourceMaps.contains(id)) mappings.addAll(sourceMaps.keySet(id)); if (targetMaps1.contains(id)) mappings.addAll(targetMaps1.keySet(id)); if (targetMaps2.contains(id)) mappings.addAll(targetMaps2.keySet(id)); return mappings; }
From source file:org.biopax.ols.impl.BaseOBO2AbstractLoader.java
/** * internal helper method to create TermPathBeans for a given term. This method will * precompute all paths from a parent to all its children for the 3 major relationship types: * IS_A, PART_OF and DEVELOPS_FROM. The PART_OF and DEVELOPS_FROM relations can traverse IS_A * relations for maximal completeness and still be semantically correct, but IS_A relationships * cannot traverse other relation types. * <pre>/*from www . ja v a 2 s .c o m*/ * term1 * |_ child1 child1 IS_A term1 * |_ child2 child2 IS_A term1 * subject pred object * </pre> * * @param obj - the OBOEdit term object to extract information from * @param trm - the OLS parent term to link to * @return a Collection of valid TermRelationshipBeans */ private Collection<TermPath> processPaths(OBOObject obj, TermBean trm) { HashSet<TermPath> retval = new HashSet<TermPath>(); HashMap<String, Integer> paths = parser.computeChildPaths(1, IS_A_SET, obj); retval.addAll(createTermPathBeans(paths, Constants.IS_A_RELATION_TYPE_ID, IS_A, trm)); //the part_of relation can traverse is_a relations to generate term_paths //so the set passed to computeChildPaths needs to contain both PART_OF and IS_A labels. HashSet<String> traversingSet = new HashSet<String>(); traversingSet.addAll(PART_OF_SET); traversingSet.addAll(IS_A_SET); paths = parser.computeChildPaths(1, traversingSet, obj); retval.addAll(createTermPathBeans(paths, Constants.PART_OF_RELATION_TYPE_ID, PART_OF, trm)); //the dev_from relation can traverse is_a relations to generate term_paths //so the set passed to computeChildPaths needs to contain both DEV_FROM and IS_A labels. traversingSet.clear(); traversingSet.addAll(DEV_FROM_SET); traversingSet.addAll(IS_A_SET); paths = parser.computeChildPaths(1, traversingSet, obj); retval.addAll(createTermPathBeans(paths, Constants.DEVELOPS_FROM_RELATION_TYPE_ID, DEVELOPS_FROM, trm)); return retval; }
From source file:com.datatorrent.lib.io.fs.AbstractFileInputOperatorTest.java
@Test public void testStateWithIdempotency() throws Exception { FileContext.getLocalFSFileContext().delete(new Path(new File(testMeta.dir).getAbsolutePath()), true); HashSet<String> allLines = Sets.newHashSet(); for (int file = 0; file < 3; file++) { HashSet<String> lines = Sets.newHashSet(); for (int line = 0; line < 2; line++) { lines.add("f" + file + "l" + line); }/*from w w w. ja v a 2 s . co m*/ allLines.addAll(lines); FileUtils.write(new File(testMeta.dir, "file" + file), StringUtils.join(lines, '\n')); } LineByLineFileInputOperator oper = new LineByLineFileInputOperator(); FSWindowDataManager manager = new FSWindowDataManager(); manager.setStatePath(testMeta.dir + "/recovery"); oper.setWindowDataManager(manager); CollectorTestSink<String> queryResults = new CollectorTestSink<String>(); @SuppressWarnings({ "unchecked", "rawtypes" }) CollectorTestSink<Object> sink = (CollectorTestSink) queryResults; oper.output.setSink(sink); oper.setDirectory(testMeta.dir); oper.getScanner().setFilePatternRegexp(".*file[\\d]"); oper.setup(testMeta.context); for (long wid = 0; wid < 4; wid++) { oper.beginWindow(wid); oper.emitTuples(); oper.endWindow(); } oper.teardown(); sink.clear(); //idempotency part oper.pendingFiles.add(new File(testMeta.dir, "file0").getAbsolutePath()); oper.failedFiles.add( new AbstractFileInputOperator.FailedFile(new File(testMeta.dir, "file1").getAbsolutePath(), 0)); oper.unfinishedFiles.add( new AbstractFileInputOperator.FailedFile(new File(testMeta.dir, "file2").getAbsolutePath(), 0)); oper.setup(testMeta.context); for (long wid = 0; wid < 4; wid++) { oper.beginWindow(wid); oper.endWindow(); } Assert.assertTrue("pending state", !oper.pendingFiles.contains("file0")); for (AbstractFileInputOperator.FailedFile failedFile : oper.failedFiles) { Assert.assertTrue("failed state", !failedFile.path.equals("file1")); } for (AbstractFileInputOperator.FailedFile unfinishedFile : oper.unfinishedFiles) { Assert.assertTrue("unfinished state", !unfinishedFile.path.equals("file2")); } oper.teardown(); }
From source file:amie.keys.CSAKey.java
/** * Construction of the maps from properties -> id and id -> properties */// w ww . j av a 2s . c o m private static void buildDictionaries(List<List<String>> nonKeys, HashSet<HashSet<Integer>> nonKeysInt, HashMap<String, Integer> property2Id, HashMap<Integer, String> id2Property, List<Integer> propertiesList, int support, KB kb) { int id = 0; HashSet<HashSet<Integer>> nonKeysIntTmp = new HashSet<>(); for (List<String> nonKey : nonKeys) { HashSet<Integer> nonKeyInt = new HashSet<>(); for (int k = 0; k < nonKey.size(); ++k) { // Ignore String property = nonKey.get(k); //**** Debugging code ***/ /*// List<String> testingProperties = Arrays.asList("db:campus", "db:mascot", "db:officialschoolcolour", "db:athletics", "db:country"); // if (getPropertySupport(property, kb) < support || !testingProperties.contains(property)) { // continue; // } */ //**** Debugging code ***/ if (!property2Id.containsKey(property)) { property2Id.put(property, id); id2Property.put(id, property); propertiesList.add(id); ++id; } Integer idProperty = property2Id.get(property); nonKeyInt.add(idProperty); } nonKeysIntTmp.add(nonKeyInt); } nonKeysInt.addAll(simplifyHashNonKeySet(nonKeysIntTmp)); //System.out.println("Simplified " + nonKeysInt + "\tThread " + Thread.currentThread().getId() + "\t" + id2Property); }
From source file:com.evolveum.midpoint.model.common.stringpolicy.ValuePolicyProcessor.java
public <O extends ObjectType> boolean validateValue(String newValue, ValuePolicyType pp, AbstractValuePolicyOriginResolver<O> originResolver, List<LocalizableMessage> messages, String shortDesc, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException { //TODO: do we want to throw exception when no value policy defined?? Validate.notNull(pp, "Value policy must not be null."); OperationResult result = parentResult.createSubresult(OPERATION_STRING_POLICY_VALIDATION); result.addArbitraryObjectAsParam("policyName", pp.getName()); normalize(pp);//from www.ja va 2 s. c o m if (newValue == null && defaultIfNull(XsdTypeMapper.multiplicityToInteger(pp.getMinOccurs()), 0) == 0) { // No value is allowed result.recordSuccess(); return true; } if (newValue == null) { newValue = ""; } LimitationsType lims = pp.getStringPolicy().getLimitations(); testMinimalLength(newValue, lims, result, messages); testMaximalLength(newValue, lims, result, messages); testMinimalUniqueCharacters(newValue, lims, result, messages); testProhibitedValues(newValue, pp.getProhibitedValues(), originResolver, shortDesc, task, result, messages); testCheckExpression(newValue, lims, originResolver, shortDesc, task, result, messages); if (!lims.getLimit().isEmpty()) { // check limitation HashSet<String> validChars; HashSet<String> allValidChars = new HashSet<>(); List<String> characters = StringPolicyUtils.stringTokenizer(newValue); for (StringLimitType stringLimitationType : lims.getLimit()) { OperationResult limitResult = new OperationResult( "Tested limitation: " + stringLimitationType.getDescription()); validChars = getValidCharacters(stringLimitationType.getCharacterClass(), pp); int count = countValidCharacters(validChars, characters); allValidChars.addAll(validChars); testMinimalOccurrence(stringLimitationType, count, limitResult, messages); testMaximalOccurrence(stringLimitationType, count, limitResult, messages); testMustBeFirst(stringLimitationType, limitResult, messages, newValue, validChars); limitResult.computeStatus(); result.addSubresult(limitResult); } testInvalidCharacters(characters, allValidChars, result, messages); } result.computeStatus(); if (!result.isSuccess() && !messages.isEmpty()) { result.setUserFriendlyMessage(new LocalizableMessageListBuilder().messages(messages) .separator(LocalizableMessageList.SPACE).buildOptimized()); } return result.isAcceptable(); }