1 package jfun.yan; 2 3 import jfun.util.Misc; 4 import jfun.yan.element.AnyArrayStore; 5 import jfun.yan.element.ArrayStore; 6 import jfun.yan.element.ElementStore; 7 import jfun.yan.util.ReflectionUtil; 8 9 final class ArrayStoreBinder<T> extends StoreBinder{ 10 private final Class etype; 11 12 public Class getElementType() { 13 return etype; 14 } 15 public ArrayStoreBinder(Creator<T>[] creators, Class etype) { 16 super(creators); 17 this.etype = etype; 18 } 19 public ElementStore<T> toStore(Object v){ 20 if(v instanceof Object []){ 21 return new ArrayStore((Object [])v); 22 } 23 else{ 24 return new AnyArrayStore<T>(v); 25 } 26 } 27 public void checkElement(int i, Class ctype){ 28 if(etype!=null && !ReflectionUtil.isCompatible(etype, ctype)){ 29 throw new TypeMismatchException(etype, ctype, 30 "type mismatch: the #" 31 +i+" element is of "+Misc.getTypeName(ctype) 32 +", while "+Misc.getTypeName(etype) 33 +" is expected."); 34 } 35 } 36 public String toString(){ 37 return "ArrayStoreBinder"; 38 } 39 } 40 | Popular Tags |