RLPark 1.0.0
Reinforcement Learning Framework in Java

Parsers.java

Go to the documentation of this file.
00001 package zephyr.plugin.core.api.internal.parsing;
00002 
00003 import java.lang.reflect.InvocationTargetException;
00004 import java.lang.reflect.Method;
00005 import java.util.LinkedHashMap;
00006 import java.util.Map;
00007 
00008 import zephyr.plugin.core.api.monitoring.abstracts.LabeledCollection;
00009 import zephyr.plugin.core.api.monitoring.annotations.LabelProvider;
00010 
00011 public class Parsers {
00012 
00013   private static void addLabelMaps(Map<String, LabeledCollection> labelsMap, final Method method,
00014       final Object container) {
00015     LabeledCollection labeledElement = new LabeledCollection() {
00016       @Override
00017       public String label(int index) {
00018         try {
00019           return (String) method.invoke(container, index);
00020         } catch (IllegalArgumentException e) {
00021           e.printStackTrace();
00022         } catch (IllegalAccessException e) {
00023           e.printStackTrace();
00024         } catch (InvocationTargetException e) {
00025           e.printStackTrace();
00026         }
00027         return "error";
00028       }
00029     };
00030     LabelProvider annotation = method.getAnnotation(LabelProvider.class);
00031     for (String id : annotation.ids())
00032       labelsMap.put(id, labeledElement);
00033   }
00034 
00035   public static Map<String, LabeledCollection> buildLabelMaps(Object container) {
00036     Class<?> objectClass = container.getClass();
00037     Map<String, LabeledCollection> labelsMaps = new LinkedHashMap<String, LabeledCollection>();
00038     while (objectClass != null) {
00039       for (Method method : objectClass.getDeclaredMethods()) {
00040         if (!method.isAnnotationPresent(LabelProvider.class))
00041           continue;
00042         method.setAccessible(true);
00043         addLabelMaps(labelsMaps, method, container);
00044       }
00045       objectClass = objectClass.getSuperclass();
00046     }
00047     return labelsMaps;
00048   }
00049 
00050 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark