class SessionComparator implements Comparator<ClientSession> {

        @Override
        public int compare(ClientSession lhs, ClientSession rhs) {
            int comparison;
            switch (sortField) {
                case SessionResultFilter.SORT_CREATION_DATE:
                    comparison = lhs.getCreationDate().compareTo(rhs.getCreationDate());
                    break;
                case SessionResultFilter.SORT_LAST_ACTIVITY_DATE:
                    comparison = lhs.getLastActiveDate().compareTo(rhs.getCreationDate());
                    break;
                case SessionResultFilter.SORT_NUM_CLIENT_PACKETS:
                    comparison = (int)(lhs.getNumClientPackets() - rhs.getNumClientPackets());
                    break;
                case SessionResultFilter.SORT_NUM_SERVER_PACKETS:
                    comparison = (int)(lhs.getNumServerPackets() - rhs.getNumServerPackets());
                    break;
                case SessionResultFilter.SORT_USER:
                    // sort first by name, then by resource
                    String lUsername = lhs.isAnonymousUser() ? "" : lhs.getAddress().getNode();
                    String rUsername = rhs.isAnonymousUser() ? "" : rhs.getAddress().getNode();
                    comparison = compareString(lUsername, rUsername);
                    if (comparison == 0) {
                        comparison = compareString(lhs.getAddress().getResource(),
                                rhs.getAddress().getResource());
                    }
                    break;
                default:
                    comparison = 0;
            }
            if (sortOrder == SessionResultFilter.DESCENDING) {
                comparison *= -1; // Naturally ascending, flip sign if descending
            }
            return comparison;
        }

        private int compareString(String lhs, String rhs) {
            if (lhs == null) {
                lhs = "";
            }
            if (rhs == null) {
                rhs = "";
            }
            return lhs.compareTo(rhs);
        }
    }

    /**
     * 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)
     *
     * <table border="1">
     * <caption>Rounding examples</caption>
     * <tr><th>Date</th><th>Seconds</th><th>Result</th></tr>
     * <tr><td>1:37.48</td><td>5</td><td>1:37.45</td></tr>
     * <tr><td>1:37.48</td><td>10</td><td>1:37.40</td></tr>
     * <tr><td>1:37.48</td><td>30</td><td>1:37.30</td></tr>
     * <tr><td>1:37.48</td><td>60</td><td>1:37.00</td></tr>
     * <tr><td>1:37.48</td><td>120</td><td>1:36.00</td></tr>
     * </table>
     *
     * <p>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:</p>
     *
     * <pre>
     * SessionResultFilter filter = new SessionResultFilter();
     * filter.setSortOrder(SessionResultFilter.DESCENDING);
     * filter.setSortField(JiveGlobals.SORT_CREATION_DATE);
     * <b>filter.setCreationDateRangeMin(SessionResultFilter.roundDate(forum.getModificationDate(), 60));</b>
     * filter.setNumResults(1);
     * Iterator messages = forum.messages(filter);
     * ForumMessage lastPost = (ForumMessage)messages.next();
     * </pre>
     *
     * @param date the {@code Date} we want to round.
     * @param seconds the number of seconds we want to round the date to.
     * @return the given date, rounded down to the nearest specified number of seconds.
     */
    public static Date roundDate(Date date, int seconds) {
        return new Date(roundDate(date.getTime(), seconds));
    }

    /**
     * Rounds the given date down to the nearest specified second.
     *
     * @param date the date (as a long) that we want to round.
     * @param seconds the number of seconds we want to round the date to.
     * @return the given date (as a long), rounded down to the nearest
     *         specified number of seconds.
     */
    public static long roundDate(long date, int seconds) {
        return date - (date % (1000 * seconds));
    }

    @Override
    public boolean equals(Object object) {<FILL_FUNCTION_BODY>

        if (this == object) {
            return true;
        }
        if (object != null && object instanceof SessionResultFilter) {
            SessionResultFilter o = (SessionResultFilter)object;
            if (sortField != o.sortField) {
                return false;
            }
            if (sortOrder != o.sortOrder) {
                return false;
            }
            if (numResults != o.numResults) {
                return false;
            }
            if (!compare(username, o.username)) {
                return false;
            }

            if (!compare(creationDateRangeMin, o.creationDateRangeMin)) {
                return false;
            }
            if (!compare(creationDateRangeMax, o.creationDateRangeMax)) {
                return false;
            }
            if (!compare(lastActivityDateRangeMin, o.lastActivityDateRangeMin)) {
                return false;
            }
            if (!compare(lastActivityDateRangeMax, o.lastActivityDateRangeMax)) {
                return false;
            }
            // All checks passed, so equal.
            return true;
        }
        else {
            return false;
        }
    
<no_super_class>