RLPark 1.0.0
Reinforcement Learning Framework in Java

ObjectCollectionParser.java

Go to the documentation of this file.
00001 package zephyr.plugin.core.api.internal.codeparser.parsers;
00002 
00003 import java.util.Collection;
00004 
00005 
00006 public class ObjectCollectionParser extends AbstractCollectionParser<Collection<?>> {
00007   private Object[] elements;
00008 
00009   @Override
00010   public boolean canParse(Object fieldValue) {
00011     if (!(fieldValue instanceof Collection))
00012       return false;
00013     Collection<?> collection = (Collection<?>) fieldValue;
00014     if (collection.size() == 0)
00015       return false;
00016     Object firstElement = collection.iterator().next();
00017     if (firstElement == null)
00018       return false;
00019     return !firstElement.getClass().isPrimitive();
00020   }
00021 
00022   @Override
00023   protected int nbChildren(Collection<?> container) {
00024     return container.size();
00025   }
00026 
00027   @Override
00028   protected void beginChildrenParse(Collection<?> container) {
00029     elements = container.toArray();
00030   }
00031 
00032   @Override
00033   protected void endChildrenParse() {
00034     elements = null;
00035   }
00036 
00037 
00038   @Override
00039   protected Object getElement(Collection<?> container, int index) {
00040     return elements[index];
00041   }
00042 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark