001: package org.wingx.table;
002:
003: import java.io.Serializable;
004: import java.util.Comparator;
005: import java.util.Arrays;
006:
007: /**
008: * ListSort
009: * A simple class to hold the ordering information of one field in a list.
010: *
011: * @author jde
012: */
013: public class ListSort implements Serializable {
014: private boolean ascending = true;
015:
016: private String field;
017: private String fields[];
018:
019: private Comparator comparator;
020:
021: public ListSort() {
022: }
023:
024: /**
025: * Creates a new ListSort on the given field.
026: */
027: public ListSort(String field) {
028: this .field = field;
029: }
030:
031: public ListSort(String[] fields) {
032: this .fields = fields;
033: }
034:
035: /**
036: * Creates a new ListSort on the given field.
037: */
038: public ListSort(String field, boolean ascending) {
039: this (field);
040: this .ascending = ascending;
041: }
042:
043: public ListSort(String field, boolean ascending,
044: Comparator comparator) {
045: this (field, ascending);
046: this .comparator = comparator;
047: }
048:
049: /**
050: * Reverses the order.
051: */
052: public void switchSort() {
053: ascending = !ascending;
054: }
055:
056: /**
057: * Returns true if the current field is marked "ascending".
058: */
059: public boolean isAscending() {
060: return ascending;
061: }
062:
063: /**
064: * Returns the string representation of the field.
065: */
066: public String getField() {
067: return field;
068: }
069:
070: public String[] getFields() {
071: return fields;
072: }
073:
074: public void setAscending(boolean ascending) {
075: this .ascending = ascending;
076: }
077:
078: public Comparator getComparator() {
079: return comparator;
080: }
081:
082: public void setComparator(Comparator comparator) {
083: this .comparator = comparator;
084: }
085:
086: public boolean equals(Object o) {
087: if (this == o)
088: return true;
089: if (o == null || getClass() != o.getClass())
090: return false;
091:
092: final ListSort listSort = (ListSort) o;
093:
094: if (field != null ? !field.equals(listSort.field)
095: : listSort.field != null)
096: return false;
097: if (!Arrays.equals(fields, listSort.fields))
098: return false;
099:
100: return true;
101: }
102:
103: public int hashCode() {
104: return (field != null ? field.hashCode() : 0);
105: }
106: }
|