private static int resolveOrder(Method method) { Order ann = AnnotatedElementUtils.findMergedAnnotation(method, Order.class); return (ann != null ? ann.value() : 0); }
private int resolveOrder(Method method) { Order ann = AnnotatedElementUtils.findMergedAnnotation(method, Order.class); return (ann != null ? ann.value() : 0); }
/** * Return the order on the specified {@code type}. * <p>Takes care of {@link Order @Order} and {@code @javax.annotation.Priority}. * @param type the type to handle * @return the order value, or {@code null} if none can be found * @see #getPriority(Class) */ @Nullable public static Integer getOrder(Class<?> type) { Object cached = orderCache.get(type); if (cached != null) { return (cached instanceof Integer ? (Integer) cached : null); } Order order = AnnotationUtils.findAnnotation(type, Order.class); Integer result; if (order != null) { result = order.value(); } else { result = getPriority(type); } orderCache.put(type, (result != null ? result : NOT_ANNOTATED)); return result; }
private static int lookupOrder(Object obj) { if (obj instanceof Ordered) { return ((Ordered) obj).getOrder(); } if (obj != null) { Class<?> clazz = (obj instanceof Class ? (Class<?>) obj : obj.getClass()); Order order = AnnotationUtils.findAnnotation(clazz, Order.class); if (order != null) { return order.value(); } } return Ordered.LOWEST_PRECEDENCE; } }
/** * Return the order on the specified {@code type}. * <p>Takes care of {@link Order @Order} and {@code @javax.annotation.Priority}. * @param type the type to handle * @return the order value, or {@code null} if none can be found * @see #getPriority(Class) */ @Nullable public static Integer getOrder(Class<?> type) { Object cached = orderCache.get(type); if (cached != null) { return (cached instanceof Integer ? (Integer) cached : null); } Order order = AnnotationUtils.findAnnotation(type, Order.class); Integer result; if (order != null) { result = order.value(); } else { result = getPriority(type); } orderCache.put(type, (result != null ? result : NOT_ANNOTATED)); return result; }
private int determineOrder(Class<?> theInterceptorClass) { int typeOrder = DEFAULT_ORDER; Order typeOrderAnnotation = AnnotationUtils.findAnnotation(theInterceptorClass, Order.class); if (typeOrderAnnotation != null) { typeOrder = typeOrderAnnotation.value(); } return typeOrder; }
@Override public int compare(Interpreter thees, Interpreter that) { Order thessOrder = thees.getClass().getAnnotation(Order.class); Order thatOrder = that.getClass().getAnnotation(Order.class); int thessValue = thessOrder == null ? 0 : thessOrder.value(); int thatValue = thatOrder == null ? 0 : thatOrder.value(); return thessValue - thatValue; } }
private void sortByOrderAnnotation(List<Object> theObjects) { IdentityHashMap<Object, Integer> interceptorToOrder = new IdentityHashMap<>(); for (Object next : theObjects) { Order orderAnnotation = next.getClass().getAnnotation(Order.class); int order = orderAnnotation != null ? orderAnnotation.value() : 0; interceptorToOrder.put(next, order); } theObjects.sort((a, b) -> { Integer orderA = interceptorToOrder.get(a); Integer orderB = interceptorToOrder.get(b); return orderA - orderB; }); }
@Override protected int getOrder(Object obj) { if (obj instanceof Ordered) { return ((Ordered) obj).getOrder(); } if (obj != null) { Order order = obj.getClass().getAnnotation(Order.class); if (order != null) { return order.value(); } } return Ordered.LOWEST_PRECEDENCE; }
private static int lookupOrder(Object obj) { if (obj instanceof Ordered) { return ((Ordered) obj).getOrder(); } if (obj != null) { Class<?> clazz = (obj instanceof Class ? (Class<?>) obj : obj.getClass()); Order order = AnnotationUtils.findAnnotation(clazz, Order.class); if (order != null) { return order.value(); } } return Ordered.LOWEST_PRECEDENCE; } }
private boolean scanInterceptorForHookMethodsAndAddThem(Object theInterceptor, int theTypeOrder) { boolean retVal = false; for (Method nextMethod : theInterceptor.getClass().getDeclaredMethods()) { Hook hook = AnnotationUtils.findAnnotation(nextMethod, Hook.class); if (hook != null) { int methodOrder = theTypeOrder; Order methodOrderAnnotation = AnnotationUtils.findAnnotation(nextMethod, Order.class); if (methodOrderAnnotation != null) { methodOrder = methodOrderAnnotation.value(); } HookInvoker invoker = new HookInvoker(hook, theInterceptor, nextMethod, methodOrder); for (Pointcut nextPointcut : hook.value()) { myInvokers.put(nextPointcut, invoker); } retVal = true; } } return retVal; }
private int getOrder(final Method method) { final int order; Order ann = AnnotationUtils.findAnnotation(method, Order.class); if (ann != null) { order = ann.value(); } else { order = LOWEST_PRECEDENCE; } return order; }
Order orderAnnotation = AnnotationUtils.findAnnotation(method, Order.class); if (orderAnnotation != null) { ((Orderable) handler).setOrder(orderAnnotation.value());
@Override public int compare(Interpreter thees, Interpreter that) { Order thessOrder = thees.getClass().getAnnotation(Order.class); Order thatOrder = that.getClass().getAnnotation(Order.class); int thessValue = thessOrder == null ? 0 : thessOrder.value(); int thatValue = thatOrder == null ? 0 : thatOrder.value(); return thessValue - thatValue; } }
@Override public int compare(Interpreter thees, Interpreter that) { Order thessOrder = thees.getClass().getAnnotation(Order.class); Order thatOrder = that.getClass().getAnnotation(Order.class); int thessValue = thessOrder == null ? 0 : thessOrder.value(); int thatValue = thatOrder == null ? 0 : thatOrder.value(); return thessValue - thatValue; } }
public class ComparatorReflection<T extends AccessibleObject & Member> implements Comparator<T>{ @Override public int compare(T o1, T o2) { Order or1 = o1.getAnnotation(Order.class); Order or2 = o2.getAnnotation(Order.class); if (or1 != null && or2 != null && or1.value() - or2.value() != 0) { return or1.value() - or2.value(); } return o1.getName().compareTo(o2.getName()); } }
private int resolveOrder(Method method) { Order ann = AnnotatedElementUtils.findMergedAnnotation(method, Order.class); return (ann != null ? ann.value() : 0); }
private static int lookupOrder(Object obj) { if (obj instanceof Ordered) { return ((Ordered) obj).getOrder(); } if (obj != null) { Class<?> clazz = (obj instanceof Class ? (Class<?>) obj : obj.getClass()); Order order = AnnotationUtils.findAnnotation(clazz,Order.class); if (order != null) { return order.value(); } } return Ordered.LOWEST_PRECEDENCE; } }