@Test public void testSort() { List<GenericEntity> entities = new LinkedList<GenericEntity>(); List<LinkedHashMap<String, Object>> studentParentsAssocistion = new LinkedList<LinkedHashMap<String, Object>>(); LinkedHashMap<String, Object> obj = new LinkedHashMap<String, Object>(); obj.put(Constants.ATTR_RELATION, "Father"); studentParentsAssocistion.add(obj); GenericEntity entity = new GenericEntity(); entity.put(Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS, studentParentsAssocistion); entities.add(entity); obj = new LinkedHashMap<String, Object>(); obj.put(Constants.ATTR_RELATION, "Mother"); studentParentsAssocistion = new LinkedList<LinkedHashMap<String, Object>>(); studentParentsAssocistion.add(obj); entity = new GenericEntity(); entity.put(Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS, studentParentsAssocistion); entities.add(entity); ParentsSorter.sort(entities); List<LinkedHashMap<String, Object>> objTest = (List<LinkedHashMap<String, Object>>) entities.get(0).get( Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS); Assert.assertEquals("Mother", objTest.get(0).get(Constants.ATTR_RELATION)); }
public static List<GenericEntity> sort(List<GenericEntity> genericEntities) { for (GenericEntity genericEntity : genericEntities) { List<Map<String, Object>> studentParentAssociations = (List<Map<String, Object>>) genericEntity .get(Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS); if (studentParentAssociations != null && !studentParentAssociations.isEmpty()) { Map<String, Object> studentParentAssociation = studentParentAssociations.get(0); genericEntity.put(Constants.ATTR_RELATION, studentParentAssociation.get(Constants.ATTR_RELATION)); genericEntity.put(Constants.ATTR_CONTACT_PRIORITY, studentParentAssociation.get(Constants.ATTR_CONTACT_PRIORITY)); genericEntity.put(Constants.ATTR_PRIMARY_CONTACT_STATUS, studentParentAssociation.get(Constants.ATTR_PRIMARY_CONTACT_STATUS)); } } GenericEntityComparator comparator = new GenericEntityComparator(Constants.ATTR_RELATION, String.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_RELATION, relationPriority); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_CONTACT_PRIORITY, Double.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_PRIMARY_CONTACT_STATUS, primaryContactStatusPriority); Collections.sort(genericEntities, comparator); for (GenericEntity genericEntity : genericEntities) { genericEntity.remove(Constants.ATTR_RELATION); genericEntity.remove(Constants.ATTR_CONTACT_PRIORITY); genericEntity.remove(Constants.ATTR_PRIMARY_CONTACT_STATUS); } return genericEntities; }
ParentsSorter { public static List<GenericEntity> sort(List<GenericEntity> genericEntities) { for (GenericEntity genericEntity : genericEntities) { List<Map<String, Object>> studentParentAssociations = (List<Map<String, Object>>) genericEntity .get(Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS); if (studentParentAssociations != null && !studentParentAssociations.isEmpty()) { Map<String, Object> studentParentAssociation = studentParentAssociations.get(0); genericEntity.put(Constants.ATTR_RELATION, studentParentAssociation.get(Constants.ATTR_RELATION)); genericEntity.put(Constants.ATTR_CONTACT_PRIORITY, studentParentAssociation.get(Constants.ATTR_CONTACT_PRIORITY)); genericEntity.put(Constants.ATTR_PRIMARY_CONTACT_STATUS, studentParentAssociation.get(Constants.ATTR_PRIMARY_CONTACT_STATUS)); } } GenericEntityComparator comparator = new GenericEntityComparator(Constants.ATTR_RELATION, String.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_RELATION, relationPriority); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_CONTACT_PRIORITY, Double.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_PRIMARY_CONTACT_STATUS, primaryContactStatusPriority); Collections.sort(genericEntities, comparator); for (GenericEntity genericEntity : genericEntities) { genericEntity.remove(Constants.ATTR_RELATION); genericEntity.remove(Constants.ATTR_CONTACT_PRIORITY); genericEntity.remove(Constants.ATTR_PRIMARY_CONTACT_STATUS); } return genericEntities; } }
ParentsSorter { public static List<GenericEntity> sort(List<GenericEntity> genericEntities) { for (GenericEntity genericEntity : genericEntities) { List<Map<String, Object>> studentParentAssociations = (List<Map<String, Object>>) genericEntity .get(Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS); if (studentParentAssociations != null && !studentParentAssociations.isEmpty()) { Map<String, Object> studentParentAssociation = studentParentAssociations.get(0); genericEntity.put(Constants.ATTR_RELATION, studentParentAssociation.get(Constants.ATTR_RELATION)); genericEntity.put(Constants.ATTR_CONTACT_PRIORITY, studentParentAssociation.get(Constants.ATTR_CONTACT_PRIORITY)); genericEntity.put(Constants.ATTR_PRIMARY_CONTACT_STATUS, studentParentAssociation.get(Constants.ATTR_PRIMARY_CONTACT_STATUS)); } } GenericEntityComparator comparator = new GenericEntityComparator(Constants.ATTR_RELATION, String.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_RELATION, relationPriority); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_CONTACT_PRIORITY, Double.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_PRIMARY_CONTACT_STATUS, primaryContactStatusPriority); Collections.sort(genericEntities, comparator); for (GenericEntity genericEntity : genericEntities) { genericEntity.remove(Constants.ATTR_RELATION); genericEntity.remove(Constants.ATTR_CONTACT_PRIORITY); genericEntity.remove(Constants.ATTR_PRIMARY_CONTACT_STATUS); } return genericEntities; } private  ParentsSorter(); }
ParentsSorter { public static List<GenericEntity> sort(List<GenericEntity> genericEntities) { for (GenericEntity genericEntity : genericEntities) { List<Map<String, Object>> studentParentAssociations = (List<Map<String, Object>>) genericEntity .get(Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS); if (studentParentAssociations != null && !studentParentAssociations.isEmpty()) { Map<String, Object> studentParentAssociation = studentParentAssociations.get(0); genericEntity.put(Constants.ATTR_RELATION, studentParentAssociation.get(Constants.ATTR_RELATION)); genericEntity.put(Constants.ATTR_CONTACT_PRIORITY, studentParentAssociation.get(Constants.ATTR_CONTACT_PRIORITY)); genericEntity.put(Constants.ATTR_PRIMARY_CONTACT_STATUS, studentParentAssociation.get(Constants.ATTR_PRIMARY_CONTACT_STATUS)); } } GenericEntityComparator comparator = new GenericEntityComparator(Constants.ATTR_RELATION, String.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_RELATION, relationPriority); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_CONTACT_PRIORITY, Double.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_PRIMARY_CONTACT_STATUS, primaryContactStatusPriority); Collections.sort(genericEntities, comparator); for (GenericEntity genericEntity : genericEntities) { genericEntity.remove(Constants.ATTR_RELATION); genericEntity.remove(Constants.ATTR_CONTACT_PRIORITY); genericEntity.remove(Constants.ATTR_PRIMARY_CONTACT_STATUS); } return genericEntities; } private  ParentsSorter(); static List<GenericEntity> sort(List<GenericEntity> genericEntities); }
ParentsSorter { public static List<GenericEntity> sort(List<GenericEntity> genericEntities) { for (GenericEntity genericEntity : genericEntities) { List<Map<String, Object>> studentParentAssociations = (List<Map<String, Object>>) genericEntity .get(Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS); if (studentParentAssociations != null && !studentParentAssociations.isEmpty()) { Map<String, Object> studentParentAssociation = studentParentAssociations.get(0); genericEntity.put(Constants.ATTR_RELATION, studentParentAssociation.get(Constants.ATTR_RELATION)); genericEntity.put(Constants.ATTR_CONTACT_PRIORITY, studentParentAssociation.get(Constants.ATTR_CONTACT_PRIORITY)); genericEntity.put(Constants.ATTR_PRIMARY_CONTACT_STATUS, studentParentAssociation.get(Constants.ATTR_PRIMARY_CONTACT_STATUS)); } } GenericEntityComparator comparator = new GenericEntityComparator(Constants.ATTR_RELATION, String.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_RELATION, relationPriority); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_CONTACT_PRIORITY, Double.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_PRIMARY_CONTACT_STATUS, primaryContactStatusPriority); Collections.sort(genericEntities, comparator); for (GenericEntity genericEntity : genericEntities) { genericEntity.remove(Constants.ATTR_RELATION); genericEntity.remove(Constants.ATTR_CONTACT_PRIORITY); genericEntity.remove(Constants.ATTR_PRIMARY_CONTACT_STATUS); } return genericEntities; } private  ParentsSorter(); static List<GenericEntity> sort(List<GenericEntity> genericEntities);  }