/** * Get or create a new BeanComparator for beans of the given type. Without * any {@link #orderBy order-by} properties specified, the returned * BeanComparator can only order against null beans (null is * {@link #nullHigh high} by default), and treats all other comparisons as * equal. */ public static <T> BeanComparator<T> forClass(Class<T> clazz) { return new BeanComparator<T>(clazz); }
/** * Toggle reverse-order option on just the last {@link #orderBy order-by} * property. By default, order is ascending. If no order-by properties have * been specified, then reverse order is applied to the compared beans. */ public BeanComparator<T> reverse() { BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = mUsingComparator; bc.mFlags = mFlags ^ 0x01; return bc; }
/** * Set the order of comparisons against null as being low * on just the last {@link #orderBy order-by} property. If no order-by * properties have been specified, then null low order is applied to the * compared beans. * <p> * Calling 'reverse, nullLow' is equivalent to calling 'nullHigh, reverse'. */ public BeanComparator<T> nullLow() { BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = mUsingComparator; bc.mFlags = mFlags ^ ((~mFlags & 0x01) << 1); return bc; }
/** * Set the order of comparisons against null as being high (the default) * on just the last {@link #orderBy order-by} property. If no order-by * properties have been specified, then null high order is applied to the * compared beans. Null high order is the default for consistency with the * high ordering of {@link Float#NaN NaN} by * {@link Float#compareTo(Float) Float}. * <p> * Calling 'nullHigh, reverse' is equivalent to calling 'reverse, nullLow'. */ public BeanComparator<T> nullHigh() { BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = mUsingComparator; bc.mFlags = mFlags ^ ((mFlags & 0x01) << 1); return bc; }
/** * Specifiy a Comparator to use on just the last {@link #orderBy order-by} * property. This is good for comparing properties that are not * {@link Comparable} or for applying special ordering rules for a * property. If no order-by properties have been specified, then Comparator * is applied to the compared beans. * <p> * Any previously applied String {@link #caseSensitive case-sensitive} or * {@link #collate collator} settings are overridden by this Comparator. * If property values being compared are primitive, they are converted to * their object peers before being passed to the Comparator. * * @param c Comparator to use on the last order-by property. Passing null * restores the default comparison for the last order-by property. */ public <S> BeanComparator<T> using(Comparator<S> c) { BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = c; bc.mFlags = mFlags; return bc; }
/** * Set a Comparator for ordering Strings, which is passed on to all * BeanComparators derived from this one. By default, String are compared * using {@link String#CASE_INSENSITIVE_ORDER}. Passing null for a collator * will cause all String comparisons to use * {@link String#compareTo(String) String.compareTo}. * <p> * A {@link #using using} Comparator disables this setting. Passing null * to the using method will re-enable a collator. * * @param c Comparator to use for ordering all Strings. Passing null * causes all Strings to be ordered by * {@link String#compareTo(String) String.compareTo}. */ public BeanComparator<T> collate(Comparator<String> c) { BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = mUsingComparator; bc.mFlags = mFlags & ~0x04; bc.mCollator = c; return bc; }
/** * Override the collator and compare just the last order-by property using * {@link String#compareTo(String) String.compareTo}, if it is of type * String. If no order-by properties have been specified then this call is * ineffective. * <p> * A {@link #using using} Comparator disables this setting. Passing null to * the using method will re-enable a case-sensitive setting. */ public BeanComparator<T> caseSensitive() { if ((mFlags & 0x04) != 0) { // Already case-sensitive. return this; } BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = mUsingComparator; bc.mFlags = mFlags | 0x04; return bc; }
BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = propertyName;
/** * Get or create a new BeanComparator for beans of the given type. Without * any {@link #orderBy order-by} properties specified, the returned * BeanComparator can only order against null beans (null is * {@link #nullHigh high} by default), and treats all other comparisons as * equal. */ public static <T> BeanComparator<T> forClass(Class<T> clazz) { return new BeanComparator<T>(clazz); }
/** * Toggle reverse-order option on just the last {@link #orderBy order-by} * property. By default, order is ascending. If no order-by properties have * been specified, then reverse order is applied to the compared beans. */ public BeanComparator<T> reverse() { BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = mUsingComparator; bc.mFlags = mFlags ^ 0x01; return bc; }
/** * Set the order of comparisons against null as being low * on just the last {@link #orderBy order-by} property. If no order-by * properties have been specified, then null low order is applied to the * compared beans. * <p> * Calling 'reverse, nullLow' is equivalent to calling 'nullHigh, reverse'. */ public BeanComparator<T> nullLow() { BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = mUsingComparator; bc.mFlags = mFlags ^ ((~mFlags & 0x01) << 1); return bc; }
/** * Set the order of comparisons against null as being high (the default) * on just the last {@link #orderBy order-by} property. If no order-by * properties have been specified, then null high order is applied to the * compared beans. Null high order is the default for consistency with the * high ordering of {@link Float#NaN NaN} by * {@link Float#compareTo(Float) Float}. * <p> * Calling 'nullHigh, reverse' is equivalent to calling 'reverse, nullLow'. */ public BeanComparator<T> nullHigh() { BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = mUsingComparator; bc.mFlags = mFlags ^ ((mFlags & 0x01) << 1); return bc; }
/** * Override the collator and compare just the last order-by property using * {@link String#compareTo(String) String.compareTo}, if it is of type * String. If no order-by properties have been specified then this call is * ineffective. * <p> * A {@link #using using} Comparator disables this setting. Passing null to * the using method will re-enable a case-sensitive setting. */ public BeanComparator<T> caseSensitive() { if ((mFlags & 0x04) != 0) { // Already case-sensitive. return this; } BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = mUsingComparator; bc.mFlags = mFlags | 0x04; return bc; }
/** * Set a Comparator for ordering Strings, which is passed on to all * BeanComparators derived from this one. By default, String are compared * using {@link String#CASE_INSENSITIVE_ORDER}. Passing null for a collator * will cause all String comparisons to use * {@link String#compareTo(String) String.compareTo}. * <p> * A {@link #using using} Comparator disables this setting. Passing null * to the using method will re-enable a collator. * * @param c Comparator to use for ordering all Strings. Passing null * causes all Strings to be ordered by * {@link String#compareTo(String) String.compareTo}. */ public BeanComparator<T> collate(Comparator<String> c) { BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = mUsingComparator; bc.mFlags = mFlags & ~0x04; bc.mCollator = c; return bc; }
/** * Specifiy a Comparator to use on just the last {@link #orderBy order-by} * property. This is good for comparing properties that are not * {@link Comparable} or for applying special ordering rules for a * property. If no order-by properties have been specified, then Comparator * is applied to the compared beans. * <p> * Any previously applied String {@link #caseSensitive case-sensitive} or * {@link #collate collator} settings are overridden by this Comparator. * If property values being compared are primitive, they are converted to * their object peers before being passed to the Comparator. * * @param c Comparator to use on the last order-by property. Passing null * restores the default comparison for the last order-by property. */ public <S> BeanComparator<T> using(Comparator<S> c) { BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = mOrderByName; bc.mUsingComparator = c; bc.mFlags = mFlags; return bc; }
BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = propertyName;