/** * Construct an empty attribute with no values * * @param name name of attribute * @param dataType type of Attribute. */ public Attribute(String name, DataType dataType, boolean isUnsigned) { this(name); this.dataType = dataType == DataType.CHAR ? DataType.STRING : dataType; this.nelems = 0; this.isUnsigned = isUnsigned; setImmutable(true); }
/** * Copy constructor * * @param name name of new Attribute * @param from copy value from here. */ public Attribute(String name, Attribute from) { super(name); if (name == null) throw new IllegalArgumentException("Trying to set name to null on "+this); this.dataType = from.dataType; this.nelems = from.nelems; this.svalue = from.svalue; this.values = from.values; this.isUnsigned = from.isUnsigned; setImmutable(true); }
/** * Create a String-valued Attribute. * * @param name name of Attribute * @param val value of Attribute */ public Attribute(String name, String val) { super(name); if (name == null) throw new IllegalArgumentException("Trying to set name to null on "+this); setStringValue(val); setImmutable(true); }
/** * Construct attribute with Array of values. * * @param name name of attribute * @param values array of values. */ public Attribute(String name, Array values) { this(name); setValues(values); setImmutable(true); }
/** * Create a String-valued Attribute. * * @param name name of Attribute * @param val value of Attribute */ public Attribute(String name, String val) { super(name); setDataType(DataType.STRING); if (name == null) throw new IllegalArgumentException("Trying to set name to null on " + this); setStringValue(val); setImmutable(); }
/** * Copy constructor * * @param name name of new Attribute * @param from copy value from here. */ public Attribute(String name, Attribute from) { super(name); if (name == null) throw new IllegalArgumentException("Trying to set name to null on " + this); setDataType(from.dataType); setEnumType(from.enumtype); this.nelems = from.nelems; this.svalue = from.svalue; this.values = from.values; setImmutable(); }
/** * Construct attribute with Array of values. * * @param name name of attribute * @param values array of values. */ public Attribute(String name, Array values) { this(name,values.getDataType()); setValues(values); setImmutable(); }
/** * Construct attribute with list of String or Number values. * The list determines the attribute type * @param name name of attribute * @param values list of values. must be String or Number, must all be the same type, and have at least 1 member * @param isUnsigned */ public Attribute(String name, List values, boolean isUnsigned) { this(name); if(values == null || values.size() == 0) throw new IllegalArgumentException("Cannot determine attribute's type"); Class c = values.get(0).getClass(); setDataType(DataType.getType(c, isUnsigned)); setValues(values); setImmutable(); }
public Attribute(String name, Number val, boolean isUnsigned) { super(name); if (name == null) throw new IllegalArgumentException("Trying to set name to null on "+this); int[] shape = new int[1]; shape[0] = 1; DataType dt = DataType.getType(val.getClass()); Array vala = Array.factory(dt.getPrimitiveClassType(), shape); Index ima = vala.getIndex(); vala.setDouble(ima.set0(0), val.doubleValue()); setValues(vala); this.isUnsigned = isUnsigned; if (isUnsigned) vala.setUnsigned(true); setImmutable(true); }
public Attribute(String name, Number val, boolean isUnsigned) { super(name); if (name == null) throw new IllegalArgumentException("Trying to set name to null on " + this); int[] shape = new int[1]; shape[0] = 1; DataType dt = DataType.getType(val.getClass(), isUnsigned); setDataType(dt); Array vala = Array.factory(dt, shape); Index ima = vala.getIndex(); vala.setObject(ima.set0(0), val); setValues(vala); setImmutable(); }
/** * A copy constructor using a ucar.unidata.util.Parameter. * Need to do this so ucar.unidata.geoloc package doesnt depend on ucar.nc2 library * * @param param copy info from here. */ public Attribute(ucar.unidata.util.Parameter param) { this(param.getName()); if (param.isString()) { setStringValue(param.getStringValue()); } else { double[] values = param.getNumericValues(); int n = values.length; Array vala = Array.factory(DataType.DOUBLE, new int[]{n}, values); setValues(vala); } setImmutable(); }
/** * A copy constructor using a ucar.unidata.util.Parameter. * Need to do this so ucar.unidata.geoloc package doesnt depend on ucar.nc2 library * * @param param copy info from here. */ public Attribute(ucar.unidata.util.Parameter param) { this(param.getName()); if (param.isString()) { setStringValue(param.getStringValue()); } else { double[] values = param.getNumericValues(); int n = values.length; Array vala = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[]{n}, values); setValues(vala); } setImmutable(true); }