/** * @param sort when true, sort annotation members by name (case sensitive) */ public AnnotationVisitor(boolean sort) { if (sort) { mMethodComparator = BeanComparator .forClass(Method.class).orderBy("name").caseSensitive(); } else { mMethodComparator = null; } }
BeanProperty prop = getProperties().get(propertyName); BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = propertyName; BeanComparator<?> subOrder = forClass(prop.getType()); subOrder.mCollator = mCollator; bc = bc.using(subOrder.orderBy(subName)); return reverse ? bc.reverse() : bc;
/** * Compares BeanComparators for equality based on their imposed ordering. * Returns true only if the given object is a BeanComparater and it can be * determined without a doubt that the ordering is identical. Because * equality testing is dependent on the behavior of the equals methods of * any 'using' Comparators and/or collators, false may be returned even * though ordering is in fact identical. */ public boolean equals(Object obj) { if (obj instanceof BeanComparator) { BeanComparator bc = (BeanComparator)obj; return mFlags == bc.mFlags && equalTest(mBeanClass, bc.mBeanClass) && equalTest(mOrderByName, bc.mOrderByName) && equalTest(mUsingComparator, bc.mUsingComparator) && equalTest(mCollator, bc.mCollator) && equalTest(mParent, bc.mParent); } else { return false; } }
setHashCode(rules); clazz = generateComparatorClass(rules); cGeneratedComparatorCache.put(rules, clazz); } else if (c instanceof Comparator) {
private static BeanComparator orderBy(BeanComparator bc, String property, Class type, Direction direction) { bc = bc.orderBy(property); if (type != null && type.isArray()) { TypeDesc td = TypeDesc.forClass(type); if (td.getRootComponentType() == TypeDesc.BYTE) { bc = bc.using(Comparators.arrayComparator(type, true)); } else { Comparator c = Comparators.arrayComparator(type, false); if (c == null) { throw new IllegalArgumentException("Cannot sort by property type of " + type.getName() + " for " + property); } bc = bc.using(c); } } else { bc = bc.caseSensitive(); } if (direction == Direction.DESCENDING) { bc = bc.reverse(); } return bc; }
private StorableProperty<S>[] ensureAllProperties(StorableProperty<S>[] properties) { if (properties == null) { properties = gatherAllProperties(); } else { for (Object prop : properties) { if (prop == null) { throw new IllegalArgumentException(); } } // Sort to generate more efficient code. properties = properties.clone(); Arrays.sort(properties, BeanComparator.forClass(StorableProperty.class).orderBy("number")); } return properties; }
(BeanProperty)bc.getProperties().get(bc.mOrderByName); Class propertyClass = prop.getType(); TypeDesc propertyType = TypeDesc.forClass(propertyClass); generateComparableCompareTo (builder, propertyClass, compareToMethod, resultLabel, nextLabel, p1, p2); generatePrimitiveComparison(builder, propertyClass, p1,p2); } else { generateComparableCompareTo (builder, propertyClass, compareToMethod, null, nextLabel, p1, p2);
/** * 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); }
/** * Convenience method to create a comparator which orders storables by the * given properties. * * @param properties list of properties to order by * @throws IllegalArgumentException if no properties or if any property is null */ public static <S extends Storable> Comparator<S> createComparator(List<OrderedProperty<S>> properties) { if (properties == null || properties.size() == 0 || properties.get(0) == null) { throw new IllegalArgumentException(); } Class<S> type = properties.get(0).getChainedProperty().getPrimeProperty().getEnclosingType(); BeanComparator bc = BeanComparator.forClass(type); for (OrderedProperty<S> property : properties) { if (property == null) { throw new IllegalArgumentException(); } bc = orderBy(bc, property); } return bc; }
private static BeanComparator orderBy(BeanComparator bc, String property, Class type, Direction direction) { bc = bc.orderBy(property); if (type != null && type.isArray()) { TypeDesc td = TypeDesc.forClass(type); if (td.getRootComponentType() == TypeDesc.BYTE) { bc = bc.using(Comparators.arrayComparator(type, true)); } else { Comparator c = Comparators.arrayComparator(type, false); if (c == null) { throw new IllegalArgumentException("Cannot sort by property type of " + type.getName() + " for " + property); } bc = bc.using(c); } } else { bc = bc.caseSensitive(); } if (direction == Direction.DESCENDING) { bc = bc.reverse(); } return bc; }
private StorableProperty<S>[] ensureAllProperties(StorableProperty<S>[] properties) { if (properties == null) { properties = gatherAllProperties(); } else { for (Object prop : properties) { if (prop == null) { throw new IllegalArgumentException(); } } // Sort to generate more efficient code. properties = properties.clone(); Arrays.sort(properties, BeanComparator.forClass(StorableProperty.class).orderBy("number")); } return properties; }
(BeanProperty)bc.getProperties().get(bc.mOrderByName); Class propertyClass = prop.getType(); TypeDesc propertyType = TypeDesc.forClass(propertyClass); generateComparableCompareTo (builder, propertyClass, compareToMethod, resultLabel, nextLabel, p1, p2); generatePrimitiveComparison(builder, propertyClass, p1,p2); } else { generateComparableCompareTo (builder, propertyClass, compareToMethod, null, nextLabel, p1, p2);
/** * 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; }
/** * Convenience method to create a comparator which orders storables by the * given properties. * * @param properties list of properties to order by * @throws IllegalArgumentException if no properties or if any property is null */ public static <S extends Storable> Comparator<S> createComparator(List<OrderedProperty<S>> properties) { if (properties == null || properties.size() == 0 || properties.get(0) == null) { throw new IllegalArgumentException(); } Class<S> type = properties.get(0).getChainedProperty().getPrimeProperty().getEnclosingType(); BeanComparator bc = BeanComparator.forClass(type); for (OrderedProperty<S> property : properties) { if (property == null) { throw new IllegalArgumentException(); } bc = orderBy(bc, property); } return bc; }
setHashCode(rules); clazz = generateComparatorClass(rules); cGeneratedComparatorCache.put(rules, clazz); } else if (c instanceof Comparator) {
BeanProperty prop = getProperties().get(propertyName); BeanComparator<T> bc = new BeanComparator<T>(this); bc.mOrderByName = propertyName; BeanComparator<?> subOrder = forClass(prop.getType()); subOrder.mCollator = mCollator; bc = bc.using(subOrder.orderBy(subName)); return reverse ? bc.reverse() : bc;
/** * @param sort when true, sort annotation members by name (case sensitive) */ public AnnotationVisitor(boolean sort) { if (sort) { mMethodComparator = BeanComparator .forClass(Method.class).orderBy("name").caseSensitive(); } else { mMethodComparator = null; } }
/** * 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; }
BeanComparator bc = BeanComparator.forClass(type);