Java Code Examples for ucar.ma2.DataType#isIntegral()
The following examples show how to use
ucar.ma2.DataType#isIntegral() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardFields.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void extract(StructureData sdata) { StructureMembers sm = sdata.getStructureMembers(); for (Field fld : map.values()) { StructureMembers.Member m = sm.findMember(fld.memberName); DataType dtype = m.getDataType(); if (dtype.isString()) fld.valueS = sdata.getScalarString(m).trim(); else if (dtype.isIntegral()) { fld.value = sdata.convertScalarInt(m); fld.valueD = fld.value; } else if (dtype.isNumeric()) fld.valueD = sdata.convertScalarDouble(m); } }
Example 2
Source File: NcMLReader.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Parse the values element * * @param s JDOM element to parse * @return Array with parsed values * @throws IllegalArgumentException if string values not parsable to specified data type */ public static ucar.ma2.Array readAttributeValues(Element s) throws IllegalArgumentException { String valString = s.getAttributeValue("value"); // can also be element text if (valString == null) { valString = s.getTextNormalize(); } // no value specified hmm technically this is not illegal !! if (valString == null) throw new IllegalArgumentException("No value specified"); String type = s.getAttributeValue("type"); DataType dtype = (type == null) ? DataType.STRING : DataType.getType(type); if (dtype == DataType.CHAR) dtype = DataType.STRING; // backwards compatibility with deprecated isUnsigned attribute String unS = s.getAttributeValue("isUnsigned"); boolean isUnsignedSet = "true".equalsIgnoreCase(unS); if (isUnsignedSet && dtype.isIntegral() && !dtype.isUnsigned()) { dtype = dtype.withSignedness(DataType.Signedness.UNSIGNED); } String sep = s.getAttributeValue("separator"); if ((sep == null) && (dtype == DataType.STRING)) { List<String> list = new ArrayList<>(); list.add(valString); return Array.makeArray(dtype, list); } if (sep == null) sep = " "; // default whitespace separated List<String> stringValues = new ArrayList<>(); StringTokenizer tokn = new StringTokenizer(valString, sep); while (tokn.hasMoreTokens()) stringValues.add(tokn.nextToken()); return Array.makeArray(dtype, stringValues); }
Example 3
Source File: NcMLReaderNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Parse the values element * * @param s JDOM element to parse * @return Array with parsed values * @throws IllegalArgumentException if string values not parsable to specified data type */ private static ucar.ma2.Array readAttributeValues(Element s) throws IllegalArgumentException { String valString = s.getAttributeValue("value"); // can also be element text if (valString == null) { valString = s.getTextNormalize(); } // no value specified hmm technically this is not illegal !! if (valString == null) { throw new IllegalArgumentException("No value specified"); } String type = s.getAttributeValue("type"); DataType dtype = (type == null) ? DataType.STRING : DataType.getType(type); if (dtype == DataType.CHAR) { dtype = DataType.STRING; } // backwards compatibility with deprecated isUnsigned attribute String unS = s.getAttributeValue("isUnsigned"); boolean isUnsignedSet = "true".equalsIgnoreCase(unS); if (isUnsignedSet && dtype.isIntegral() && !dtype.isUnsigned()) { dtype = dtype.withSignedness(DataType.Signedness.UNSIGNED); } String sep = s.getAttributeValue("separator"); if ((sep == null) && (dtype == DataType.STRING)) { List<String> list = new ArrayList<>(); list.add(valString); return Array.makeArray(dtype, list); } if (sep == null) { sep = " "; // default whitespace separated } List<String> stringValues = new ArrayList<>(); StringTokenizer tokn = new StringTokenizer(valString, sep); while (tokn.hasMoreTokens()) { stringValues.add(tokn.nextToken()); } return Array.makeArray(dtype, stringValues); }