@Test public void testIsEqualEntityRefsToEntities() { Entity e1 = mock(Entity.class); when(e1.getReference()).thenReturn("/ref/e1"); Entity e2 = mock(Entity.class); when(e2.getReference()).thenReturn("/ref/e2"); assertFalse(isEqualEntityRefsToEntities( Arrays.asList(new String[] { "/ref/e2" }), Arrays.asList(new Entity[] { e1, e2 }))); assertFalse(isEqualEntityRefsToEntities( Arrays.asList(new String[] { "/ref/e2" }), Arrays.asList(new Entity[] {}))); assertFalse(isEqualEntityRefsToEntities(Arrays.asList(new String[] {}), Arrays.asList(new Entity[] { e1, e2 }))); assertFalse(isEqualEntityRefsToEntities( Arrays.asList(new String[] { "/ref/a1", "/ref/a2" }), Arrays.asList(new Entity[] { e1, e2 }))); assertFalse(isEqualEntityRefsToEntities( Arrays.asList(new String[] { "/ref/e1", "/ref/e2", "/ref/e3" }), Arrays.asList(new Entity[] { e1, e2 }))); assertTrue(isEqualEntityRefsToEntities( Arrays.asList(new String[] { "/ref/e1", "/ref/e2" }), Arrays.asList(new Entity[] { e1, e2 }))); assertTrue(isEqualEntityRefsToEntities( Arrays.asList(new String[] { "/ref/e2", "/ref/e1" }), Arrays.asList(new Entity[] { e1, e2 }))); assertFalse(isEqualEntityRefsToEntities( Arrays.asList(new String[] { "/ref/e1", "/ref/e1" }), Arrays.asList(new Entity[] { e1, e2 }))); assertFalse(isEqualEntityRefsToEntities( Arrays.asList(new String[] { "/ref/e1", "/ref/e2" }), Arrays.asList(new Entity[] { e1, e1 }))); }
public static boolean isEqualEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities) { if (entityRefs.size() != entities.size()) return false; for (Iterator<String> iRefs = entityRefs.iterator(); iRefs.hasNext();) { String entityRef = iRefs.next(); if (!entityCollectionContainsRefString(entities, entityRef)) { return false; } } for (Iterator<Entity> iEntities = entities.iterator(); iEntities.hasNext();) { String findThisEntityRef = iEntities.next().getReference(); if(!entityRefs.contains(findThisEntityRef)) { return false; } } return true; }
EntityCollections { public static boolean isEqualEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities) { if (entityRefs.size() != entities.size()) return false; for (Iterator<String> iRefs = entityRefs.iterator(); iRefs.hasNext();) { String entityRef = iRefs.next(); if (!entityCollectionContainsRefString(entities, entityRef)) { return false; } } for (Iterator<Entity> iEntities = entities.iterator(); iEntities.hasNext();) { String findThisEntityRef = iEntities.next().getReference(); if(!entityRefs.contains(findThisEntityRef)) { return false; } } return true; } }
EntityCollections { public static boolean isEqualEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities) { if (entityRefs.size() != entities.size()) return false; for (Iterator<String> iRefs = entityRefs.iterator(); iRefs.hasNext();) { String entityRef = iRefs.next(); if (!entityCollectionContainsRefString(entities, entityRef)) { return false; } } for (Iterator<Entity> iEntities = entities.iterator(); iEntities.hasNext();) { String findThisEntityRef = iEntities.next().getReference(); if(!entityRefs.contains(findThisEntityRef)) { return false; } } return true; }  }
EntityCollections { public static boolean isEqualEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities) { if (entityRefs.size() != entities.size()) return false; for (Iterator<String> iRefs = entityRefs.iterator(); iRefs.hasNext();) { String entityRef = iRefs.next(); if (!entityCollectionContainsRefString(entities, entityRef)) { return false; } } for (Iterator<Entity> iEntities = entities.iterator(); iEntities.hasNext();) { String findThisEntityRef = iEntities.next().getReference(); if(!entityRefs.contains(findThisEntityRef)) { return false; } } return true; }  static boolean isIntersectionEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities); static boolean isContainedEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities); static boolean isEqualEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities); static boolean entityCollectionContainsRefString(Collection<Entity> entities, String entityRef); static boolean refCollectionContainsEntity(Collection<String> refs, Entity entity); static void setEntityRefsFromEntities(Collection<String> refs, Collection<Entity> entities); static void computeAddedRemovedEntityRefsFromNewEntitiesOldRefs(Collection<String> addedEntities, Collection<String> removedEntities,
			Collection<Entity> newEntities, Collection<String> oldEntityRefs); }
EntityCollections { public static boolean isEqualEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities) { if (entityRefs.size() != entities.size()) return false; for (Iterator<String> iRefs = entityRefs.iterator(); iRefs.hasNext();) { String entityRef = iRefs.next(); if (!entityCollectionContainsRefString(entities, entityRef)) { return false; } } for (Iterator<Entity> iEntities = entities.iterator(); iEntities.hasNext();) { String findThisEntityRef = iEntities.next().getReference(); if(!entityRefs.contains(findThisEntityRef)) { return false; } } return true; }  static boolean isIntersectionEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities); static boolean isContainedEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities); static boolean isEqualEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities); static boolean entityCollectionContainsRefString(Collection<Entity> entities, String entityRef); static boolean refCollectionContainsEntity(Collection<String> refs, Entity entity); static void setEntityRefsFromEntities(Collection<String> refs, Collection<Entity> entities); static void computeAddedRemovedEntityRefsFromNewEntitiesOldRefs(Collection<String> addedEntities, Collection<String> removedEntities,
			Collection<Entity> newEntities, Collection<String> oldEntityRefs);  }