mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 14:05:44 +01:00
improve manager sort api
This commit is contained in:
@@ -83,6 +83,17 @@ public interface Manager<T extends ModelObject, E extends Exception>
|
||||
*/
|
||||
public Collection<T> getAll();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param comparator
|
||||
* @return
|
||||
* @since 1.4
|
||||
*/
|
||||
public Collection<T> getAll(Comparator<T> comparator);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -62,9 +62,12 @@ import sonia.scm.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -351,16 +354,35 @@ public class XmlGroupManager extends AbstractGroupManager
|
||||
*/
|
||||
@Override
|
||||
public Collection<Group> getAll()
|
||||
{
|
||||
return getAll(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param comparator
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Collection<Group> getAll(Comparator<Group> comparator)
|
||||
{
|
||||
SecurityUtil.assertIsAdmin(securityContextProvider);
|
||||
|
||||
LinkedList<Group> groups = new LinkedList<Group>();
|
||||
List<Group> groups = new ArrayList<Group>();
|
||||
|
||||
for (Group group : groupDB.values())
|
||||
{
|
||||
groups.add(group.clone());
|
||||
}
|
||||
|
||||
if (comparator != null)
|
||||
{
|
||||
Collections.sort(groups, comparator);
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,10 +71,10 @@ import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -377,12 +377,14 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param comparator
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Collection<Repository> getAll()
|
||||
public Collection<Repository> getAll(Comparator<Repository> comparator)
|
||||
{
|
||||
LinkedList<Repository> repositories = new LinkedList<Repository>();
|
||||
List<Repository> repositories = new ArrayList<Repository>();
|
||||
|
||||
for (Repository repository : repositoryDB.values())
|
||||
{
|
||||
@@ -394,9 +396,26 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
}
|
||||
}
|
||||
|
||||
if (comparator != null)
|
||||
{
|
||||
Collections.sort(repositories, comparator);
|
||||
}
|
||||
|
||||
return repositories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Collection<Repository> getAll()
|
||||
{
|
||||
return getAll(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -69,6 +69,7 @@ import java.io.InputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
@@ -395,16 +396,35 @@ public class XmlUserManager extends AbstractUserManager
|
||||
*/
|
||||
@Override
|
||||
public Collection<User> getAll()
|
||||
{
|
||||
return getAll(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param comparator
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Collection<User> getAll(Comparator<User> comparator)
|
||||
{
|
||||
SecurityUtil.assertIsAdmin(scurityContextProvider);
|
||||
|
||||
LinkedList<User> users = new LinkedList<User>();
|
||||
List<User> users = new ArrayList<User>();
|
||||
|
||||
for (User user : userDB.values())
|
||||
{
|
||||
users.add(user.clone());
|
||||
}
|
||||
|
||||
if (comparator != null)
|
||||
{
|
||||
Collections.sort(users, comparator);
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user