package ru.matevosyan;

import java.util.*;

/**
 * UserSort was created to sort list ans set.
 * Created on 28.04.2017.
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class UserSort {

    /**
     * sort method sorted convert list to treeSet and sort treeSet with comparable class.
     * @param userList list of users.
     * @return sorted treeSet by age.
     */

    public Set<User> sort(List<User> userList) {

        Iterator<User> userIterator = userList.listIterator();
        TreeSet<User> userTreeSet = new TreeSet<>();

        while (userIterator.hasNext()) {
            User user = userIterator.next();
            userTreeSet.add(user);
        }
        return userTreeSet;
    }

    /**
     * sortHash use to sort list with comparator by hash code.
     * @param users list od users.
     * @return sorted list of users.
     */

    public List<User> sortHash (List<User> users) {
        Collections.sort(users, new Comparator<User>() {
            @Override
        public int compare(User user1, User user2) {
                Integer user1Hash = user1.hashCode();
                Integer user2Hash = user2.hashCode();

                return user1Hash.compareTo(user2Hash);
            }
    });
        return users;
    }

    /**
     * sortLength use to sort list with comparator by length name.
     * @param users list od users.
     * @return sorted list of users.
     */

    public List<User> sortLength (List<User> users) {
        Collections.sort(users, new Comparator<User>() {
            @Override
            public int compare(User o1, User o2) {
                Integer user1Length = o1.getName().length();
                Integer user2Length = o2.getName().length();

                return user1Length.compareTo(user2Length);
            }
        });
        return users;
    }

}

@@ -17,16 +17,17 @@
 osyan;%0A%0A
+%0A
 import j
@@ -35,17 +35,154 @@
 va.util.
-*
+Iterator;%0Aimport java.util.List;%0Aimport java.util.Set;%0Aimport java.util.TreeSet;%0Aimport java.util.Comparator;%0Aimport java.util.Collections
 ;%0A%0A/**%0A 
@@ -219,17 +219,17 @@
  list an
-s
+d
  set.%0A *

change imports