Source:
private List<Instance> sortInstances(List<Instance> instanceSet, String orderBy, String sortOrder) { final String order = getValidSortOrder(sortOrder, orderBy); if (orderBy.equals("status")) { Collections.sort(instanceSet, new Comparator<Instance>() { @Override public int compare(Instance i1, Instance i2) { if (i1.getStatus() == null) { i1.status = InstancesResult.WorkflowStatus.ERROR; } if (i2.getStatus() == null) { i2.status = InstancesResult.WorkflowStatus.ERROR; } return (order.equalsIgnoreCase("asc")) ? i1.getStatus().name().compareTo(i2.getStatus().name()) : i2.getStatus().name().compareTo(i1.getStatus().name()); } }); } else if (orderBy.equals("cluster")) { Collections.sort(instanceSet, new Comparator<Instance>() { @Override public int compare(Instance i1, Instance i2) { return (order.equalsIgnoreCase("asc")) ? i1.getCluster().compareTo(i2.getCluster()) : i2.getCluster().compareTo(i1.getCluster()); } }); } else if (orderBy.equals("starttime") || orderBy.isEmpty()){ Collections.sort(instanceSet, new Comparator<Instance>() { @Override public int compare(Instance i1, Instance i2) { Date start1 = (i1.getStartTime() == null) ? new Date(0) : i1.getStartTime(); Date start2 = (i2.getStartTime() == null) ? new Date(0) : i2.getStartTime(); return (order.equalsIgnoreCase("asc")) ? start1.compareTo(start2) : start2.compareTo(start1); } }); } else if (orderBy.equals("endtime")) { Collections.sort(instanceSet, new Comparator<Instance>() { @Override public int compare(Instance i1, Instance i2) { Date end1 = (i1.getEndTime() == null) ? new Date(0) : i1.getEndTime(); Date end2 = (i2.getEndTime() == null) ? new Date(0) : i2.getEndTime(); return (order.equalsIgnoreCase("asc")) ? end1.compareTo(end2) : end2.compareTo(end1); } }); } return instanceSet; }

Target:
private List<Instance> sortInstances(List<Instance> instanceSet, String orderBy, String sortOrder) { final String order = getValidSortOrder(sortOrder, orderBy); if (orderBy.equals("status")) { Collections.sort(instanceSet, new Comparator<Instance>() { @Override public int compare(Instance i1, Instance i2) { if (i1.getStatus() == null) { i1.status = InstancesResult.WorkflowStatus.ERROR; } if (i2.getStatus() == null) { i2.status = InstancesResult.WorkflowStatus.ERROR; } return (order.equalsIgnoreCase("asc")) ? i1.getStatus().name().compareTo(i2.getStatus().name()) : i2.getStatus().name().compareTo(i1.getStatus().name()); } }); } else if (orderBy.equals("cluster")) { Collections.sort(instanceSet, new Comparator<Instance>() { @Override public int compare(Instance i1, Instance i2) { return (order.equalsIgnoreCase("asc")) ? i1.getCluster().compareTo(i2.getCluster()) : i2.getCluster().compareTo(i1.getCluster()); } }); } else if (orderBy.equals("starttime")){ Collections.sort(instanceSet, new Comparator<Instance>() { @Override public int compare(Instance i1, Instance i2) { Date start1 = (i1.getStartTime() == null) ? new Date(0) : i1.getStartTime(); Date start2 = (i2.getStartTime() == null) ? new Date(0) : i2.getStartTime(); return (order.equalsIgnoreCase("asc")) ? start1.compareTo(start2) : start2.compareTo(start1); } }); } else if (orderBy.equals("endtime")) { Collections.sort(instanceSet, new Comparator<Instance>() { @Override public int compare(Instance i1, Instance i2) { Date end1 = (i1.getEndTime() == null) ? new Date(0) : i1.getEndTime(); Date end2 = (i2.getEndTime() == null) ? new Date(0) : i2.getEndTime(); return (order.equalsIgnoreCase("asc")) ? end1.compareTo(end2) : end2.compareTo(end1); } }); } return instanceSet; }