@Test public final void testLoadTunables() { interceptor.getHandlers(hasAnnotatedField); interceptor.getHandlers(hasAnnotatedSetterAndGetterMethods); }
private List<T> loadTunables(final Object obj, final double initialOffset) { List<T> handlerList = handlerMap.get(obj); if (handlerList == null) { handlerList = new ArrayList<T>(); handlerMap.put(obj, handlerList); for (final Field field : obj.getClass().getFields()) { if (field.isAnnotationPresent(Tunable.class)) { try { final Tunable tunable = field.getAnnotation(Tunable.class); T handler = getHandler(field, obj, tunable); if (handler instanceof AbstractTunableHandler) ((AbstractTunableHandler)handler).setOffset(initialOffset); if (handler != null) { handlerList.add(handler); } else logOrThrowException("No handler for type: " + field.getType().getName(), null); } catch (final Throwable ex) { logOrThrowException("tunable field intercept failed for " + field.toString(), ex); } } else if (field.isAnnotationPresent(ContainsTunables.class)) { try { Object tunableContainer = field.get(obj); final ContainsTunables containsT = field.getAnnotation(ContainsTunables.class); double offset = containsT.offset(); if (offset == 999.0) offset = 0.0; if (tunableContainer instanceof Task) { List<T>subTaskHandlers = loadTunables(tunableContainer, initialOffset+offset); handlerList.addAll( subTaskHandlers ); handlerMap.put(tunableContainer, new ArrayList<T>()); } else { if ( !handlerMap.containsKey(tunableContainer) ) handlerList.addAll( loadTunables(tunableContainer, initialOffset) ); } } catch (final Throwable ex) { logOrThrowException("ContainsTunables field intercept failed for " + field.toString(), ex); } } } for (final Method method : obj.getClass().getMethods()) { if (method.isAnnotationPresent(Tunable.class)) { try { final Tunable tunable = method.getAnnotation(Tunable.class); final String rootName = validateAndExtractRootName(method); final Method setter = findCompatibleSetter(obj, rootName, method.getReturnType()); final T handler = getHandler(method, setter, obj, tunable); if (handler instanceof AbstractTunableHandler) ((AbstractTunableHandler)handler).setOffset(initialOffset); if (handler == null) { logOrThrowException("Failed to create a handler for " + setter.getName() + "().",null); } else { handlerList.add(handler); } } catch (Throwable t) { logOrThrowException("tunable method intercept failed for " + method.toString(), t); } } else if (method.isAnnotationPresent(ProvidesTitle.class)) { if (!String.class.isAssignableFrom(method.getReturnType())) { throw new IllegalArgumentException(method.getName() + " annotated with @ProvidesTitle must return String."); } else if (method.getParameterTypes().length != 0) { throw new IllegalArgumentException(method.getName() + " annotated with @ProvidesTitle must take 0 arguments."); } else { if (titleProviderMap.containsKey(obj) && initialOffset == 0.0) { throw new IllegalArgumentException("Classes must have at most one @ProvidesTitle annotated method but " + method.getDeclaringClass().getName() + " has more than one."); } titleProviderMap.put(obj, method); } } } Collections.sort(handlerList, new TunableGravityOrderer()); } return handlerList; }
AbstractTunableInterceptor { private List<T> loadTunables(final Object obj, final double initialOffset) { List<T> handlerList = handlerMap.get(obj); if (handlerList == null) { handlerList = new ArrayList<T>(); handlerMap.put(obj, handlerList); for (final Field field : obj.getClass().getFields()) { if (field.isAnnotationPresent(Tunable.class)) { try { final Tunable tunable = field.getAnnotation(Tunable.class); T handler = getHandler(field, obj, tunable); if (handler instanceof AbstractTunableHandler) ((AbstractTunableHandler)handler).setOffset(initialOffset); if (handler != null) { handlerList.add(handler); } else logOrThrowException("No handler for type: " + field.getType().getName(), null); } catch (final Throwable ex) { logOrThrowException("tunable field intercept failed for " + field.toString(), ex); } } else if (field.isAnnotationPresent(ContainsTunables.class)) { try { Object tunableContainer = field.get(obj); final ContainsTunables containsT = field.getAnnotation(ContainsTunables.class); double offset = containsT.offset(); if (offset == 999.0) offset = 0.0; if (tunableContainer instanceof Task) { List<T>subTaskHandlers = loadTunables(tunableContainer, initialOffset+offset); handlerList.addAll( subTaskHandlers ); handlerMap.put(tunableContainer, new ArrayList<T>()); } else { if ( !handlerMap.containsKey(tunableContainer) ) handlerList.addAll( loadTunables(tunableContainer, initialOffset) ); } } catch (final Throwable ex) { logOrThrowException("ContainsTunables field intercept failed for " + field.toString(), ex); } } } for (final Method method : obj.getClass().getMethods()) { if (method.isAnnotationPresent(Tunable.class)) { try { final Tunable tunable = method.getAnnotation(Tunable.class); final String rootName = validateAndExtractRootName(method); final Method setter = findCompatibleSetter(obj, rootName, method.getReturnType()); final T handler = getHandler(method, setter, obj, tunable); if (handler instanceof AbstractTunableHandler) ((AbstractTunableHandler)handler).setOffset(initialOffset); if (handler == null) { logOrThrowException("Failed to create a handler for " + setter.getName() + "().",null); } else { handlerList.add(handler); } } catch (Throwable t) { logOrThrowException("tunable method intercept failed for " + method.toString(), t); } } else if (method.isAnnotationPresent(ProvidesTitle.class)) { if (!String.class.isAssignableFrom(method.getReturnType())) { throw new IllegalArgumentException(method.getName() + " annotated with @ProvidesTitle must return String."); } else if (method.getParameterTypes().length != 0) { throw new IllegalArgumentException(method.getName() + " annotated with @ProvidesTitle must take 0 arguments."); } else { if (titleProviderMap.containsKey(obj) && initialOffset == 0.0) { throw new IllegalArgumentException("Classes must have at most one @ProvidesTitle annotated method but " + method.getDeclaringClass().getName() + " has more than one."); } titleProviderMap.put(obj, method); } } } Collections.sort(handlerList, new TunableGravityOrderer()); } return handlerList; } }
AbstractTunableInterceptor { private List<T> loadTunables(final Object obj, final double initialOffset) { List<T> handlerList = handlerMap.get(obj); if (handlerList == null) { handlerList = new ArrayList<T>(); handlerMap.put(obj, handlerList); for (final Field field : obj.getClass().getFields()) { if (field.isAnnotationPresent(Tunable.class)) { try { final Tunable tunable = field.getAnnotation(Tunable.class); T handler = getHandler(field, obj, tunable); if (handler instanceof AbstractTunableHandler) ((AbstractTunableHandler)handler).setOffset(initialOffset); if (handler != null) { handlerList.add(handler); } else logOrThrowException("No handler for type: " + field.getType().getName(), null); } catch (final Throwable ex) { logOrThrowException("tunable field intercept failed for " + field.toString(), ex); } } else if (field.isAnnotationPresent(ContainsTunables.class)) { try { Object tunableContainer = field.get(obj); final ContainsTunables containsT = field.getAnnotation(ContainsTunables.class); double offset = containsT.offset(); if (offset == 999.0) offset = 0.0; if (tunableContainer instanceof Task) { List<T>subTaskHandlers = loadTunables(tunableContainer, initialOffset+offset); handlerList.addAll( subTaskHandlers ); handlerMap.put(tunableContainer, new ArrayList<T>()); } else { if ( !handlerMap.containsKey(tunableContainer) ) handlerList.addAll( loadTunables(tunableContainer, initialOffset) ); } } catch (final Throwable ex) { logOrThrowException("ContainsTunables field intercept failed for " + field.toString(), ex); } } } for (final Method method : obj.getClass().getMethods()) { if (method.isAnnotationPresent(Tunable.class)) { try { final Tunable tunable = method.getAnnotation(Tunable.class); final String rootName = validateAndExtractRootName(method); final Method setter = findCompatibleSetter(obj, rootName, method.getReturnType()); final T handler = getHandler(method, setter, obj, tunable); if (handler instanceof AbstractTunableHandler) ((AbstractTunableHandler)handler).setOffset(initialOffset); if (handler == null) { logOrThrowException("Failed to create a handler for " + setter.getName() + "().",null); } else { handlerList.add(handler); } } catch (Throwable t) { logOrThrowException("tunable method intercept failed for " + method.toString(), t); } } else if (method.isAnnotationPresent(ProvidesTitle.class)) { if (!String.class.isAssignableFrom(method.getReturnType())) { throw new IllegalArgumentException(method.getName() + " annotated with @ProvidesTitle must return String."); } else if (method.getParameterTypes().length != 0) { throw new IllegalArgumentException(method.getName() + " annotated with @ProvidesTitle must take 0 arguments."); } else { if (titleProviderMap.containsKey(obj) && initialOffset == 0.0) { throw new IllegalArgumentException("Classes must have at most one @ProvidesTitle annotated method but " + method.getDeclaringClass().getName() + " has more than one."); } titleProviderMap.put(obj, method); } } } Collections.sort(handlerList, new TunableGravityOrderer()); } return handlerList; } AbstractTunableInterceptor(); }
AbstractTunableInterceptor { private List<T> loadTunables(final Object obj, final double initialOffset) { List<T> handlerList = handlerMap.get(obj); if (handlerList == null) { handlerList = new ArrayList<T>(); handlerMap.put(obj, handlerList); for (final Field field : obj.getClass().getFields()) { if (field.isAnnotationPresent(Tunable.class)) { try { final Tunable tunable = field.getAnnotation(Tunable.class); T handler = getHandler(field, obj, tunable); if (handler instanceof AbstractTunableHandler) ((AbstractTunableHandler)handler).setOffset(initialOffset); if (handler != null) { handlerList.add(handler); } else logOrThrowException("No handler for type: " + field.getType().getName(), null); } catch (final Throwable ex) { logOrThrowException("tunable field intercept failed for " + field.toString(), ex); } } else if (field.isAnnotationPresent(ContainsTunables.class)) { try { Object tunableContainer = field.get(obj); final ContainsTunables containsT = field.getAnnotation(ContainsTunables.class); double offset = containsT.offset(); if (offset == 999.0) offset = 0.0; if (tunableContainer instanceof Task) { List<T>subTaskHandlers = loadTunables(tunableContainer, initialOffset+offset); handlerList.addAll( subTaskHandlers ); handlerMap.put(tunableContainer, new ArrayList<T>()); } else { if ( !handlerMap.containsKey(tunableContainer) ) handlerList.addAll( loadTunables(tunableContainer, initialOffset) ); } } catch (final Throwable ex) { logOrThrowException("ContainsTunables field intercept failed for " + field.toString(), ex); } } } for (final Method method : obj.getClass().getMethods()) { if (method.isAnnotationPresent(Tunable.class)) { try { final Tunable tunable = method.getAnnotation(Tunable.class); final String rootName = validateAndExtractRootName(method); final Method setter = findCompatibleSetter(obj, rootName, method.getReturnType()); final T handler = getHandler(method, setter, obj, tunable); if (handler instanceof AbstractTunableHandler) ((AbstractTunableHandler)handler).setOffset(initialOffset); if (handler == null) { logOrThrowException("Failed to create a handler for " + setter.getName() + "().",null); } else { handlerList.add(handler); } } catch (Throwable t) { logOrThrowException("tunable method intercept failed for " + method.toString(), t); } } else if (method.isAnnotationPresent(ProvidesTitle.class)) { if (!String.class.isAssignableFrom(method.getReturnType())) { throw new IllegalArgumentException(method.getName() + " annotated with @ProvidesTitle must return String."); } else if (method.getParameterTypes().length != 0) { throw new IllegalArgumentException(method.getName() + " annotated with @ProvidesTitle must take 0 arguments."); } else { if (titleProviderMap.containsKey(obj) && initialOffset == 0.0) { throw new IllegalArgumentException("Classes must have at most one @ProvidesTitle annotated method but " + method.getDeclaringClass().getName() + " has more than one."); } titleProviderMap.put(obj, method); } } } Collections.sort(handlerList, new TunableGravityOrderer()); } return handlerList; } AbstractTunableInterceptor(); final List<T> getHandlers(final Object o); boolean hasTunables(final Object o); void addTunableHandlerFactory(TunableHandlerFactory<T> thf, Map properties); void removeTunableHandlerFactory(TunableHandlerFactory<T> thf, Map properties); }
AbstractTunableInterceptor { private List<T> loadTunables(final Object obj, final double initialOffset) { List<T> handlerList = handlerMap.get(obj); if (handlerList == null) { handlerList = new ArrayList<T>(); handlerMap.put(obj, handlerList); for (final Field field : obj.getClass().getFields()) { if (field.isAnnotationPresent(Tunable.class)) { try { final Tunable tunable = field.getAnnotation(Tunable.class); T handler = getHandler(field, obj, tunable); if (handler instanceof AbstractTunableHandler) ((AbstractTunableHandler)handler).setOffset(initialOffset); if (handler != null) { handlerList.add(handler); } else logOrThrowException("No handler for type: " + field.getType().getName(), null); } catch (final Throwable ex) { logOrThrowException("tunable field intercept failed for " + field.toString(), ex); } } else if (field.isAnnotationPresent(ContainsTunables.class)) { try { Object tunableContainer = field.get(obj); final ContainsTunables containsT = field.getAnnotation(ContainsTunables.class); double offset = containsT.offset(); if (offset == 999.0) offset = 0.0; if (tunableContainer instanceof Task) { List<T>subTaskHandlers = loadTunables(tunableContainer, initialOffset+offset); handlerList.addAll( subTaskHandlers ); handlerMap.put(tunableContainer, new ArrayList<T>()); } else { if ( !handlerMap.containsKey(tunableContainer) ) handlerList.addAll( loadTunables(tunableContainer, initialOffset) ); } } catch (final Throwable ex) { logOrThrowException("ContainsTunables field intercept failed for " + field.toString(), ex); } } } for (final Method method : obj.getClass().getMethods()) { if (method.isAnnotationPresent(Tunable.class)) { try { final Tunable tunable = method.getAnnotation(Tunable.class); final String rootName = validateAndExtractRootName(method); final Method setter = findCompatibleSetter(obj, rootName, method.getReturnType()); final T handler = getHandler(method, setter, obj, tunable); if (handler instanceof AbstractTunableHandler) ((AbstractTunableHandler)handler).setOffset(initialOffset); if (handler == null) { logOrThrowException("Failed to create a handler for " + setter.getName() + "().",null); } else { handlerList.add(handler); } } catch (Throwable t) { logOrThrowException("tunable method intercept failed for " + method.toString(), t); } } else if (method.isAnnotationPresent(ProvidesTitle.class)) { if (!String.class.isAssignableFrom(method.getReturnType())) { throw new IllegalArgumentException(method.getName() + " annotated with @ProvidesTitle must return String."); } else if (method.getParameterTypes().length != 0) { throw new IllegalArgumentException(method.getName() + " annotated with @ProvidesTitle must take 0 arguments."); } else { if (titleProviderMap.containsKey(obj) && initialOffset == 0.0) { throw new IllegalArgumentException("Classes must have at most one @ProvidesTitle annotated method but " + method.getDeclaringClass().getName() + " has more than one."); } titleProviderMap.put(obj, method); } } } Collections.sort(handlerList, new TunableGravityOrderer()); } return handlerList; } AbstractTunableInterceptor(); final List<T> getHandlers(final Object o); boolean hasTunables(final Object o); void addTunableHandlerFactory(TunableHandlerFactory<T> thf, Map properties); void removeTunableHandlerFactory(TunableHandlerFactory<T> thf, Map properties);  }