mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-04-01 18:00:12 +02:00
start implementing paging and server side sorting for users, groups and repositories
This commit is contained in:
@@ -81,4 +81,20 @@ public interface Manager<T extends ModelObject, E extends Exception>
|
||||
* @return
|
||||
*/
|
||||
public Collection<T> getAll();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param sortby
|
||||
* @param desc
|
||||
* @param start
|
||||
* @param limit
|
||||
*
|
||||
* @return
|
||||
* @since 1.4
|
||||
*/
|
||||
public Collection<T> getAll(String sortby, boolean desc, int start,
|
||||
int limit);
|
||||
}
|
||||
|
||||
@@ -119,4 +119,19 @@ public class AssertUtil
|
||||
throw new IllegalStateException("object is not valid");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* throws an IllegalArgumentException if the value is smaller then 0
|
||||
*
|
||||
*
|
||||
* @param value
|
||||
* @since 1.4
|
||||
*/
|
||||
public static void assertPositive(int value)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new IllegalArgumentException("value is smaller then 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @param <T>
|
||||
* @since 1.4
|
||||
*/
|
||||
public interface CollectionAppender<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param collection
|
||||
* @param item
|
||||
*/
|
||||
public void append(Collection<T> collection, T item);
|
||||
}
|
||||
@@ -38,9 +38,13 @@ package sonia.scm.util;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@@ -177,6 +181,117 @@ public class Util
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param values
|
||||
* @param comparator
|
||||
* @param start
|
||||
* @param limit
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
* @since 1.4
|
||||
*/
|
||||
public static <T> Collection<T> createSubCollection(Collection<T> values,
|
||||
Comparator<T> comparator, int start, int limit)
|
||||
{
|
||||
return createSubCollection(values, comparator, null, start, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param values
|
||||
* @param start
|
||||
* @param limit
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
* @since 1.4
|
||||
*/
|
||||
public static <T> Collection<T> createSubCollection(Collection<T> values,
|
||||
int start, int limit)
|
||||
{
|
||||
return createSubCollection(values, null, null, start, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param values
|
||||
* @param appender
|
||||
* @param start
|
||||
* @param limit
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
* @since 1.4
|
||||
*/
|
||||
public static <T> Collection<T> createSubCollection(Collection<T> values,
|
||||
CollectionAppender<T> appender, int start, int limit)
|
||||
{
|
||||
return createSubCollection(values, null, appender, start, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param values
|
||||
* @param comparator
|
||||
* @param appender
|
||||
* @param start
|
||||
* @param limit
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
* @since 1.4
|
||||
*/
|
||||
public static <T> Collection<T> createSubCollection(Collection<T> values,
|
||||
Comparator<T> comparator, CollectionAppender<T> appender, int start,
|
||||
int limit)
|
||||
{
|
||||
List<T> result = new ArrayList<T>();
|
||||
List<T> valueList = new ArrayList(values);
|
||||
|
||||
if (comparator != null)
|
||||
{
|
||||
Collections.sort(valueList, comparator);
|
||||
}
|
||||
|
||||
int length = valueList.size();
|
||||
int end = start + limit;
|
||||
|
||||
if (length > start)
|
||||
{
|
||||
if (length < end)
|
||||
{
|
||||
end = length;
|
||||
}
|
||||
|
||||
valueList = valueList.subList(start, end);
|
||||
|
||||
if (appender == null)
|
||||
{
|
||||
result = valueList;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (T v : valueList)
|
||||
{
|
||||
appender.append(result, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user