Class 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
    • 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)
        Rounding examples
        DateSecondsResult
        1:37.4851:37.45
        1:37.48101:37.40
        1:37.48301:37.30
        1:37.48601:37.00
        1:37.481201: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 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object