Class SessionResultFilter
The class also supports pagination of results with the setStartIndex(int) and setNumResults(int) methods. If the start index is not set, it will begin at index 0 (the start of results). If the number of results is not set, it will be unbounded and return as many results as available.
Factory methods to create common queries are provided for convenience.
- Author:
- Matt Tucker
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Ascending sort (ie 3, 4, 5...).static final int
Descending sort (ie 3, 2, 1...).static final int
Represents no result limit (infinite results).static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SessionResultFilter
Creates a default SessionResultFilter: no filtering with results sorted by user (ascending).boolean
int
Returns the max number of results that should be returned.Returns a comparator that will sort a standard sorted set according to this filter's sort order.int
Returns the currently selected sort field.int
Returns the sort order, which will be SessionResultFilter.ASCENDING for ascending sorting, or SessionResultFilter.DESCENDING for descending sorting.int
Returns the index of the first result to return.int
hashCode()
static long
roundDate
(long date, int seconds) Rounds the given date down to the nearest specified second.static Date
Rounds the given date down to the nearest specified second.void
setNumResults
(int numResults) Sets the limit on the number of results to be returned.void
setSortField
(int sortField) Sets the sort field to use.void
setSortOrder
(int sortOrder) Sets the sort type.void
setStartIndex
(int startIndex) Sets the index of the first result to return.
-
Field Details
-
DESCENDING
public static final int DESCENDINGDescending sort (ie 3, 2, 1...).- See Also:
-
ASCENDING
public static final int ASCENDINGAscending sort (ie 3, 4, 5...).- See Also:
-
NO_RESULT_LIMIT
public static final int NO_RESULT_LIMITRepresents no result limit (infinite results).- See Also:
-
SORT_USER
public static final int SORT_USER- See Also:
-
SORT_CREATION_DATE
public static final int SORT_CREATION_DATE- See Also:
-
SORT_LAST_ACTIVITY_DATE
public static final int SORT_LAST_ACTIVITY_DATE- See Also:
-
SORT_NUM_CLIENT_PACKETS
public static final int SORT_NUM_CLIENT_PACKETS- See Also:
-
SORT_NUM_SERVER_PACKETS
public static final int SORT_NUM_SERVER_PACKETS- See Also:
-
-
Constructor Details
-
SessionResultFilter
public SessionResultFilter()
-
-
Method Details
-
createDefaultSessionFilter
Creates a default SessionResultFilter: no filtering with results sorted by user (ascending).- Returns:
- default SessionResultFilter.
-
getSortField
public int getSortField()Returns the currently selected sort field. The default value is SessionResultFilter.SORT_LAST_ACTIVITY_DATE.- Returns:
- current sort field.
-
setSortField
public void setSortField(int sortField) Sets the sort field to use. The default value is SessionResultFilter.SORT_LAST_ACTIVITY_DATE.- Parameters:
sortField
- the field that will be used for sorting.
-
getSortOrder
public int getSortOrder()Returns the sort order, which will be SessionResultFilter.ASCENDING for ascending sorting, or SessionResultFilter.DESCENDING for descending sorting. Descending sorting is: 3, 2, 1, etc. Ascending sorting is 1, 2, 3, etc.- Returns:
- the sort order.
-
setSortOrder
public void setSortOrder(int sortOrder) Sets the sort type. Valid arguments are SessionResultFilter.ASCENDING for ascending sorting or SessionResultFilter.DESCENDING for descending sorting. Descending sorting is: 3, 2, 1, etc. Ascending sorting is 1, 2, 3, etc.- Parameters:
sortOrder
- the order that results will be sorted in.
-
getNumResults
public int getNumResults()Returns the max number of results that should be returned.
The default value for is NO_RESULT_LIMIT, which means there will be no limit on the number of results. This method can be used in combination with setStartIndex(int) to perform pagination of results.
- Returns:
- the max number of results to return or NO_RESULT_LIMIT for no limit
- See Also:
-
setNumResults
public void setNumResults(int numResults) Sets the limit on the number of results to be returned.
User NO_RESULT_LIMIT if you don't want to limit the results returned.
- Parameters:
numResults
- the number of results to return or NO_RESULT_LIMIT for no limit
-
getStartIndex
public int getStartIndex()Returns the index of the first result to return.- Returns:
- the index of the first result which should be returned.
-
setStartIndex
public void setStartIndex(int startIndex) Sets the index of the first result to return. For example, if the start index is set to 20, the Iterator returned will start at the 20th result in the query. This method can be used in combination with setNumResults(int) to perform pagination of results.- Parameters:
startIndex
- the index of the first result to return.
-
getSortComparator
Returns a comparator that will sort a standard sorted set according to this filter's sort order.- Returns:
- a comparator that sorts Sessions matching the sort order for this filter.
-
roundDate
Rounds the given date down to the nearest specified second. The following table shows sample input and expected output values: (Note, only the time portion of the date is shown for brevity)Rounding examples Date Seconds Result 1:37.48 5 1:37.45 1:37.48 10 1:37.40 1:37.48 30 1:37.30 1:37.48 60 1:37.00 1:37.48 120 1:36.00 This method is useful when calculating the last post in a forum or the number of new messages from a given date. Using a rounded date allows Jive to internally cache the results of the date query. Here's an example that shows the last posted message in a forum accurate to the last 60 seconds:
SessionResultFilter filter = new SessionResultFilter(); filter.setSortOrder(SessionResultFilter.DESCENDING); filter.setSortField(JiveGlobals.SORT_CREATION_DATE); filter.setCreationDateRangeMin(SessionResultFilter.roundDate(forum.getModificationDate(), 60)); filter.setNumResults(1); Iterator messages = forum.messages(filter); ForumMessage lastPost = (ForumMessage)messages.next();
- Parameters:
date
- theDate
we want to round.seconds
- the number of seconds we want to round the date to.- Returns:
- the given date, rounded down to the nearest specified number of seconds.
-
roundDate
public static long roundDate(long date, int seconds) Rounds the given date down to the nearest specified second.- Parameters:
date
- the date (as a long) that we want to round.seconds
- the number of seconds we want to round the date to.- Returns:
- the given date (as a long), rounded down to the nearest specified number of seconds.
-
equals
-
hashCode
public int hashCode()
-