1 19 20 21 package org.apache.cayenne.jpa.map; 22 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 26 31 class EnumList extends ArrayList { 34 35 private Class enumClass; 36 37 EnumList(Class enumClass, int capacity) { 38 super(capacity); 39 this.enumClass = enumClass; 40 } 41 42 private Object convertValue(Object value) { 43 if (value instanceof String ) { 44 value = Enum.valueOf(enumClass, value.toString()); 45 } 46 47 return value; 48 } 49 50 private Collection convertValues(Collection values) { 51 if(values != null && !values.isEmpty()) { 52 Collection converted = new ArrayList (values.size()); 53 for(Object value : values) { 54 converted.add(convertValue(value)); 55 } 56 57 return converted; 58 } 59 else { 60 return values; 61 } 62 } 63 64 @Override 65 public void add(int index, Object element) { 66 super.add(index, convertValue(element)); 67 } 68 69 @Override 70 public boolean add(Object o) { 71 return super.add(convertValue(o)); 72 } 73 74 @Override 75 public boolean addAll(Collection c) { 76 return super.addAll(convertValues(c)); 77 } 78 79 @Override 80 public boolean addAll(int index, Collection c) { 81 return super.addAll(index, convertValues(c)); 82 } 83 } 84 | Popular Tags |