sessionresultfilter.java
来自「基于Jabber协议的即时消息服务器」· Java 代码 · 共 588 行 · 第 1/2 页
JAVA
588 行
/**
* $Revision: 580 $
* $Date: 2004-12-01 18:46:33 -0300 (Wed, 01 Dec 2004) $
*
* Copyright (C) 2004-2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire;
import java.util.Comparator;
import java.util.Date;
/**
* 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".<p>
*
* 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.<p>
*
* Factory methods to create common queries are provided for convenience.
*
* @author Matt Tucker
*/
public class SessionResultFilter {
// ############################################################
// Search order criteria
// ############################################################
/**
* Descending sort (ie 3, 2, 1...).
*/
public static final int DESCENDING = 0;
/**
* Ascending sort (ie 3, 4, 5...).
*/
public static final int ASCENDING = 1;
// ############################################################
// Result limit search criteria
// ############################################################
/**
* Represents no result limit (infinite results).
*/
public static final int NO_RESULT_LIMIT = -1;
// ############################################################
// Packet limit search criteria
// ############################################################
/**
* Represents no result limit (infinite results).
*/
public static final long NO_PACKET_LIMIT = -1;
// ############################################################
// Sort fields
// ############################################################
public static final int SORT_USER = 0;
public static final int SORT_CREATION_DATE = 1;
public static final int SORT_LAST_ACTIVITY_DATE = 2;
public static final int SORT_NUM_CLIENT_PACKETS = 3;
public static final int SORT_NUM_SERVER_PACKETS = 4;
/**
* Creates a default SessionResultFilter: no filtering with results sorted
* by user (ascending).
*/
public static SessionResultFilter createDefaultSessionFilter() {
SessionResultFilter resultFilter = new SessionResultFilter();
resultFilter.setSortField(SORT_USER);
resultFilter.setSortOrder(ASCENDING);
return resultFilter;
}
private int sortField = SORT_LAST_ACTIVITY_DATE;
private int sortOrder = DESCENDING;
private long clientPacketRangeMin = NO_PACKET_LIMIT;
private long clientPacketRangeMax = NO_PACKET_LIMIT;
private long serverPacketRangeMin = NO_PACKET_LIMIT;
private long serverPacketRangeMax = NO_PACKET_LIMIT;
private String username = null;
/**
* The starting index for results. Default is 0.
*/
private int startIndex = 0;
/**
* Number of results to return. Default is NO_RESULT_LIMIT
* which means an unlimited number of results.
*/
private int numResults = NO_RESULT_LIMIT;
private Date creationDateRangeMin = null;
private Date creationDateRangeMax = null;
private Date lastActivityDateRangeMin = null;
private Date lastActivityDateRangeMax = null;
/**
* Returns the username that results will be filtered on. The method will
* return <tt>null</tt> if no user to filter on has been specified.
*
* @return the username that results will be filtered on.
*/
public String getUsername() {
return username;
}
/**
* Sets the username that results will be filtered on. By default, no filtering on
* username will take place. To avoid filtering on username pass in <tt>null</tt>.
*
* @param username the user ID to filter on.
*/
public void setUsername(String username) {
this.username = username;
}
/**
* Returns the creation date that represents the lower boundary for
* sessions to be filtered on. If this value has not been set, the method
* will return null.
*
* @return a Date representing the lower bound for creation dates to filter on.
*/
public Date getCreationDateRangeMin() {
return creationDateRangeMin;
}
/**
* Sets the date that represents the lower boundary for sessions to
* be selected by the result filter. If this value is not set the results filter will
* be unbounded for the earliest creation date selected.
*
* @param creationDateRangeMin Date representing the filter lowest value of
* the creation date to be selected.
*/
public void setCreationDateRangeMin(Date creationDateRangeMin) {
this.creationDateRangeMin = creationDateRangeMin;
}
/**
* Returns a date that represents the upper boundry for sessions to
* be selected by the result filter. If this value is not set it will return null
* and the results filter will be unbounded for the latest creation date selected.
*
* @return a Date representing the filter highest value of the creation date to be
* selected.
*/
public Date getCreationDateRangeMax() {
return creationDateRangeMax;
}
/**
* Sets a date that represents the upper boundry for sessions to
* be selected by the result filter. If this value is not set the results
* filter will be unbounded for the latest creation date selected.
*
* @param creationDateRangeMax Date representing the filter lowest value of
* the creation date range.
*/
public void setCreationDateRangeMax(Date creationDateRangeMax) {
this.creationDateRangeMax = creationDateRangeMax;
}
/**
* Returns a date that represents the lower boundary for session
* to be selected by the result filter. If this value is not set it will
* return null and the results filter will be unbounded for the earliest
* last activity date selected.
*
* @return a Date representing the filter lowest value of the last activity date
* range.
*/
public Date getLastActivityDateRangeMin() {
return lastActivityDateRangeMin;
}
/**
* Sets a date that represents the lower boundary for sessions to
* be selected by the result filter. If this value is not set the results
* filter will be unbounded for the earliest last activity date selected.
*
* @param lastActivityDateRangeMin Date representing the filter lowest value of
* the last activity date to be selected.
*/
public void setLastActivityDateRangeMin(Date lastActivityDateRangeMin) {
this.lastActivityDateRangeMin = lastActivityDateRangeMin;
}
/**
* Returns a date that represents the upper boundry for sessions to
* be selected by the result filter. If this value is not set it will return null
* and the results filter will be unbounded for the latest activity date selected.
*
* @return a Date representing the filter highest value of the last activity date to be
* selected.
*/
public Date getLastActivityDateRangeMax() {
return lastActivityDateRangeMax;
}
/**
* Sets a date that represents the upper boundry for sessions to
* be selected by the result filter. If this value is not set the results filter will
* be unbounded for the latest activity date selected.
*
* @param lastActivityDateRangeMax Date representing the filter lowest value of
* the last activity date range.
*/
public void setLastActivityDateRangeMax(Date lastActivityDateRangeMax) {
this.lastActivityDateRangeMax = lastActivityDateRangeMax;
}
/**
* Returns the lower boundary on client packets for sessions to be selected
* by the result filter. A value of {@link #NO_PACKET_LIMIT} will be returned if
* there is no lower packet limit.
*
* @return the lower limit of client packets allowed for sessions to meet this
* filter requirement.
*/
public long getClientPacketRangeMin() {
return clientPacketRangeMin;
}
/**
* Sets the lower boundary on client packets for sessions to be selected
* by the result filter. If this value is not set (using the value
* {@link #NO_PACKET_LIMIT}), the results filter will have no lower bounds
* for client packets selected.
*
* @param min the lower limit of client packets allowed for sessions to meet
* this filter requirement.
*/
public void setClientPacketRangeMin(long min) {
this.clientPacketRangeMin = min;
}
/**
* Returns the upper boundary on client packets for sessions to be selected
* by the result filter. A value of {@link #NO_PACKET_LIMIT} will be returned if
* there is no upper packet limit.
*
* @return the upper limit of client packets allowed for sessions to meet this
* filter requirement.
*/
public long getClientPacketRangeMax() {
return clientPacketRangeMax;
}
/**
* Sets the upper boundary on client packets for sessions to be selected
* by the result filter. If this value is not set (using the value
* {@link #NO_PACKET_LIMIT}), the results filter will have no upper bounds
* for client packets selected.
*
* @param max the upper limit of client packets allowed for sessions to meet
* this filter requirement.
*/
public void setClientPacketRangeMax(long max) {
this.clientPacketRangeMax = max;
}
/**
* Returns the lower boundary on server packets for sessions to be selected
* by the result filter. A value of {@link #NO_PACKET_LIMIT} will be returned if
* there is no lower packet limit.
*
* @return the lower limit of server packets allowed for sessions to meet this
* filter requirement.
*/
public long getServerPacketRangeMin() {
return serverPacketRangeMin;
}
/**
* Sets the lower boundary on server packets for sessions to be selected
* by the result filter. If this value is not set (using the value
* {@link #NO_PACKET_LIMIT}), the results filter will have no lower bounds
* for server packets selected.
*
* @param min the lower limit of server packets allowed for sessions to meet
* this filter requirement.
*/
public void setServerPacketRangeMin(long min) {
this.serverPacketRangeMin = min;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?