List of usage examples for java.util Collection containsAll
boolean containsAll(Collection<?> c);
From source file:pt.ist.maidSyncher.domain.MaidRoot.java
/** * /* w ww . j a v a 2 s .co m*/ * @param syncActionWrapper {@link SyncActionWrapper} to validate * @throws Exception if there is any kind of problem with it * It verifies the syncActionWrapper for an originationg sync event; * That the lists are not null, that all of the property descriptors were ticked, etc; */ @ShoutOutTo(value = { "the guy that thought that including a null was a good idea" }) private void validate(SyncActionWrapper syncActionWrapper, SyncEvent syncEvent) { checkNotNull(syncActionWrapper.getOriginatingSyncEvent()); checkNotNull(syncActionWrapper.getOriginatingSyncEvent().getOriginObject()); checkNotNull(syncActionWrapper.getOriginatingSyncEvent().getDsiElement()); checkNotNull(syncActionWrapper.getPropertyDescriptorNamesTicked()); try { checkNotNull(syncActionWrapper.getSyncDependedDSIObjects()); } catch (NullPointerException ex) { //An NPE might occur here, but that doesn't mean that this is invalid } checkNotNull(syncActionWrapper.getSyncDependedTypesOfDSIObjects()); if (syncActionWrapper.getOriginatingSyncEvent().equals(syncEvent) == false) { throw new IllegalArgumentException("Sync events from wrapper and original event differ"); } Collection<String> propertyDescriptorsTicked = syncActionWrapper.getPropertyDescriptorNamesTicked(); Collection<String> changedPropertyDescriptors = syncActionWrapper.getOriginatingSyncEvent() .getChangedPropertyDescriptorNames().getUnmodifiableList(); if (!propertyDescriptorsTicked.containsAll(changedPropertyDescriptors)) { //let's generate a log registerPropertyDescriptorNotConsideredWarning(changedPropertyDescriptors, propertyDescriptorsTicked, syncEvent); } }
From source file:org.drools.guvnor.server.generators.ServiceWarGeneratorTest.java
@Test public void testWs() throws IOException, URISyntaxException { setupLocalCache();/*from ww w.j av a 2 s . c o m*/ final File temp = File.createTempFile("drools-service", ".jar"); // Delete temp file when program exits. temp.deleteOnExit(); final OutputStream out = new FileOutputStream(temp); final Map<String, File> models = new HashMap<String, File>() { { put("jarWithSourceFiles.jar", new File(ServiceWarGeneratorTest.class.getClassLoader().getResource(MODEL_NAME).toURI())); } }; buildWar(new ServiceConfig(WS_SERVICE_CONFIG), models, out); final WebArchive archive = ShrinkWrap.createFromZipFile(WebArchive.class, temp); final Collection<String> fileNames = new LinkedList<String>(); for (final Map.Entry<ArchivePath, Node> entry : archive.getContent().entrySet()) { final String extension = getExtension(entry.getKey().get()); final String fileName = getName(entry.getKey().get()); if (extension.equalsIgnoreCase("jar")) { fileNames.add(fileName); } else if (extension.equalsIgnoreCase("xml")) { validateGeneratedFiles("ws-", fileName, toString(entry.getValue().getAsset().openStream())); } } assertEquals(3, fileNames.size()); assertTrue(fileNames.containsAll(LIBS)); assertTrue(fileNames.contains("jarWithSourceFiles.jar")); }
From source file:org.drools.guvnor.server.generators.ServiceWarGeneratorTest.java
@Test public void testRest() throws IOException, URISyntaxException { setupLocalCache();// w w w .j ava2s .c om final File temp = File.createTempFile("drools-service", ".jar"); // Delete temp file when program exits. temp.deleteOnExit(); final OutputStream out = new FileOutputStream(temp); final Map<String, File> models = new HashMap<String, File>() { { put("jarWithSourceFiles.jar", new File(ServiceWarGeneratorTest.class.getClassLoader().getResource(MODEL_NAME).toURI())); } }; buildWar(new ServiceConfig(REST_SERVICE_CONFIG), models, out); final WebArchive archive = ShrinkWrap.createFromZipFile(WebArchive.class, temp); final Collection<String> fileNames = new LinkedList<String>(); for (final Map.Entry<ArchivePath, Node> entry : archive.getContent().entrySet()) { final String extension = getExtension(entry.getKey().get()); final String fileName = getName(entry.getKey().get()); if (extension.equalsIgnoreCase("jar")) { fileNames.add(fileName); } else if (extension.equalsIgnoreCase("xml")) { validateGeneratedFiles("rest-", fileName, toString(entry.getValue().getAsset().openStream())); } } assertEquals(3, fileNames.size()); assertTrue(fileNames.containsAll(LIBS)); assertTrue(fileNames.contains("jarWithSourceFiles.jar")); }
From source file:org.intermine.pathquery.LogicExpression.java
/** * Take a Collection of String variable names, and return the part of the Logic Expression that * contains those variables./*from ww w .j a v a 2s . c om*/ * * @param variables a Collection of variable names * @return a section of the LogicExpression * @throws IllegalArgumentException if there are unrecognised variables, or if the expression * cannot be split up in that way */ public LogicExpression getSection(Collection<String> variables) { if (variables.isEmpty()) { return null; } if (!getVariableNames().containsAll(variables)) { throw new IllegalArgumentException("Unrecognised variables in request"); } if (root instanceof Variable) { return this; } else if (root instanceof Or) { if (variables.containsAll(getVariableNames())) { return this; } else { throw new IllegalArgumentException("Expression " + toString() + " cannot be split"); } } else { And and = (And) root; StringBuffer retval = new StringBuffer(); boolean needComma = false; for (Node node : and.getChildren()) { Set<String> hasVariables = new HashSet<String>(); getVariableNames(hasVariables, node); boolean containsAll = true; boolean containsNone = true; for (String var : hasVariables) { if (variables.contains(var)) { containsNone = false; } else { containsAll = false; } } if ((!containsNone) && (!containsAll)) { throw new IllegalArgumentException("Expression " + node + " cannot be split"); } if (containsAll) { if (needComma) { retval.append(" and "); } needComma = true; retval.append("(" + node.toString() + ")"); } } return new LogicExpression(retval.toString()); } }
From source file:nu.localhost.tapestry5.springsecurity.components.IfRole.java
/** * @return false as the default. Returns true if all non-null role expressions are * satisfied. Typically, only one will be used, but if more than one are used, then * the conditions are effectively AND'd *///from www . j a va 2s .c o m private boolean checkPermission() { boolean returnValue = true; if (((null == ifAllGranted) || "".equals(ifAllGranted)) && ((null == ifAnyGranted) || "".equals(ifAnyGranted)) && ((null == role) || "".equals(role)) && ((null == ifNotGranted) || "".equals(ifNotGranted))) { return false; } final Collection<GrantedAuthority> granted = getPrincipalAuthorities(); if ((null != role) && !"".equals(role)) { final Collection<GrantedAuthority> grantedCopy = retainAll(granted, parseAuthoritiesString(role)); if (grantedCopy.isEmpty()) { returnValue = false; } } if ((null != ifNotGranted) && !"".equals(ifNotGranted)) { final Collection<GrantedAuthority> grantedCopy = retainAll(granted, parseAuthoritiesString(ifNotGranted)); if (!grantedCopy.isEmpty()) { returnValue = false; } } if ((null != ifAllGranted) && !"".equals(ifAllGranted)) { if (!granted.containsAll(parseAuthoritiesString(ifAllGranted))) { returnValue = false; } } if ((null != ifAnyGranted) && !"".equals(ifAnyGranted)) { final Collection<GrantedAuthority> grantedCopy = retainAll(granted, parseAuthoritiesString(ifAnyGranted)); if (grantedCopy.isEmpty()) { returnValue = false; } } return returnValue; }
From source file:org.gridgain.grid.util.ipc.shmem.GridIpcSharedMemoryCrashDetectionSelfTest.java
/** * @throws Exception If failed.//from w ww. j a v a2 s. co m */ public void testGgfsClientServerInteractionsUponServerKilling() throws Exception { Collection<Integer> shmemIdsBeforeInteractions = GridIpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs before starting server-client interactions: " + shmemIdsBeforeInteractions); Collection<Integer> shmemIdsWithinInteractions = interactWithServer(); Collection<Integer> shmemIdsAfterInteractions = GridIpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs created within interaction: " + shmemIdsWithinInteractions); info("Shared memory IDs after server and client killing: " + shmemIdsAfterInteractions); if (!U.isLinux()) assertTrue( "List of shared memory IDs after server-client interactions should include IDs created within " + "client-server interactions.", shmemIdsAfterInteractions.containsAll(shmemIdsWithinInteractions)); else assertFalse( "List of shared memory IDs after server-client interactions should not include IDs created " + "(on Linux): within client-server interactions.", CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions)); ProcessStartResult srvStartRes = startSharedMemoryTestServer(); try { // Give server endpoint some time to make resource clean up. See GridIpcSharedMemoryServerEndpoint.GC_FREQ. for (int i = 0; i < 12; i++) { shmemIdsAfterInteractions = GridIpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs after server restart: " + shmemIdsAfterInteractions); if (CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions)) U.sleep(1000); else break; } assertFalse( "List of shared memory IDs after server endpoint restart should not include IDs created: " + "within client-server interactions.", CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions)); } finally { srvStartRes.proc().kill(); srvStartRes.isKilledLatch().await(); } }
From source file:org.topazproject.otm.ClassMetadata.java
/** * Gets a field mapper by its predicate uri. * * @param sf the session factory for looking up associations * @param uri the predicate uri//from w ww . j av a 2 s . c o m * @param inverse if the mapping is reverse (ie. o,p,s instead of s,p,o)) * @param typeUris Collection of rdf:Type values * * @return the mapper or null */ public RdfMapper getMapperByUri(SessionFactory sf, String uri, boolean inverse, Collection<String> typeUris) { List<RdfMapper> rdfMappers = uriMap.get(uri); if (rdfMappers == null) return null; Collection<String> uris = typeUris; RdfMapper candidate = null; for (RdfMapper m : rdfMappers) { if (m.hasInverseUri() != inverse) continue; if (candidate == null) candidate = m; if ((uris == null) || uris.isEmpty()) break; ClassMetadata assoc = !m.isAssociation() ? null : sf.getClassMetadata(m.getAssociatedEntity()); if ((assoc == null) || assoc.getTypes().isEmpty()) continue; if (uris.containsAll(assoc.getTypes())) { if (uris == typeUris) uris = new HashSet<String>(typeUris); // lazy copy uris.removeAll(assoc.getAllTypes()); candidate = m; } } return candidate; }
From source file:org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryCrashDetectionSelfTest.java
/** * @throws Exception If failed.//from w w w. j av a 2 s.c o m */ public void testIgfsClientServerInteractionsUponServerKilling() throws Exception { fail("https://issues.apache.org/jira/browse/IGNITE-1386"); Collection<Integer> shmemIdsBeforeInteractions = IpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs before starting server-client interactions: " + shmemIdsBeforeInteractions); Collection<Integer> shmemIdsWithinInteractions = interactWithServer(); Collection<Integer> shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs created within interaction: " + shmemIdsWithinInteractions); info("Shared memory IDs after server and client killing: " + shmemIdsAfterInteractions); if (!U.isLinux()) assertTrue( "List of shared memory IDs after server-client interactions should include IDs created within " + "client-server interactions.", shmemIdsAfterInteractions.containsAll(shmemIdsWithinInteractions)); else assertFalse( "List of shared memory IDs after server-client interactions should not include IDs created " + "(on Linux): within client-server interactions.", CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions)); ProcessStartResult srvStartRes = startSharedMemoryTestServer(); try { // Give server endpoint some time to make resource clean up. See IpcSharedMemoryServerEndpoint.GC_FREQ. for (int i = 0; i < 12; i++) { shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds(); info("Shared memory IDs after server restart: " + shmemIdsAfterInteractions); if (CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions)) U.sleep(1000); else break; } assertFalse( "List of shared memory IDs after server endpoint restart should not include IDs created: " + "within client-server interactions.", CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions)); } finally { srvStartRes.proc().kill(); srvStartRes.isKilledLatch().await(); } }
From source file:edu.ksu.cis.indus.staticanalyses.callgraphs.CallInfo.java
/** * Validates the information. This is designed to be used inside an assertion. * //from w ww . ja v a2 s . c om * @return <code>true</code> if the info is valid. An assertion violation is raised otherwise. */ private boolean validate() { final Collection<SootMethod> _k1 = caller2callees.keySet(); for (final Iterator<Collection<CallTriple>> _i = callee2callers.values().iterator(); _i.hasNext();) { final Collection<CallTriple> _c = _i.next(); for (final Iterator<CallTriple> _j = _c.iterator(); _j.hasNext();) { final CallTriple _ctrp = _j.next(); assert _k1.contains(_ctrp.getMethod()); } } final Collection<SootMethod> _k2 = callee2callers.keySet(); for (final Iterator<Collection<CallTriple>> _i = caller2callees.values().iterator(); _i.hasNext();) { final Collection<CallTriple> _c = _i.next(); for (final Iterator<CallTriple> _j = _c.iterator(); _j.hasNext();) { final CallTriple _ctrp = _j.next(); assert _k2.contains(_ctrp.getMethod()); } } assert _k1.containsAll(reachables) : SetUtils.difference(reachables, _k1); assert _k2.containsAll(reachables) : SetUtils.difference(reachables, _k2); assert reachables.containsAll(_k1) : SetUtils.difference(_k1, reachables); assert reachables.containsAll(_k2) : SetUtils.difference(_k2, reachables); return true; }
From source file:ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.java
private void deleteOldAnalyses(ExpressionExperiment expressionExperiment, DifferentialExpressionAnalysis newAnalysis, Collection<ExperimentalFactor> factors) { Collection<DifferentialExpressionAnalysis> diffAnalyses = differentialExpressionAnalysisService .findByInvestigation(expressionExperiment); int numDeleted = 0; if (diffAnalyses == null || diffAnalyses.isEmpty()) { DifferentialExpressionAnalyzerServiceImpl.log.info( "No differential expression analyses to remove for " + expressionExperiment.getShortName()); return;//from w w w . j av a 2 s . c om } this.differentialExpressionAnalysisService.thaw(diffAnalyses); for (DifferentialExpressionAnalysis existingAnalysis : diffAnalyses) { Collection<ExperimentalFactor> factorsInAnalysis = new HashSet<>(); for (ExpressionAnalysisResultSet resultSet : existingAnalysis.getResultSets()) { factorsInAnalysis.addAll(resultSet.getExperimentalFactors()); } FactorValue subsetFactorValueForExisting = existingAnalysis.getSubsetFactorValue(); /* * Match if: factors are the same, and if this is a subset, it's the same subset factorvalue. */ if (factorsInAnalysis.size() == factors.size() && factorsInAnalysis.containsAll(factors) && (subsetFactorValueForExisting == null || subsetFactorValueForExisting.equals(newAnalysis.getSubsetFactorValue()))) { DifferentialExpressionAnalyzerServiceImpl.log .info("Deleting analysis with ID=" + existingAnalysis.getId()); this.deleteAnalysis(expressionExperiment, existingAnalysis); numDeleted++; } } if (numDeleted == 0) { DifferentialExpressionAnalyzerServiceImpl.log .info("None of the other existing analyses were eligible for deletion"); } }