Overview | Package | Class | Tree | Deprecated | Index | Help
| Openfire 3.7.1 Javadoc
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jivesoftware.openfire
Class SessionResultFilter

    java.lang.Object
      org.jivesoftware.openfire.SessionResultFilter

    public class SessionResultFilter

extends Object

Filters and sorts lists of sessions. This allows for a very rich set of possible queries that can be run on session data. Some examples are: "Show all sessions started during the last hour by a certain user".

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
`static int` | `ASCENDING` Ascending sort (ie 3, 4, 5...).
`static int` | `DESCENDING` Descending sort (ie 3, 2, 1...).
`static int` | `NO_RESULT_LIMIT` Represents no result limit (infinite results).
`static int` | `SORT_CREATION_DATE`
`static int` | `SORT_LAST_ACTIVITY_DATE`
`static int` | `SORT_NUM_CLIENT_PACKETS`
`static int` | `SORT_NUM_SERVER_PACKETS`
`static int` | `SORT_USER`

Constructor Summary
`SessionResultFilter()`

Method Summary
`static SessionResultFilter` | `createDefaultSessionFilter()` Creates a default SessionResultFilter: no filtering with results sorted by user (ascending).
`boolean` | `equals(Object object)`
`int` | `getNumResults()` Returns the max number of results that should be returned.
`Comparator<ClientSession>` | `getSortComparator()` Returns a comparator that will sort a standard sorted set according to this filter's sort order.
`int` | `getSortField()` Returns the currently selected sort field.
`int` | `getSortOrder()` Returns the sort order, which will be SessionResultFilter.ASCENDING for ascending sorting, or SessionResultFilter.DESCENDING for descending sorting.
`int` | `getStartIndex()` Returns the index of the first result to return.
`static Date` | `roundDate(Date date, int seconds)` Rounds the given date down to the nearest specified second.
`static long` | `roundDate(long date, int seconds)` Rounds the given date down to the nearest specfied 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.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DESCENDING

    public static final int DESCENDING

  Descending sort (ie 3, 2, 1...).

  See Also:
    Constant Field Values

### ASCENDING

    public static final int ASCENDING

  Ascending sort (ie 3, 4, 5...).

  See Also:
    Constant Field Values

### NO_RESULT_LIMIT

    public static final int NO_RESULT_LIMIT

  Represents no result limit (infinite results).

  See Also:
    Constant Field Values

### SORT_USER

    public static final int SORT_USER

See Also:
  Constant Field Values

### SORT_CREATION_DATE

    public static final int SORT_CREATION_DATE

See Also:
  Constant Field Values

### SORT_LAST_ACTIVITY_DATE

    public static final int SORT_LAST_ACTIVITY_DATE

See Also:
  Constant Field Values

### SORT_NUM_CLIENT_PACKETS

    public static final int SORT_NUM_CLIENT_PACKETS

See Also:
  Constant Field Values

### SORT_NUM_SERVER_PACKETS

    public static final int SORT_NUM_SERVER_PACKETS

See Also:
  Constant Field Values

Constructor Detail

### SessionResultFilter

    public SessionResultFilter()

Method Detail

### createDefaultSessionFilter

    public static SessionResultFilter 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:
    `setStartIndex(int)`

### 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

    public Comparator<ClientSession> 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

    public static Date roundDate(Date date,
                                 int seconds)

  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)

  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` - the `Date` 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 specfied 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

    public boolean equals(Object object)

  Overrides:
    `equals` in class `Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Openfire 3.7.1 Javadoc
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2008 Jive Software.