List of usage examples for org.apache.commons.collections CollectionUtils isEqualCollection
public static boolean isEqualCollection(final Collection a, final Collection b)
From source file:com.redhat.rhn.domain.server.test.ServerFactoryTest.java
public void testFindVirtPlatformHostsByOrg() throws Exception { HostBuilder builder = new HostBuilder(user); List expectedViews = new ArrayList(); expectedViews.add(builder.createVirtPlatformHost().withGuests(1).build().asHostAndGuestCountView()); expectedViews.add(builder.createVirtPlatformHost().withGuests(3).build().asHostAndGuestCountView()); expectedViews.add(builder.createVirtPlatformHost().withGuests(8).build().asHostAndGuestCountView()); builder.createVirtPlatformHost().withUnregisteredGuests(2); builder.createVirtHost().withGuests(2).build(); builder.createVirtHost().withGuests(6).build(); builder.createNonVirtHost().withGuests(3).build(); builder.createNonVirtHost().withGuests(5).build(); List actualViews = ServerFactory.findVirtPlatformHostsByOrg(user.getOrg()); assertTrue(CollectionUtils.isEqualCollection(expectedViews, actualViews)); }
From source file:com.tesora.dve.sql.schema.PEForeignKey.java
private static void processFKChecksOnUpdate(SchemaContext sc, PETable modifiedTable, List<PEColumn> modifiedColumns, PETable referencingTable, Set<PETable> processed) { if (referencingTable == null) { for (SchemaCacheKey<PEAbstractTable<?>> referring : modifiedTable.getReferencingTables()) { PETable actual = sc.getSource().find(sc, referring).asTable(); processFKChecksOnUpdate(sc, modifiedTable, modifiedColumns, actual, processed); }//from www .ja v a2 s . co m } else { if (!processed.add(referencingTable)) return; RangeDistribution mr = modifiedTable.getDistributionVector(sc).getDistributedWhollyOnTenantColumn(sc); RangeDistribution rr = referencingTable.getDistributionVector(sc) .getDistributedWhollyOnTenantColumn(sc); boolean bothTenantID = (mr != null && rr != null && mr.getCacheKey().equals(rr.getCacheKey())); for (PEKey pek : referencingTable.getKeys(sc)) { if (!pek.isForeign()) continue; PEForeignKey pefk = (PEForeignKey) pek; if (!pefk.isPersisted()) continue; PETable targTab = pefk.getTargetTable(sc); if (targTab == null) continue; if (targTab != modifiedTable) continue; List<PEColumn> targCols = pefk.getTargetColumns(sc); if (!CollectionUtils.isEqualCollection(modifiedColumns, targCols)) continue; ForeignKeyAction updateAction = pefk.getUpdateAction(); boolean mustRecurse = false; if (updateAction == ForeignKeyAction.RESTRICT || updateAction == ForeignKeyAction.NO_ACTION) { mustRecurse = false; } else if (updateAction == ForeignKeyAction.SET_NULL || updateAction == ForeignKeyAction.CASCADE) { if (referencingTable.getDistributionVector(sc).isBroadcast() || bothTenantID) { // must propagate the update mustRecurse = true; } else { throw new SchemaException(Pass.PLANNER, "Unable to update table " + modifiedTable.getName() + " due to cascade/set null action on foreign key " + pefk.getName() + " in table " + referencingTable.getName()); } } if (mustRecurse) processFKChecksOnUpdate(sc, referencingTable, pefk.getColumns(sc), null, processed); } } }
From source file:io.mindmaps.graql.internal.analytics.AnalyticsTest.java
@Ignore @Test//from w ww. java2 s . c o m public void testDegreeIsPersisted() throws Exception { // create a simple graph RoleType pet = graph.putRoleType("pet"); RoleType owner = graph.putRoleType("owner"); RoleType breeder = graph.putRoleType("breeder"); RelationType mansBestFriend = graph.putRelationType("mans-best-friend").hasRole(pet).hasRole(owner) .hasRole(breeder); EntityType person = graph.putEntityType("person").playsRole(owner).playsRole(breeder); EntityType animal = graph.putEntityType("animal").playsRole(pet); // make one person breeder and owner Entity coco = graph.putEntity("coco", animal); Entity dave = graph.putEntity("dave", person); Relation daveBreedsAndOwnsCoco = graph.addRelation(mansBestFriend).putRolePlayer(pet, coco) .putRolePlayer(owner, dave); // manual degrees Map<String, Long> referenceDegrees = new HashMap<>(); referenceDegrees.put(coco.getId(), 1L); referenceDegrees.put(dave.getId(), 1L); referenceDegrees.put(daveBreedsAndOwnsCoco.getId(), 2L); // validate graph.commit(); // compute and persist degrees Analytics analytics = new Analytics(keyspace); analytics.degreesAndPersist(); // check degrees are correct graph = MindmapsClient.getGraph(keyspace); referenceDegrees.entrySet().forEach(entry -> { Instance instance = graph.getInstance(entry.getKey()); if (instance.isEntity()) { assertTrue(instance.asEntity().resources().iterator().next().getValue().equals(entry.getValue())); } else if (instance.isRelation()) { assertTrue(instance.asRelation().resources().iterator().next().getValue().equals(entry.getValue())); } }); // check only expected resources exist Collection<String> allConcepts = new ArrayList<>(); ResourceType<Long> rt = graph.getResourceType(Analytics.degree); Collection<Resource<Long>> degrees = rt.instances(); Map<Instance, Long> currentDegrees = new HashMap<>(); degrees.forEach(degree -> { Long degreeValue = degree.getValue(); degree.ownerInstances().forEach(instance -> { currentDegrees.put(instance, degreeValue); }); }); // check all resources exist and no more assertTrue(CollectionUtils.isEqualCollection(currentDegrees.values(), referenceDegrees.values())); // persist again and check again analytics.degreesAndPersist(); // check only expected resources exist graph = MindmapsClient.getGraph(keyspace); rt = graph.getResourceType(Analytics.degree); degrees = rt.instances(); degrees.forEach(i -> i.ownerInstances().iterator().forEachRemaining(r -> allConcepts.add(r.getId()))); // check degrees are correct referenceDegrees.entrySet().forEach(entry -> { Instance instance = graph.getInstance(entry.getKey()); if (instance.isEntity()) { assertTrue(instance.asEntity().resources().iterator().next().getValue().equals(entry.getValue())); } else if (instance.isRelation()) { assertTrue(instance.asRelation().resources().iterator().next().getValue().equals(entry.getValue())); } }); degrees = rt.instances(); currentDegrees.clear(); degrees.forEach(degree -> { Long degreeValue = degree.getValue(); degree.ownerInstances().forEach(instance -> { currentDegrees.put(instance, degreeValue); }); }); // check all resources exist and no more assertTrue(CollectionUtils.isEqualCollection(currentDegrees.values(), referenceDegrees.values())); }
From source file:com.fiveamsolutions.nci.commons.audit.AuditLogInterceptor.java
private boolean collectionNeedsAuditing(Object auditableObj, Object newValue, Object oldValue, String property) {// www.ja v a 2 s . c o m // PO-6030: this method has undesirable side-effect that may impact // performance: it initializes lazy // collections on the auditableObj entity even if the collections don't // need to be audited. // Initialization happens during the CollectionUtils.isEqualCollection // check below. We should skip the check at least // when oldValue and newValue point to the same uninitialized collection // instance, because in such case it is obvious that the collection hasn't been touched. try { if (!sameNonInitializedCollection(newValue, oldValue)) { String cn = ProxyUtils.unEnhanceCGLIBClassName(auditableObj.getClass()); Method getter = getHibernateHelper().getConfiguration().getClassMapping(cn).getProperty(property) .getGetter(auditableObj.getClass()).getMethod(); if (getter.getAnnotation(MapKey.class) != null || getter.getAnnotation(MapKeyManyToMany.class) != null) { // this is some sort of map Map<?, ?> oldMap = (Map<?, ?>) oldValue; Map<?, ?> newMap = (Map<?, ?>) newValue; oldMap = oldMap == null ? Collections.emptyMap() : oldMap; newMap = newMap == null ? Collections.emptyMap() : newMap; return !equalsMap(oldMap, newMap); } else if (getter.getAnnotation(JoinTable.class) != null || getter.getAnnotation(OneToMany.class) != null) { Collection<?> oldSet = (Collection<?>) oldValue; Collection<?> newSet = (Collection<?>) newValue; return !CollectionUtils.isEqualCollection(oldSet == null ? Collections.emptySet() : oldSet, newSet == null ? Collections.emptySet() : newSet); } } } catch (SecurityException e) { LOG.error(e.getMessage(), e); } return false; }
From source file:ai.grakn.test.graql.reasoner.AtomicTest.java
@Test public void testTypeInference_singleGuard() { GraknGraph graph = typeInferenceSet.graph(); String patternString = "{$x isa entity1; ($x, $y);}"; String patternString2 = "{$x isa subEntity1; ($x, $y);}"; ReasonerAtomicQuery query = ReasonerQueries.atomic(conjunction(patternString, graph), graph); ReasonerAtomicQuery query2 = ReasonerQueries.atomic(conjunction(patternString2, graph), graph); Relation atom = (Relation) query.getAtom(); Relation atom2 = (Relation) query2.getAtom(); List<RelationType> possibleTypes = Lists.newArrayList(graph.getType(TypeLabel.of("relation1")), graph.getType(TypeLabel.of("relation3"))); List<RelationType> relationTypes = atom.inferPossibleRelationTypes(new QueryAnswer()); List<RelationType> relationTypes2 = atom2.inferPossibleRelationTypes(new QueryAnswer()); assertTrue(CollectionUtils.isEqualCollection(relationTypes, possibleTypes)); assertTrue(CollectionUtils.isEqualCollection(relationTypes2, possibleTypes)); assertEquals(atom.getType(), null);/*from w w w . ja v a 2 s.c o m*/ assertEquals(atom2.getType(), null); }
From source file:ai.grakn.test.graql.reasoner.AtomicTest.java
@Test public void testTypeInference_singleRole() { GraknGraph graph = typeInferenceSet.graph(); String patternString = "{(role2: $x, $y);}"; ReasonerAtomicQuery query = ReasonerQueries.atomic(conjunction(patternString, graph), graph); Relation atom = (Relation) query.getAtom(); List<RelationType> possibleTypes = Lists.newArrayList(graph.getType(TypeLabel.of("relation1")), graph.getType(TypeLabel.of("relation2")), graph.getType(TypeLabel.of("relation3"))); List<RelationType> relationTypes = atom.inferPossibleRelationTypes(new QueryAnswer()); assertTrue(CollectionUtils.isEqualCollection(relationTypes, possibleTypes)); assertEquals(atom.getType(), null);//from w ww. ja v a 2s. c o m }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
private boolean isEqualString(String xpathElem, String xpathObj, ArrayList<String> catalogs) { ArrayList<String> elems = new ArrayList<String>(Arrays.asList(xpathElem.split("/")));//$NON-NLS-1$ ArrayList<String> objs = new ArrayList<String>(Arrays.asList(xpathObj.split("/")));//$NON-NLS-1$ int orgSize = objs.size(); for (int i = 0; i < objs.size(); i++) { if (!objs.get(i).equals(elems.get(i))) { objs.addAll(i, catalogs);/*from w w w . j a v a 2 s . c o m*/ break; } } if (orgSize == objs.size() && orgSize != elems.size()) { objs.addAll(objs.size(), catalogs); } return CollectionUtils.isEqualCollection(elems, objs); }
From source file:ai.grakn.test.graql.reasoner.AtomicTest.java
@Test public void testTypeInference_singleRole_singleGuard() { GraknGraph graph = typeInferenceSet.graph(); String patternString = "{(role2: $x, $y); $y isa entity1;}"; String patternString2 = "{(role2: $x, $y); $y isa subEntity1;}"; ReasonerAtomicQuery query = ReasonerQueries.atomic(conjunction(patternString, graph), graph); ReasonerAtomicQuery query2 = ReasonerQueries.atomic(conjunction(patternString2, graph), graph); Relation atom = (Relation) query.getAtom(); Relation atom2 = (Relation) query2.getAtom(); List<RelationType> possibleTypes = Lists.newArrayList(graph.getType(TypeLabel.of("relation1")), graph.getType(TypeLabel.of("relation3"))); List<RelationType> relationTypes = atom.inferPossibleRelationTypes(new QueryAnswer()); List<RelationType> relationTypes2 = atom2.inferPossibleRelationTypes(new QueryAnswer()); assertTrue(CollectionUtils.isEqualCollection(relationTypes, possibleTypes)); assertTrue(CollectionUtils.isEqualCollection(relationTypes2, possibleTypes)); assertEquals(atom.getType(), null);//from w ww. j av a 2 s .c o m assertEquals(atom2.getType(), null); }
From source file:com.vmware.photon.controller.common.dcp.DcpRestClientTest.java
private void checkDocumentsRetrievedInAll(int numDocuments, ImmutableMap<String, String> queryTerms, boolean expandContent, Collection<ExampleService.ExampleServiceState> expectedDocuments) throws Throwable { ServiceDocumentQueryResult queryResult = dcpRestClient.queryDocuments( ExampleService.ExampleServiceState.class, queryTerms, Optional.absent(), expandContent); Set<String> expectedDocumentNames = expectedDocuments.stream().map(d -> d.name).collect(Collectors.toSet()); Set<String> actualDocumentNames = queryResult.documents.values().stream() .map(d -> Utils.fromJson(d, ExampleService.ExampleServiceState.class).name) .collect(Collectors.toSet()); assertThat(queryResult.documentLinks.size(), is(numDocuments)); assertThat(queryResult.documents.size(), is(numDocuments)); assertThat(CollectionUtils.isEqualCollection(expectedDocumentNames, actualDocumentNames), is(true)); assertNull(queryResult.nextPageLink); assertNull(queryResult.prevPageLink); }
From source file:com.vmware.photon.controller.common.dcp.DcpRestClientTest.java
private void checkDocumentsRetrievedPageByPage(int numDocuments, int pageSize, ImmutableMap<String, String> queryTerms, boolean expandContent, Collection<ExampleService.ExampleServiceState> expectedDocuments) throws Throwable { ServiceDocumentQueryResult queryResult = dcpRestClient.queryDocuments( ExampleService.ExampleServiceState.class, queryTerms, Optional.of(pageSize), expandContent); assertNotNull(queryResult.documents); assertNotNull(queryResult.nextPageLink); assertNull(queryResult.prevPageLink); Set<String> actualDocumentNames = new HashSet<>(); actualDocumentNames.addAll(queryResult.documents.values().stream() .map(d -> Utils.fromJson(d, ExampleService.ExampleServiceState.class).name) .collect(Collectors.toSet())); Set<String> expectedDocumentNames = expectedDocuments.stream().map(d -> d.name).collect(Collectors.toSet()); while (queryResult.nextPageLink != null) { queryResult = dcpRestClient.queryDocumentPage(queryResult.nextPageLink); actualDocumentNames.addAll(queryResult.documents.values().stream() .map(d -> Utils.fromJson(d, ExampleService.ExampleServiceState.class).name) .collect(Collectors.toSet())); }/*from w w w .j a va 2 s . c o m*/ assertThat(actualDocumentNames.size(), is(numDocuments)); assertThat(CollectionUtils.isEqualCollection(expectedDocumentNames, actualDocumentNames), is(true)); }