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.wizecommerce.hecuba.hector.HectorColumnSliceResultSetTest.java
@Test public void testGetColumnNames() throws Exception { assertTrue(CollectionUtils.isEqualCollection(columnNameList, sliceResultSet.getColumnNames())); }
From source file:grakn.core.graql.reasoner.GeoInferenceIT.java
private static <T> void assertCollectionsNonTriviallyEqual(Collection<T> c1, Collection<T> c2) { assertTrue(CollectionUtils.isEqualCollection(c1, c2)); }
From source file:com.stratio.deep.cassandra.entity.CellValidator.java
/** * {@inheritDoc}/* w ww .ja v a2s . c om*/ */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } CellValidator that = (CellValidator) o; if (validatorKind != that.validatorKind) { return false; } if (!validatorClassName.equals(that.validatorClassName)) { return false; } if (validatorKind != Kind.NOT_A_COLLECTION && !CollectionUtils.isEqualCollection(validatorTypes, that.validatorTypes)) { return false; } return true; }
From source file:gov.nih.nci.caarray.dao.ProjectDaoTest.java
private void checkBioMaterials(Experiment dummyInv, Experiment retrievedInv) { CollectionUtils.isEqualCollection(dummyInv.getSources(), retrievedInv.getSources()); CollectionUtils.isEqualCollection(dummyInv.getSamples(), retrievedInv.getSamples()); CollectionUtils.isEqualCollection(dummyInv.getExtracts(), retrievedInv.getExtracts()); CollectionUtils.isEqualCollection(dummyInv.getLabeledExtracts(), retrievedInv.getLabeledExtracts()); }
From source file:ai.grakn.test.graql.analytics.DegreeTest.java
@Test public void testDegreeIsPersisted() throws Exception { // TODO: Fix on TinkerGraphComputer assumeFalse(usingTinker());//from ww w .ja v a 2 s . c o m // 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 = animal.addEntity(); Entity dave = person.addEntity(); Relation daveBreedsAndOwnsCoco = mansBestFriend.addRelation().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); graph.commit(); // compute and persist degrees graph.graql().compute().degree().persist().execute(); // check degrees are correct graph = factory.getGraph(); GraknGraph finalGraph = graph; referenceDegrees.entrySet().forEach(entry -> { Instance instance = finalGraph.getConcept(entry.getKey()); assertTrue(instance.resources().iterator().next().getValue().equals(entry.getValue())); }); // check only expected resources exist Collection<String> allConcepts = new ArrayList<>(); ResourceType<Long> rt = graph.getResourceType(AbstractComputeQuery.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 graph.graql().compute().degree().persist().execute(); // check only expected resources exist graph = factory.getGraph(); rt = graph.getResourceType(AbstractComputeQuery.degree); degrees = rt.instances(); degrees.forEach(i -> i.ownerInstances().iterator().forEachRemaining(r -> allConcepts.add(r.getId()))); // check degrees are correct GraknGraph finalGraph1 = graph; referenceDegrees.entrySet().forEach(entry -> { Instance instance = finalGraph1.getConcept(entry.getKey()); assertTrue(instance.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:gov.nih.nci.caarray.util.CaArrayAuditLogInterceptor.java
private boolean collectionNeedsAuditing(Object auditableObj, Object newValue, Object oldValue, String property) {//from w w w. ja v a 2 s.c o m try { String cn = CGLIBUtils.unEnhanceCBLIBClassName(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(JoinColumn.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:com.wingnest.play2.origami.plugin.OrigamiPlugin.java
@SuppressWarnings("unchecked") private void maintainProperties(final OClass oClass, final Class<?> javaClass) { final Map<String, Map<String, Object>> compositeIndexMap = new HashMap<String, Map<String, Object>>(); final Map<String, OIndex<?>> classIndexCache = new HashMap<String, OIndex<?>>(); final Map<String, OIndex<?>> compositeIndexCache = new HashMap<String, OIndex<?>>(); final Set<String> wkCurIndexNames = new HashSet<String>(); // for ( final OProperty prop : oClass.properties() ) { // debug("[b] prop name =%s, type = %s", prop.getName(), prop.getType()); // }//from w w w . j a v a 2s .c om for (final OIndex<?> index : oClass.getClassIndexes()) { wkCurIndexNames.add(index.getName()); if (index.getName().indexOf('.') > -1) { classIndexCache.put(index.getName(), index); } else { compositeIndexCache.put(index.getName(), index); } // debug("[b] index name =%s, type = %s", index.getName(), index.getType()); } for (final Field field : javaClass.getDeclaredFields()) { if (Modifier.isStatic(field.getModifiers()) || field.isAnnotationPresent(Id.class) || field.isAnnotationPresent(Version.class) || field.isAnnotationPresent(Transient.class) || field.isAnnotationPresent(DisupdateFlag.class)) continue; OProperty prop = oClass.getProperty(field.getName()); final OType type = guessType(field); if (prop == null) { if (type != null) { debug("create property : %s", field.getName()); prop = oClass.createProperty(field.getName(), type); } } else { if (!type.equals(prop.getType())) { deleteIndex(oClass, oClass.getName() + "." + field.getName(), classIndexCache, compositeIndexCache); debug("drop property : %s", field.getName()); oClass.dropProperty(field.getName()); debug("create property : %s", field.getName()); prop = oClass.createProperty(field.getName(), type); } } final Index index = field.getAnnotation(Index.class); if (index != null) { final String indexName = makeIndexName(javaClass, field); OIndex<?> oindex = classIndexCache.get(indexName); if (oindex == null) { debug("create Class Index : %s.%s", javaClass.getSimpleName(), field.getName()); if (prop != null) { oindex = oClass.createIndex(indexName, index.indexType(), field.getName()); } else { error("could not create Class Index : property(%s.%s) has't type", javaClass.getName(), field.getName()); } } if (oindex != null) { wkCurIndexNames.remove(oindex.getName()); } } final CompositeIndex cindex = field.getAnnotation(CompositeIndex.class); if (cindex != null) { final String indexName = javaClass.getSimpleName() + "_" + cindex.indexName(); Map<String, Object> ci = compositeIndexMap.get(indexName); if (ci == null) { ci = new HashMap<String, Object>(); ci.put("fields", new HashSet<Field>()); ci.put("indexType", OClass.INDEX_TYPE.UNIQUE); } if (!cindex.indexType().equals(OClass.INDEX_TYPE.UNIQUE)) ci.put("indexType", cindex.indexType()); ((Set<Field>) ci.get("fields")).add(field); compositeIndexMap.put(indexName, ci); } } for (final String cindexName : compositeIndexMap.keySet()) { final Map<String, Object> ci = compositeIndexMap.get(cindexName); final Set<Field> fields = (Set<Field>) ci.get("fields"); final String[] fieldNames = new String[fields.size()]; int i = 0; for (final Field f : fields) { fieldNames[i++] = f.getName(); } final OIndex<?> oindex = compositeIndexCache.get(cindexName); if (oindex != null && !CollectionUtils.isEqualCollection(Arrays.asList(fieldNames), oindex.getDefinition().getFields())) { debug("recreate composite index : %s", cindexName); deleteIndex(oClass, cindexName, classIndexCache, compositeIndexCache); } else if (oindex == null) { debug("create composite index : %s", cindexName); } oClass.createIndex(cindexName, (OClass.INDEX_TYPE) ci.get("indexType"), fieldNames); wkCurIndexNames.remove(cindexName); } for (final String indexName : wkCurIndexNames) { final int ind = indexName.indexOf('.'); if (ind > -1) { debug("delete index : %s", indexName); } else { debug("delete composite index : %s", indexName); } deleteIndex(oClass, indexName, classIndexCache, compositeIndexCache); } // for ( final OProperty prop : oClass.properties() ) { // debug("[a] prop name =%s, type = %s", prop.getName(), prop.getType()); // } // for ( final OIndex<?> index : oClass.getClassIndexes() ) { // debug("[a] class index name =%s, type = %s", index.getName(), index.getType()); // } }
From source file:integration.delete.HierarchyDeleteTest.java
/** * Verify that the persisted entities are exactly as expected from among a superset. * @param iQuery the query service to use * @param entityClass the name of the entity class to query * @param allIds the IDs of the entities that may exist * @param expectedIds the IDs of the entities that should exist, a subset of <code>allIds</code> * @throws ServerError if the query fails *///from w w w . j a v a 2 s. c o m private void checkIds(IQueryPrx iQuery, String entityClass, Collection<Long> allIds, Collection<Long> expectedIds) throws ServerError { final Set<Long> actualIds = new HashSet<Long>(expectedIds.size()); for (final List<RType> wrappedId : iQuery.projection( "SELECT id FROM " + entityClass + " WHERE id IN (:" + Parameters.IDS + ")", new ParametersI().addIds(allIds))) { actualIds.add(((RLong) wrappedId.get(0)).getValue()); } Assert.assertTrue(CollectionUtils.isEqualCollection(actualIds, expectedIds), "persisted entities not as expected: " + entityClass); }
From source file:com.redhat.rhn.domain.server.test.ServerFactoryTest.java
public void testFindVirtHostsExceedingGuestLimitByOrg() throws Exception { HostBuilder builder = new HostBuilder(user); List expectedViews = new ArrayList(); expectedViews.add(builder.createVirtHost().withGuests(10).build().asHostAndGuestCountView()); expectedViews.add(builder.createVirtHost().withGuests(6).build().asHostAndGuestCountView()); expectedViews.add(builder.createVirtHost().withGuests(1).build().asHostAndGuestCountView()); builder.createVirtHost().withUnregisteredGuests(2); builder.createVirtPlatformHost().withGuests(5).build(); builder.createVirtPlatformHost().withGuests(2).build(); builder.createNonVirtHost().withGuests(2).build(); builder.createNonVirtHost().withGuests(5).build(); List actualViews = ServerFactory.findVirtHostsExceedingGuestLimitByOrg(user.getOrg()); assertTrue(CollectionUtils.isEqualCollection(expectedViews, actualViews)); }
From source file:ai.grakn.test.graql.analytics.AnalyticsTest.java
@Test public void testDegreeIsPersisted() throws Exception { // TODO: Fix on TinkerGraphComputer assumeFalse(usingTinker());/* w ww. j ava2 s. c o m*/ // 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 = animal.addEntity(); Entity dave = person.addEntity(); Relation daveBreedsAndOwnsCoco = mansBestFriend.addRelation().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(graph.getKeyspace(), new HashSet<>(), new HashSet<>()); analytics.degreesAndPersist(); // check degrees are correct graph = factory.getGraph(); GraknGraph finalGraph = graph; referenceDegrees.entrySet().forEach(entry -> { Instance instance = finalGraph.getConcept(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 = factory.getGraph(); rt = graph.getResourceType(Analytics.degree); degrees = rt.instances(); degrees.forEach(i -> i.ownerInstances().iterator().forEachRemaining(r -> allConcepts.add(r.getId()))); // check degrees are correct GraknGraph finalGraph1 = graph; referenceDegrees.entrySet().forEach(entry -> { Instance instance = finalGraph1.getConcept(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())); }