예제 #1
0
 // сортирует список отпусков по ФИО сотрудников, а внутри группы по сотруднику - по типу отпусков
 private void sortVacations(List<Vacation> vacations) {
   Collections.sort(
       vacations,
       new Comparator() {
         @Override
         public int compare(Object v1, Object v2) {
           String employeeName1 = ((Vacation) v1).getEmployee().getName();
           String employeeName2 = ((Vacation) v2).getEmployee().getName();
           int compareRes = employeeName2.compareTo(employeeName1);
           if (compareRes == 0) {
             Integer typeId1 = ((Vacation) v1).getType().getId();
             Integer typeId2 = ((Vacation) v2).getType().getId();
             return typeId1.compareTo(typeId2);
           }
           return employeeName1.compareTo(employeeName2);
         }
       });
 }
예제 #2
0
 public List<DictionaryItem> getVacationTypes(List<Vacation> vacations) {
   List<DictionaryItem> result = new ArrayList<DictionaryItem>();
   for (Vacation vacation : vacations) {
     if (!result.contains(vacation.getType())) {
       result.add(vacation.getType());
     }
   }
   // отсортируем
   Collections.sort(
       result,
       new Comparator() {
         @Override
         public int compare(Object type1, Object type2) {
           Integer typeId1 = ((DictionaryItem) type1).getId();
           Integer typeId2 = ((DictionaryItem) type2).getId();
           return typeId1.compareTo(typeId2);
         }
       });
   return result;
 }