Package org.renjin.invoke.reflection.converters

Source Code of org.renjin.invoke.reflection.converters.BoxedScalarConverter

package org.renjin.invoke.reflection.converters;

import org.renjin.eval.EvalException;
import org.renjin.sexp.AtomicVector;
import org.renjin.sexp.Null;
import org.renjin.sexp.SEXP;
import org.renjin.sexp.Vector;


public abstract class BoxedScalarConverter<T> implements Converter<T>  {
 
  @Override
  public final Object convertToJava(SEXP value) {
    if(!(value instanceof AtomicVector)) {
      throw new EvalException("Cannot convert '%s' to boolean", value.getTypeName());
    }
    Vector vector = (Vector)value;
    if(vector == Null.INSTANCE || vector.isElementNA(0)) {
      return null;
    }
    return getFirstElement((Vector)value);
  }
 
  protected abstract Object getFirstElement(Vector value);

}
TOP

Related Classes of org.renjin.invoke.reflection.converters.BoxedScalarConverter

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.