/** * Returns the integer value of the attribute with the given name. <p>The given default value is returned if an * attribute with the given name could not be found in this node. * * @param name the attribute name * @param defaultValue the default value * * @return the attribute value as integer. * * @throws NumberFormatException if the attribute type is ASCII but cannot be converted to a number */ public int getAttributeInt(String name, int defaultValue) { final MetadataAttribute attribute = getAttribute(name); if (attribute == null) { return defaultValue; } if (attribute.getDataType() == ProductData.TYPE_ASCII) { return Integer.parseInt(attribute.getData().getElemString()); } return attribute.getData().getElemInt(); }
/** * Returns the double value of the attribute with the given name. <p>An Exception is thrown if an * attribute with the given name could not be found in this node. * * @param name the attribute name * * @return the attribute value as double. * * @throws NumberFormatException if the attribute type is ASCII but cannot be converted to a number * @throws IllegalArgumentException if an attribute with the given name could not be found */ public double getAttributeDouble(String name) { final MetadataAttribute attribute = getAttribute(name); if (attribute == null) { throw new IllegalArgumentException(getAttributeNotFoundMessage(name)); } if (attribute.getDataType() == ProductData.TYPE_ASCII) { return Double.parseDouble(attribute.getData().getElemString()); } return attribute.getData().getElemDouble(); }
/** * Returns the integer value of the attribute with the given name. <p>An Exception is thrown if an * attribute with the given name could not be found in this node. * * @param name the attribute name * * @return the attribute value as integer. * * @throws NumberFormatException if the attribute type is ASCII but cannot be converted to a number * @throws IllegalArgumentException if an attribute with the given name could not be found */ public int getAttributeInt(String name) { final MetadataAttribute attribute = getAttribute(name); if (attribute == null) { throw new IllegalArgumentException(getAttributeNotFoundMessage(name)); } if (attribute.getDataType() == ProductData.TYPE_ASCII) { return Integer.parseInt(attribute.getData().getElemString()); } return attribute.getData().getElemInt(); }
/** * Returns the double value of the attribute with the given name. <p>The given default value is returned if an * attribute with the given name could not be found in this node. * * @param name the attribute name * @param defaultValue the default value * * @return the attribute value as double. * * @throws NumberFormatException if the attribute type is ASCII but cannot be converted to a number */ public double getAttributeDouble(String name, double defaultValue) { final MetadataAttribute attribute = getAttribute(name); if (attribute == null) { return defaultValue; } if (attribute.getDataType() == ProductData.TYPE_ASCII) { return Double.parseDouble(attribute.getData().getElemString()); } return attribute.getData().getElemDouble(); }
public static void assertIntAttribute(MetadataElement elem, String attributeName, int expectedValue) { final MetadataAttribute attribute = elem.getAttribute(attributeName); assertNotNull(attribute); assertEquals(ProductData.TYPE_INT32, attribute.getDataType()); assertEquals(1, attribute.getNumDataElems()); assertEquals(expectedValue, attribute.getData().getElemInt()); }
private void writeMetadataAttribute(int locationID, MetadataAttribute attribute) throws IOException { int productDataType = attribute.getDataType(); if (attribute.getData() instanceof ProductData.ASCII || attribute.getData() instanceof ProductData.UTC) {