Album Cover

Refactoring Java

Close Preview
A class called Group has a method called getUsers(). Below are three versions of that method.
Please drag and drop the versions such that the best is on top, the 2nd best beneath it, and the worst is at the bottom. More instructions...
Place these in the correct order:
  • public class Group…
       // Gets users sorted by the most recently registered user
       public List getUsers() {
          List users = new ArrayList();
    if (!new File(persistencePath()).exists()) return users;
    File[] files = new File(persistencePath()).listFiles(); for (File file : files) if (file.isDirectory()) users.add(new User(file.getName(), this));
    Collections.sort(users, new User.UserComparatorByDescendingRegistration());
    return users; }
  • public class Group…
       public List getUsers() {
          List users = new ArrayList();
    if (!userDirectoryExists()) return users;
    // Add found users to users collection File[] files = new File(persistencePath()).listFiles(); for (File file : files) if (file.isDirectory()) users.add(new User(file.getName(), this));
    // sort by most recently registered users Collections.sort(users, new User.UserComparatorByDescendingRegistration());
    return users; }
  • public class Group…
       public List getUsersSortedByMostRecentlyRegistered() {
          List users = new ArrayList();
    if (!userDirectoryExists()) return users;
    addFoundUsersTo(users);
    sortByMostRecentlyRegistered(users);
    return users; }
       
(Reading...)
| Tweet...
Page rating: | Rate this Page