Package jfun.yan

Source Code of jfun.yan.ArrayStoreBinder

package jfun.yan;

import jfun.util.Misc;
import jfun.yan.element.AnyArrayStore;
import jfun.yan.element.ArrayStore;
import jfun.yan.element.ElementStore;
import jfun.yan.util.ReflectionUtil;

final class ArrayStoreBinder<T> extends StoreBinder{
  private final Class etype;
 
  public Class getElementType() {
    return etype;
  }
  public ArrayStoreBinder(Creator<T>[] creators, Class etype) {
    super(creators);
    this.etype = etype;
  }
  public ElementStore<T> toStore(Object v){
    if(v instanceof Object[]){
      return new ArrayStore((Object[])v);
    }
    else{
      return new AnyArrayStore<T>(v);
    }
  }
  public void checkElement(int i, Class ctype){
    if(etype!=null && !ReflectionUtil.isCompatible(etype, ctype)){
      throw new TypeMismatchException(etype, ctype,
          "type mismatch: the #"
          +i+" element is of "+Misc.getTypeName(ctype)
          +", while "+Misc.getTypeName(etype)
          +" is expected.");
    }
  }
  public String toString(){
    return "ArrayStoreBinder";
  }
}
TOP

Related Classes of jfun.yan.ArrayStoreBinder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.