List of usage examples for java.util Set containsAll
boolean containsAll(Collection<?> c);
From source file:org.fao.geonet.services.user.List.java
public Element exec(Element params, ServiceContext context) throws Exception { UserSession session = context.getUserSession(); //--- retrieve groups for myself Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); Set<String> hsMyGroups = getGroups(dbms, session.getUserId(), session.getProfile()); Set profileSet = context.getProfileManager().getProfilesSet(session.getProfile()); //--- retrieve all users Element elUsers = dbms.select("SELECT * FROM Users ORDER BY username"); //--- now filter them java.util.List<Element> alToRemove = new ArrayList<Element>(); for (Iterator i = elUsers.getChildren().iterator(); i.hasNext();) { Element elRec = (Element) i.next(); String userId = elRec.getChildText("id"); String profile = elRec.getChildText("profile"); if (!hsMyGroups.containsAll(getGroups(dbms, userId, profile))) alToRemove.add(elRec);// w ww . j ava 2 s. co m if (!profileSet.contains(profile)) alToRemove.add(elRec); } //--- remove unwanted users for (Element elem : alToRemove) elem.detach(); //--- return result //Element result = new Element(Jeeves.Elem.RESPONSE) ; String id = Util.getParam(params, Params.ID, null); if (StringUtils.isNotEmpty(id)) { //result.addContent(new Element(Geonet.Elem.ID).setText(id)); elUsers.addContent(new Element(Geonet.Elem.ID).setText(id)); } //result.addContent(elUsers); //return result; return elUsers; }
From source file:org.drools.semantics.lang.dl.DL_9_CompilationTest.java
@Test public void testIncrementalCompilation() { try {//w w w . ja v a2 s. c om OntoModel diamond = factory.buildModel("diamondX", ResourceFactory.newClassPathResource("ontologies/diamondProp.manchester.owl"), DLFactoryConfiguration.newConfiguration(OntoModel.Mode.OPTIMIZED)); compiler = new OntoModelCompiler(diamond, folder.getRoot()); List<Diagnostic<? extends JavaFileObject>> diag1 = compiler .compileOnTheFly(OntoModelCompiler.minimalOptions, OntoModelCompiler.MOJO_VARIANTS.JPA2); for (Diagnostic<?> dx : diag1) { System.out.println(dx); assertFalse(dx.getKind() == Diagnostic.Kind.ERROR); } showDirContent(folder); ClassLoader urlKL = new URLClassLoader(new URL[] { compiler.getBinDir().toURI().toURL() }, Thread.currentThread().getContextClassLoader()); OntoModel results = factory.buildModel("diamondInc", ResourceFactory.newClassPathResource("ontologies/dependency.test.owl"), DLFactoryConfiguration.newConfiguration(OntoModel.Mode.OPTIMIZED), urlKL); System.out.println(results); Class bot = Class.forName("org.jboss.drools.semantics.diamond.BottomImpl", true, urlKL); Class botIF = Class.forName("org.jboss.drools.semantics.diamond.Bottom", true, urlKL); Assert.assertNotNull(bot); Assert.assertNotNull(botIF); Object botInst = bot.newInstance(); Assert.assertNotNull(botInst); OntoModelCompiler compiler2 = new OntoModelCompiler(results, folder.getRoot()); compiler2.fixResolvedClasses(); compiler2.streamJavaInterfaces(false); compiler2.streamXSDsWithBindings(true); compiler2.mojo(OntoModelCompiler.defaultOptions, OntoModelCompiler.MOJO_VARIANTS.JPA2); showDirContent(folder); File unImplBoundLeft = new File(compiler2.getXjcDir() + File.separator + "org.jboss.drools.semantics.diamond".replace(".", File.separator) + File.separator + "Left.java"); assertFalse(unImplBoundLeft.exists()); File implBoundLeft = new File(compiler2.getXjcDir() + File.separator + "org.jboss.drools.semantics.diamond".replace(".", File.separator) + File.separator + "LeftImpl.java"); assertTrue(implBoundLeft.exists()); File leftInterface = new File(compiler2.getJavaDir() + File.separator + "org.jboss.drools.semantics.diamond".replace(".", File.separator) + File.separator + "Left.java"); assertTrue(leftInterface.exists()); List<Diagnostic<? extends JavaFileObject>> diagnostics = compiler2.doCompile(); for (Diagnostic<?> dx : diagnostics) { System.out.println(dx); assertFalse(dx.getKind() == Diagnostic.Kind.ERROR); } showDirContent(folder); Document dox = parseXML(new File(compiler2.getBinDir().getPath() + "/META-INF/persistence.xml"), false); XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile("//persistence-unit/@name"); assertEquals("diamondX", (String) expr.evaluate(dox, XPathConstants.STRING)); File YInterface = new File(compiler2.getJavaDir() + File.separator + "org.jboss.drools.semantics.diamond".replace(".", File.separator) + File.separator + "X.java"); assertTrue(YInterface.exists()); Class colf = Class.forName("some.dependency.test.ChildOfLeftImpl", true, urlKL); Assert.assertNotNull(colf); Object colfInst = colf.newInstance(); List<String> hierarchy = getHierarchy(colf); assertTrue(hierarchy.contains("some.dependency.test.ChildOfLeftImpl")); assertTrue(hierarchy.contains("some.dependency.test.org.jboss.drools.semantics.diamond.LeftImpl")); assertTrue(hierarchy.contains("org.jboss.drools.semantics.diamond.LeftImpl")); assertTrue(hierarchy.contains("org.jboss.drools.semantics.diamond.C0Impl")); assertTrue(hierarchy.contains("org.jboss.drools.semantics.diamond.TopImpl")); assertTrue(hierarchy.contains("org.w3._2002._07.owl.ThingImpl")); Set<String> itfHierarchy = getIFHierarchy(colf); System.err.println(itfHierarchy.containsAll( Arrays.asList("org.jboss.drools.semantics.diamond.C1", "org.jboss.drools.semantics.diamond.C0", "some.dependency.test.org.jboss.drools.semantics.diamond.Left", "some.dependency.test.ChildOfLeft", "org.jboss.drools.semantics.diamond.Left", "org.jboss.drools.semantics.diamond.Top", "com.clarkparsia.empire.EmpireGenerated", "org.w3._2002._07.owl.Thing", "java.io.Serializable", "org.drools.semantics.Thing", "com.clarkparsia.empire.SupportsRdfId"))); Method getter1 = colf.getMethod("getAnotherLeftProp"); assertNotNull(getter1); Method getter2 = colf.getMethod("getImportantProp"); assertNotNull(getter2); for (Method m : colf.getMethods()) { if (m.getName().equals("addImportantProp")) { m.getName(); } } Method adder = colf.getMethod("addImportantProp", botIF); assertNotNull(adder); adder.invoke(colfInst, botInst); List l = (List) getter2.invoke(colfInst); assertEquals(1, l.size()); File off = new File(compiler2.getXjcDir() + File.separator + "org.jboss.drools.semantics.diamond".replace(".", File.separator) + File.separator + "Left_Off.java"); assertFalse(off.exists()); testPersistenceWithInstance(urlKL, "org.jboss.drools.semantics.diamond.Bottom", diamond.getName()); System.out.println(" Done"); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:com.streamsets.datacollector.validation.PipelineFragmentConfigurationValidator.java
boolean sortStages(boolean sortOriginalStages) { boolean ok = true; List<StageConfiguration> original; if (sortOriginalStages) { original = new ArrayList<>(pipelineFragmentConfiguration.getOriginalStages()); } else {//from ww w .java2 s . c om original = new ArrayList<>(pipelineFragmentConfiguration.getStages()); } List<StageConfiguration> sorted = new ArrayList<>(); Set<String> producedOutputs = new HashSet<>(); while (ok && !original.isEmpty()) { int prior = sorted.size(); Iterator<StageConfiguration> it = original.iterator(); while (it.hasNext()) { StageConfiguration stage = it.next(); if (producedOutputs.containsAll(stage.getInputLanes())) { producedOutputs.addAll(stage.getOutputAndEventLanes()); it.remove(); sorted.add(stage); } } if (prior == sorted.size()) { // pipeline has not stages at all List<String> names = new ArrayList<>(original.size()); for (StageConfiguration stage : original) { names.add(stage.getInstanceName()); } issues.add(IssueCreator.getPipeline().create(ValidationError.VALIDATION_0002, names)); ok = false; } } sorted.addAll(original); if (sortOriginalStages) { pipelineFragmentConfiguration.setOriginalStages(sorted); } else { pipelineFragmentConfiguration.setStages(sorted); } return ok; }
From source file:org.openqa.selenium.TakesScreenshotTest.java
private void compareColors(Set<String> expectedColors, Set<String> actualColors) { TreeSet<String> c = new TreeSet<String>(expectedColors); c.removeAll(actualColors);// w w w. j a va2 s . c o m if (!c.isEmpty()) { fail("Unknown expected color is generated: " + c.toString() + ", \n" + " actual colors are: " + actualColors.toString()); } if (actualColors.containsAll(expectedColors)) { // all is ok } else { actualColors.removeAll(expectedColors); fail("Unknown colors are presented at screenshot: " + actualColors.toString() + " \n" + " expected colors are excluded: " + expectedColors.toString()); } }
From source file:org.apigw.authserver.svc.impl.TokenServicesImpl.java
/** * Create a refreshed authentication./*w ww . java2 s . c o m*/ * * @param authentication The authentication. * @param scope The scope for the refreshed token. * @return The refreshed authentication. * @throws InvalidScopeException If the scope requested is invalid or wider than the original scope. */ protected OAuth2Authentication createRefreshedAuthentication(OAuth2Authentication authentication, Set<String> scope) { log.debug("createRefreshedAuthentication"); OAuth2Authentication narrowed = authentication; if (scope != null && !scope.isEmpty()) { AuthorizationRequest clientAuth = authentication.getAuthorizationRequest(); Set<String> originalScope = clientAuth.getScope(); if (originalScope == null || !originalScope.containsAll(scope)) { throw new InvalidScopeException( "Unable to narrow the scope of the client authentication to " + scope + ".", originalScope); } else { narrowed = new OAuth2Authentication(clientAuth, authentication.getUserAuthentication()); } } log.debug("returning from createRefreshedAuthentication"); return narrowed; }
From source file:org.apache.geode.management.internal.cli.commands.GfshCommandJUnitTest.java
@Test public void testGetMembersContainsOnlySelf() { final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache"); final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem"); final DistributedMember mockMemberSelf = createMockMember("S", "Self"); mockContext.checking(new Expectations() { {/*ww w .ja va2 s . c om*/ oneOf(mockCache).getMembers(); will(returnValue(Collections.emptySet())); oneOf(mockCache).getDistributedSystem(); will(returnValue(mockDistributedSystem)); oneOf(mockDistributedSystem).getDistributedMember(); will(returnValue(mockMemberSelf)); } }); final GfshCommand commands = createAbstractCommandsSupport(mockCache); final Set<DistributedMember> expectedMembers = CollectionUtils.asSet(mockMemberSelf); final Set<DistributedMember> actualMembers = commands.getMembers(mockCache); assertNotNull(actualMembers); assertEquals(expectedMembers.size(), actualMembers.size()); assertTrue(actualMembers.containsAll(expectedMembers)); }
From source file:podd.util.WebappInitializationUtil.java
private boolean testSameOntology(OWLOntology curOntology, OWLClass concept, Set<OWLAxiom> axiomSet) { final Set<OWLAxiom> oldAxiomSet = new HashSet<OWLAxiom>(); oldAxiomSet.addAll(curOntology.getAxioms(concept)); oldAxiomSet.addAll(curOntology.getEntityAnnotationAxioms(concept)); final int oldCount = oldAxiomSet.size(); final int newCount = axiomSet.size(); return oldCount == newCount && oldAxiomSet.containsAll(axiomSet); }
From source file:org.apache.geode.management.internal.cli.commands.GfshCommandJUnitTest.java
@Test public void testGetMembers() { final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache"); final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem"); final DistributedMember mockMemberSelf = createMockMember("S", "Self"); final DistributedMember mockMemberOne = createMockMember("1", "One"); final DistributedMember mockMemberTwo = createMockMember("2", "Two"); mockContext.checking(new Expectations() { {/*from www . ja va2s. co m*/ oneOf(mockCache).getMembers(); will(returnValue(CollectionUtils.asSet(mockMemberOne, mockMemberTwo))); oneOf(mockCache).getDistributedSystem(); will(returnValue(mockDistributedSystem)); oneOf(mockDistributedSystem).getDistributedMember(); will(returnValue(mockMemberSelf)); } }); final GfshCommand commands = createAbstractCommandsSupport(mockCache); final Set<DistributedMember> expectedMembers = CollectionUtils.asSet(mockMemberOne, mockMemberTwo, mockMemberSelf); final Set<DistributedMember> actualMembers = commands.getMembers(mockCache); assertNotNull(actualMembers); assertEquals(expectedMembers.size(), actualMembers.size()); assertTrue(actualMembers.containsAll(expectedMembers)); }
From source file:org.thingsboard.server.controller.BaseEntityViewControllerTest.java
@Test public void testTheCopyOfAttrsIntoTSForTheView() throws Exception { Set<String> actualAttributesSet = getAttributesByKeys( "{\"caKey1\":\"value1\", \"caKey2\":true, \"caKey3\":42.0, \"caKey4\":73}"); Set<String> expectedActualAttributesSet = new HashSet<>( Arrays.asList("caKey1", "caKey2", "caKey3", "caKey4")); assertTrue(actualAttributesSet.containsAll(expectedActualAttributesSet)); EntityView savedView = getNewSavedEntityView("Test entity view"); Thread.sleep(1000);/*from w w w . ja v a 2 s .c o m*/ List<Map<String, Object>> values = doGetAsync( "/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() + "/values/attributes?keys=" + String.join(",", actualAttributesSet), List.class); assertEquals("value1", getValue(values, "caKey1")); assertEquals(true, getValue(values, "caKey2")); assertEquals(42.0, getValue(values, "caKey3")); assertEquals(73, getValue(values, "caKey4")); }
From source file:org.apache.kylin.cube.upgrade.V1_5_1.CubeDescUpgrade_v_1_5_1.java
private void upgradeAggregationGroup(org.apache.kylin.cube.model.CubeDesc newModel) { List<AggregationGroup> aggs = Lists.newArrayList(); if (oldAggGroup == null || oldAggGroup.length == 0) { oldAggGroup = new String[1][]; oldAggGroup[0] = toArray(allRowKeyCols); }//from w ww . j ava2 s . co m if (rowKeyColExistsInMultipleAggGroup()) { throw new IllegalArgumentException("rowKeyColExistsInMultipleAggGroup!"); } Set<String> visited = newIgnoreCaseSet(null); for (String[] group : oldAggGroup) { AggregationGroup agg = new AggregationGroup(); Set<String> remaining = newIgnoreCaseSet(allRowKeyCols); remaining.removeAll(visited); Set<String> joint = newIgnoreCaseSet(remaining); joint.removeAll(oldMandatories); Set<String> groupAsSet = newIgnoreCaseSet(null); for (String entry : group) { groupAsSet.add(entry); } visited.addAll(groupAsSet); joint.removeAll(groupAsSet); List<String> mandatories = Lists.newArrayList(); List<String[]> hierarchies = Lists.newArrayList(); for (String s : oldMandatories) { mandatories.add(s); } for (String[] h : oldHierarchies) { if (groupAsSet.containsAll(Arrays.asList(h))) { hierarchies.add(h); } } agg.setIncludes(toArray(remaining)); SelectRule selectRule = new SelectRule(); selectRule.hierarchyDims = hierarchies.toArray(new String[hierarchies.size()][]); if (joint.size() != 0) { selectRule.jointDims = new String[1][]; selectRule.jointDims[0] = joint.toArray(new String[joint.size()]); } else { selectRule.jointDims = new String[0][]; } selectRule.mandatoryDims = mandatories.toArray(new String[mandatories.size()]); agg.setSelectRule(selectRule); aggs.add(agg); } newModel.setAggregationGroups(aggs); }