List of usage examples for java.util HashSet addAll
boolean addAll(Collection<? extends E> c);
From source file:org.apache.axis.encoding.SerializationContextImpl.java
/** * The serialize method uses hrefs to reference all non-primitive * values. These values are stored and serialized by calling * outputMultiRefs after the serialize method completes. *//*from ww w . j av a 2s . co m*/ public void outputMultiRefs() throws IOException { if (!doMultiRefs || (multiRefValues == null) || soapConstants == SOAPConstants.SOAP12_CONSTANTS) return; outputMultiRefsFlag = true; AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("","","","",""); String encodingURI = soapConstants.getEncodingURI(); // explicitly state that this attribute is not a root String prefix = getPrefixForURI(encodingURI); String root = prefix + ":root"; attrs.addAttribute(encodingURI, Constants.ATTR_ROOT, root, "CDATA", "0"); // Make sure we put the encodingStyle on each multiref element we // output. String encodingStyle; if (msgContext != null) { encodingStyle = msgContext.getEncodingStyle(); } else { encodingStyle = soapConstants.getEncodingURI(); } String encStyle = getPrefixForURI(soapConstants.getEnvelopeURI()) + ':' + Constants.ATTR_ENCODING_STYLE; attrs.addAttribute(soapConstants.getEnvelopeURI(), Constants.ATTR_ENCODING_STYLE, encStyle, "CDATA", encodingStyle); // Make a copy of the keySet because it could be updated // during processing HashSet keys = new HashSet(); keys.addAll(multiRefValues.keySet()); Iterator i = keys.iterator(); while (i.hasNext()) { while (i.hasNext()) { Object val = i.next(); MultiRefItem mri = (MultiRefItem) multiRefValues.get(val); attrs.setAttribute(0, "", Constants.ATTR_ID, "id", "CDATA", mri.id); forceSer = mri.value; // Now serialize the value. // The sendType parameter is defaulted for interop purposes. // Some of the remote services do not know how to // ascertain the type in these circumstances (though Axis does). serialize(multirefQName, attrs, mri.value, mri.xmlType, true, Boolean.TRUE); // mri.sendType } // Done processing the iterated values. During the serialization // of the values, we may have run into new nested values. These // were placed in the secondLevelObjects map, which we will now // process by changing the iterator to locate these values. if (secondLevelObjects != null) { i = secondLevelObjects.iterator(); secondLevelObjects = null; } } // Reset maps and flags forceSer = null; outputMultiRefsFlag = false; multiRefValues = null; multiRefIndex = -1; secondLevelObjects = null; }
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.PropertyDaoJena.java
/** * Finds the classes that have a definition involving a restriction * on the given property. /* www . ja v a 2s . c o m*/ * * @param propertyURI identifier of a property * @return a list of VClass objects representing the classes that have * definitions involving a restriction on the given property. */ @Override public List<VClass> getClassesWithRestrictionOnProperty(String propertyURI) { if (propertyURI == null) { log.warn("getClassesWithRestrictionOnProperty: called with null propertyURI"); return null; } OntModel ontModel = getOntModel(); ontModel.enterCriticalSection(Lock.READ); HashSet<String> classURISet = new HashSet<String>(); try { Resource targetProp = ontModel.getResource(propertyURI); if (targetProp != null) { StmtIterator stmtIter = ontModel.listStatements((Resource) null, OWL.onProperty, targetProp); while (stmtIter.hasNext()) { Statement statement = stmtIter.next(); if (statement.getSubject().canAs(OntClass.class)) { classURISet.addAll(getRestrictedClasses(statement.getSubject().as(OntClass.class))); } else { log.warn( "getClassesWithRestrictionOnProperty: Unexpected use of onProperty: it is not applied to a class"); } } } else { log.error( "getClassesWithRestrictionOnProperty: Error: didn't find a Property in the ontology model for the URI: " + propertyURI); } } finally { ontModel.leaveCriticalSection(); } List<VClass> classes = new ArrayList<VClass>(); Iterator<String> iter = classURISet.iterator(); VClassDao vcd = getWebappDaoFactory().getVClassDao(); while (iter.hasNext()) { String curi = iter.next(); VClass vc = vcd.getVClassByURI(curi); if (vc != null) { classes.add(vc); } else { log.error("getClassesWithRestrictionOnProperty: Error: no VClass found for URI: " + curi); } } return (classes.size() > 0) ? classes : null; }
From source file:org.ihtsdo.classifier.ClassificationRunner.java
/** * Gets the roles./* w w w. jav a 2 s .co m*/ * * @param parentConcepts the parent concepts * @return the roles * @throws Exception the exception */ private int[] getRoles(HashSet<String> parentConcepts) throws IOException, ClassificationException { HashSet<String> roles = new HashSet<String>(); for (String statedRel : statedRelationships) { File relationshipFile = new File(statedRel); GetDescendants getDesc = new GetDescendants(parentConcepts, relationshipFile, null); getDesc.execute(); roles.addAll(getDesc.getDescendants()); getDesc = null; } roles.add(GetDescendants.ISA_SCTID); int[] result = new int[roles.size()]; int resIdx = 0; for (String role : roles) { Integer integer = conStrList.get(role); if (integer != null) { result[resIdx] = integer; } else { throw new ClassificationException("No entry for " + role + " in conStrList."); } resIdx++; } roles = null; Arrays.sort(result); return result; }
From source file:org.eclipse.smila.security.processing.SampleSecurityConverterPipelet.java
/** * Gets the access rights values from the security information. Depending on the configuration the return values are * the plain values provided by a crawler/search client or are resolved against a SecurityResolver. * /* ww w . ja v a 2s . c om*/ * @param sa * the SecurityAnnotation * @return a Set of Strings containing the values * @throws BlackboardAccessException * if any error occurs * @throws SecurityException * if any security error occurs */ private Set<String> getReadAccessRights(final SecurityAttribute sa) throws BlackboardAccessException, SecurityException { final HashSet<String> accessRights = new HashSet<String>(); final AnySeq users = sa.getAccessRights(AccessRightType.READ, EntityType.PRINCIPALS); final SecurityResolver securityResolver = getSecurityResolver(); // check if there was a security resolver set, else skip any resolving if (securityResolver != null) { if (users != null) { for (final Any user : users) { final String userDN = securityResolver.resolvePrincipal(((Value) user).asString()); accessRights.add(userDN); } } // check if to resolve members of groups if (_resolveGroups) { final AnySeq groups = sa.getAccessRights(AccessRightType.READ, EntityType.GROUPS); if (groups != null) { for (final Any group : groups) { final String groupDN = securityResolver.resolvePrincipal(((Value) group).asString()); final Set<String> groupMembers = securityResolver.resolveGroupMembers(groupDN); accessRights.addAll(groupMembers); } // for } // if } // if // check if to resolve user names to some display name final Set<String> displayNames; if (_resolveUserNames) { displayNames = new HashSet<String>(); for (final String principalDN : accessRights) { final Map<String, Collection<String>> properties = securityResolver.getProperties(principalDN); final Collection<String> resolvedUserNames = properties.get(_resolvedUserNameProperty); if (resolvedUserNames != null && !resolvedUserNames.isEmpty()) { displayNames.add(resolvedUserNames.iterator().next()); } } // for } else { displayNames = accessRights; } return displayNames; } else { if (users != null) { for (final Any user : users) { accessRights.add(((Value) user).asString()); } } return accessRights; } }
From source file:com.datatorrent.lib.io.fs.AbstractFileInputOperatorTest.java
private void checkSubDir(boolean recursive) throws Exception { FileContext.getLocalFSFileContext().delete(new Path(new File(testMeta.dir).getAbsolutePath()), true); HashSet<String> allLines = Sets.newHashSet(); String subdir = ""; for (int file = 0; file < 2; file++) { subdir += String.format("/depth_%d", file); HashSet<String> lines = Sets.newHashSet(); for (int line = 0; line < 2; line++) { lines.add("f" + file + "l" + line); }/* w w w . j a va 2s .c om*/ allLines.addAll(lines); FileUtils.write(new File(testMeta.dir + subdir, "file" + file), StringUtils.join(lines, '\n')); } LineByLineFileInputOperator oper = new LineByLineFileInputOperator(); 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("((?!target).)*file[\\d]"); oper.getScanner().setRecursive(recursive); oper.setup(testMeta.context); for (long wid = 0; wid < 3; wid++) { oper.beginWindow(wid); oper.emitTuples(); oper.endWindow(); } oper.teardown(); int expectedNumTuples = 4; if (!recursive) { allLines = new HashSet<String>(); expectedNumTuples = 0; } Assert.assertEquals("number tuples", expectedNumTuples, queryResults.collectedTuples.size()); Assert.assertEquals("lines", allLines, new HashSet<String>(queryResults.collectedTuples)); }
From source file:dr.evomodel.epidemiology.casetocase.CaseToCaseTreeLikelihood.java
public HashSet<AbstractCase> descendantTipPartitions(NodeRef node, HashMap<Integer, HashSet<AbstractCase>> map) { HashSet<AbstractCase> out = new HashSet<AbstractCase>(); if (treeModel.isExternal(node)) { out.add(getBranchMap().get(node.getNumber())); if (map != null) { map.put(node.getNumber(), out); }/*from w w w.j a va2s.co m*/ return out; } else { for (int i = 0; i < treeModel.getChildCount(node); i++) { out.addAll(descendantTipPartitions(treeModel.getChild(node, i), map)); } if (map != null) { map.put(node.getNumber(), out); } return out; } }
From source file:amie.keys.CombinationsExplorationNew.java
public static void discoverConditionalKeysForComplexConditions(GraphNew graph, HashSet<Node> candidateKeys, Rule conditionRule) {/*from www . j av a 2 s. c om*/ HashSet<Node> childrenCandidateKeys = new HashSet<>(); // System.out.println("candidates:" + candidateKeys); for (Node candidateKey : candidateKeys) { // System.out.println("candidate:" + candidateKey); if (candidateKey.toExplore) { // System.out.println("candidate:" + candidateKey); if (candidateKey.toExplore) { List<String> properties = candidateKey.mapToString(id2Property); // System.out.println("properties:"+properties); Rule amieRule = buildAMIERule(properties, conditionRule); boolean isConditionalKey = isConditionaKey(amieRule); if (amieRule.getSupport() < support || isConditionalKey) { candidateKey.toExplore = false; // System.out.println("key"); flagChildren(graph, candidateKey); } // If the rule is a conditional above the support // and there is no a simpler key already discovered // then output it if (isConditionalKey && amieRule.getSupport() >= support && !isSubsumedByKey(amieRule, conditionRule, conditions2Keys)) { System.out.println(Utilities.formatKey(amieRule)); conditions2Keys.put(conditionRule, amieRule); } if (candidateKey.toExplore) { if (graph.graph.containsKey(candidateKey)) { childrenCandidateKeys.addAll(graph.graph.get(candidateKey)); } } } } else { flagChildren(graph, candidateKey); } } if (!childrenCandidateKeys.isEmpty()) { discoverConditionalKeysForComplexConditions(graph, childrenCandidateKeys, conditionRule); } }
From source file:org.eclipse.smila.security.processing.SampleSecurityConverter.java
/** * Gets the access rights values from the security annotations. Depending on the configuration the return values are * the plain values provided by a crawler/search client or are resolved against a SecurityResolver. * //w ww. j av a2 s . c o m * @param sa * the SecurityAnnotation * @return a Set of Strings containing the values * @throws BlackboardAccessException * if any error occurs * @throws SecurityException * if any security error occurs */ private Set<String> getReadAccessRights(SecurityAnnotation sa) throws BlackboardAccessException, SecurityException { final HashSet<String> accessRights = new HashSet<String>(); final Collection<String> users = sa.getAccessRights(AccessRightType.READ, EntityType.PRINCIPALS) .getAnonValues(); // check if there was a security resolver set, else skip any resolving if (_securityResolver != null) { if (users != null) { for (String user : users) { final String userDN = _securityResolver.resolvePrincipal(user); accessRights.add(userDN); } } // check if to resolve members of groups if (_resolveGroups) { final Collection<String> groups = sa.getAccessRights(AccessRightType.READ, EntityType.GROUPS) .getAnonValues(); if (groups != null) { for (String group : groups) { final String groupDN = _securityResolver.resolvePrincipal(group); final Set<String> groupMembers = _securityResolver.resolveGroupMembers(groupDN); accessRights.addAll(groupMembers); } // for } // if } // if // check if to resolve user names to some display name Set<String> displayNames = new HashSet<String>(); if (_resolveUserNames) { for (String principalDN : accessRights) { final Map<String, Collection<String>> properties = _securityResolver.getProperties(principalDN); final Collection<String> resolvedUserNames = properties.get(_resolvedUserNameProperty); if (resolvedUserNames != null && !resolvedUserNames.isEmpty()) { displayNames.add(resolvedUserNames.iterator().next()); } } // for } else { displayNames = accessRights; } return displayNames; } else { if (users != null) { accessRights.addAll(users); } return accessRights; } }
From source file:com.pinterest.deployservice.db.DBDAOTest.java
@Test public void testGroupDAO() throws Exception { groupDAO.addGroupCapacity("env-id3", "group3"); groupDAO.addGroupCapacity("env-id4", "group4"); groupDAO.addGroupCapacity("env-id5", "group3"); List<String> envids = groupDAO.getEnvsByGroupName("group3"); assertEquals(envids.size(), 2);//from ww w . j ava2 s. co m HashSet<String> target_ids = new HashSet<>(); target_ids.addAll(envids); assertTrue(target_ids.contains("env-id3")); assertTrue(target_ids.contains("env-id5")); List<String> groups = groupDAO.getAllEnvGroups(); assertEquals(groups.size(), 2); }
From source file:com.rovemonteux.silvertunnel.netlib.layer.tor.directory.Directory.java
/** * Exclude related nodes: family, class C and country (if specified in * TorConfig)./*w ww. jav a 2 s . co m*/ * * @param r * node that should be excluded with all its relations * @return set of excluded node names */ public Set<Fingerprint> excludeRelatedNodes(final Router r) { final HashSet<Fingerprint> excludedServerfingerprints = new HashSet<Fingerprint>(); HashSet<Fingerprint> myAddressNeighbours, myCountryNeighbours; if (TorConfig.isRouteUniqueClassC()) { myAddressNeighbours = getAddressNeighbours(r.getAddress().getHostAddress()); if (myAddressNeighbours != null) { excludedServerfingerprints.addAll(myAddressNeighbours); } } else { excludedServerfingerprints.add(r.getFingerprint()); } // exclude all country insider, if desired if (TorConfig.isRouteUniqueCountry()) { myCountryNeighbours = countryNeighbours.get(r.getCountryCode()); if (myCountryNeighbours != null) { excludedServerfingerprints.addAll(myCountryNeighbours); } } // exclude its family as well excludedServerfingerprints.addAll(r.getFamily()); return excludedServerfingerprints; }