@Nullable public StringValue getStringValue(int tagType) { Object o = getObject(tagType); if (o instanceof StringValue) return (StringValue)o; return null; }
/** Returns the specified tag's value as an array of Rational. If the value is unset or cannot be converted, <code>null</code> is returned. */ @Nullable public Rational[] getRationalArray(int tagType) { Object o = getObject(tagType); if (o == null) return null; if (o instanceof Rational[]) return (Rational[])o; return null; }
/** Returns the specified tag's value as a float. If the tag is not set or cannot be converted, <code>null</code> is returned. */ @Nullable public Float getFloatObject(int tagType) { Object o = getObject(tagType); if (o == null) return null; if (o instanceof String || o instanceof StringValue) { try { return Float.parseFloat(o.toString()); } catch (NumberFormatException nfe) { return null; } } if (o instanceof Number) return ((Number)o).floatValue(); return null; }
/** * Gets the specified tag's value as a StringValue array, if possible. * Only succeeds if the tag is set as StringValue[], or StringValue. * * @param tagType the tag identifier * @return the tag's value as an array of StringValues. If the value is unset or cannot be converted, <code>null</code> is returned. */ @Nullable public StringValue[] getStringValueArray(int tagType) { Object o = getObject(tagType); if (o == null) return null; if (o instanceof StringValue[]) return (StringValue[])o; if (o instanceof StringValue) return new StringValue[] {(StringValue) o}; return null; }
/** Returns the specified tag's value as a Double. If the tag is not set or cannot be converted, <code>null</code> is returned. */ @Nullable public Double getDoubleObject(int tagType) { Object o = getObject(tagType); if (o == null) return null; if (o instanceof String || o instanceof StringValue) { try { return Double.parseDouble(o.toString()); } catch (NumberFormatException nfe) { return null; } } if (o instanceof Number) return ((Number)o).doubleValue(); return null; }
/** Returns the specified tag's value as a boolean. If the tag is not set or cannot be converted, <code>null</code> is returned. */ @Nullable @SuppressWarnings(value = "NP_BOOLEAN_RETURN_NULL", justification = "keep API interface consistent") public Boolean getBooleanObject(int tagType) { Object o = getObject(tagType); if (o == null) return null; if (o instanceof Boolean) return (Boolean)o; if (o instanceof String || o instanceof StringValue) { try { return Boolean.getBoolean(o.toString()); } catch (NumberFormatException nfe) { return null; } } if (o instanceof Number) return (((Number)o).doubleValue() != 0); return null; }
public String getDescription(int tagType) Object object = _directory.getObject(tagType);
@Nullable public String getReferenceBlackWhiteDescription() { // For some reason, sometimes this is read as a long[] and // getIntArray isn't able to deal with it int[] ints = _directory.getIntArray(TAG_REFERENCE_BLACK_WHITE); if (ints==null || ints.length < 6) { Object o = _directory.getObject(TAG_REFERENCE_BLACK_WHITE); if (o != null && (o instanceof long[])) { long[] longs = (long[])o; if (longs.length < 6) return null; ints = new int[longs.length]; for (int i = 0; i < longs.length; i++) ints[i] = (int)longs[i]; } else return null; } int blackR = ints[0]; int whiteR = ints[1]; int blackG = ints[2]; int whiteG = ints[3]; int blackB = ints[4]; int whiteB = ints[5]; return String.format("[%d,%d,%d] [%d,%d,%d]", blackR, blackG, blackB, whiteR, whiteG, whiteB); }
public Long getLongObject(int tagType) Object o = getObject(tagType); if (o == null) return null;
/** Returns the specified tag's value as a long, if possible. */ public long getLong(int tagType) throws MetadataException { Long value = getLongObject(tagType); if (value != null) return value; Object o = getObject(tagType); if (o == null) throw new MetadataException("Tag '" + getTagName(tagType) + "' has not been set -- check using containsTag() first"); throw new MetadataException("Tag '" + tagType + "' cannot be converted to a long. It is of type '" + o.getClass() + "'."); }
public Integer getInteger(int tagType) Object o = getObject(tagType);
/** Returns the specified tag's value as a boolean, if possible. */ public boolean getBoolean(int tagType) throws MetadataException { Boolean value = getBooleanObject(tagType); if (value != null) return value; Object o = getObject(tagType); if (o == null) throw new MetadataException("Tag '" + getTagName(tagType) + "' has not been set -- check using containsTag() first"); throw new MetadataException("Tag '" + tagType + "' cannot be converted to a boolean. It is of type '" + o.getClass() + "'."); }
/** Returns the specified tag's value as a double, if possible. */ public double getDouble(int tagType) throws MetadataException { Double value = getDoubleObject(tagType); if (value!=null) return value; Object o = getObject(tagType); if (o == null) throw new MetadataException("Tag '" + getTagName(tagType) + "' has not been set -- check using containsTag() first"); throw new MetadataException("Tag '" + tagType + "' cannot be converted to a double. It is of type '" + o.getClass() + "'."); } /** Returns the specified tag's value as a Double. If the tag is not set or cannot be converted, <code>null</code> is returned. */
/** Returns the specified tag's value as a float, if possible. */ public float getFloat(int tagType) throws MetadataException { Float value = getFloatObject(tagType); if (value!=null) return value; Object o = getObject(tagType); if (o == null) throw new MetadataException("Tag '" + getTagName(tagType) + "' has not been set -- check using containsTag() first"); throw new MetadataException("Tag '" + tagType + "' cannot be converted to a float. It is of type '" + o.getClass() + "'."); }
public int[] getIntArray(int tagType) Object o = getObject(tagType); if (o == null) return null;
public String getString(int tagType) Object o = getObject(tagType); if (o == null) return null;
public byte[] getByteArray(int tagType) Object o = getObject(tagType); if (o == null) { return null;
/** Returns the specified tag's value as a Rational. If the value is unset or cannot be converted, <code>null</code> is returned. */ @Nullable public Rational getRational(int tagType) { Object o = getObject(tagType); if (o == null) return null; if (o instanceof Rational) return (Rational)o; if (o instanceof Integer) return new Rational((Integer)o, 1); if (o instanceof Long) return new Rational((Long)o, 1); // NOTE not doing conversions for real number types return null; }
public String[] getStringArray(int tagType) Object o = getObject(tagType); if (o == null) return null;
/** * Returns the specified tag's value as an int, if possible. Every attempt to represent the tag's value as an int * is taken. Here is a list of the action taken depending upon the tag's original type: * <ul> * <li> int - Return unchanged. * <li> Number - Return an int value (real numbers are truncated). * <li> Rational - Truncate any fractional part and returns remaining int. * <li> String - Attempt to parse string as an int. If this fails, convert the char[] to an int (using shifts and OR). * <li> Rational[] - Return int value of first item in array. * <li> byte[] - Return int value of first item in array. * <li> int[] - Return int value of first item in array. * </ul> * * @throws MetadataException if no value exists for tagType or if it cannot be converted to an int. */ public int getInt(int tagType) throws MetadataException { Integer integer = getInteger(tagType); if (integer!=null) return integer; Object o = getObject(tagType); if (o == null) throw new MetadataException("Tag '" + getTagName(tagType) + "' has not been set -- check using containsTag() first"); throw new MetadataException("Tag '" + tagType + "' cannot be converted to int. It is of type '" + o.getClass() + "'."); }