/** * Get the value of property {@code name} as a Long. * * @param name property name. * @param defaultValue default value. * @return property value as a Long, or {@code defaultValue} if * the property does not exist. * @throws NumberFormatException if value does not represent a Long. */ public Long getLong(String name, Long defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } return Long.parseLong(val); }
/** * Get the value of property {@code name} as a file object. * * @param name property name. * @param defaultValue default value. * @return property value as a {@code File}, or {@code defaultValue} if * the property does not exist. */ public File getFile(String name, File defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } return new File(val); }
/** * Get the value of property {@code name} as a file object. * * @param name property name. * @param defaultValue default value. * @return property value as a {@code File}, or {@code defaultValue} if * the property does not exist. */ public File getFile(String name, File defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } return new File(val); }
/** * Get the value of property {@code name} as an Integer. * * @param name property name. * @param defaultValue default value. * @return property value as an Integer, or {@code defaultValue} if * the property does not exist. * @throws NumberFormatException if value does not represent an Integer. */ public Integer getInteger(String name, Integer defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } return Integer.parseInt(val); }
/** * Get the value of property {@code name} as an Integer. * * @param name property name. * @param defaultValue default value. * @return property value as an Integer, or {@code defaultValue} if * the property does not exist. * @throws NumberFormatException if value does not represent an Integer. */ public Integer getInteger(String name, Integer defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } return Integer.parseInt(val); }
/** * Get the value of property {@code name} as a Long. * * @param name property name. * @param defaultValue default value. * @return property value as a Long, or {@code defaultValue} if * the property does not exist. * @throws NumberFormatException if value does not represent a Long. */ public Long getLong(String name, Long defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } return Long.parseLong(val); }
/** * Get the value of property {@code name} as a Double. * * @param name property name. * @param defaultValue default value. * @return property value as a Double, or {@code defaultValue} if * the property does not exist. * @throws NumberFormatException if value does not represent a Double. */ public Double getDouble(String name, Double defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } return Double.parseDouble(val); }
/** * Get the value of property {@code name} as a Float. * * @param name property name. * @param defaultValue default value. * @return property value as a Float, or {@code defaultValue} if * the property does not exist. * @throws NumberFormatException if value does not represent a Float. */ public Float getFloat(String name, Float defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } return Float.parseFloat(val); }
/** * Get the value of property {@code name} as a Float. * * @param name property name. * @param defaultValue default value. * @return property value as a Float, or {@code defaultValue} if * the property does not exist. * @throws NumberFormatException if value does not represent a Float. */ public Float getFloat(String name, Float defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } return Float.parseFloat(val); }
/** * Get the value of property {@code name} as a class. * * @param name property name. * @param defaultValue default value. * @return property value as a class, or {@code defaultValue} if * the property does not exist. * @throws ClassNotFoundException if value does not map to an existing class. */ public Class<?> getClass(String name, Class<?> defaultValue) throws ClassNotFoundException { final String val = get(name); if (null == val) { return defaultValue; } return Class.forName(val); }
/** * Get the value of property {@code name} as a Double. * * @param name property name. * @param defaultValue default value. * @return property value as a Double, or {@code defaultValue} if * the property does not exist. * @throws NumberFormatException if value does not represent a Double. */ public Double getDouble(String name, Double defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } return Double.parseDouble(val); }
/** * Get the value of property {@code name} as a class. * * @param name property name. * @param defaultValue default value. * @return property value as a class, or {@code defaultValue} if * the property does not exist. * @throws ClassNotFoundException if value does not map to an existing class. */ public Class<?> getClass(String name, Class<?> defaultValue) throws ClassNotFoundException { final String val = get(name); if (null == val) { return defaultValue; } return Class.forName(val); }
public String getCompanion() { MetadataOptions options = getMetadataOptions(); if (options instanceof DynamicMetadataOptions) { return ((DynamicMetadataOptions) options).get(COMPANION_KEY); } return null; }
public String getCompanion() { MetadataOptions options = getMetadataOptions(); if (options instanceof DynamicMetadataOptions) { return ((DynamicMetadataOptions) options).get(COMPANION_KEY); } return null; }
/** * Get the value of property {@code name} as an enumerated type. * * @param name property name. * @param defaultValue default value. * @return property value as an enumerated type, or {@code * defaultValue} if the property does not exist. * @throws IllegalArgumentException if mapping is illegal for the type * provided */ public <T extends Enum<T>> T getEnum(String name, T defaultValue) { if (null == defaultValue) { throw new IllegalArgumentException("default value can't be null"); } final String val = get(name); if (null == val) { return defaultValue; } return Enum.valueOf(defaultValue.getDeclaringClass(), val); }
/** * Get the value of property {@code name} as an enumerated type. * * @param name property name. * @param defaultValue default value. * @return property value as an enumerated type, or {@code * defaultValue} if the property does not exist. * @throws IllegalArgumentException if mapping is illegal for the type * provided */ public <T extends Enum<T>> T getEnum(String name, T defaultValue) { if (null == defaultValue) { throw new IllegalArgumentException("default value can't be null"); } final String val = get(name); if (null == val) { return defaultValue; } return Enum.valueOf(defaultValue.getDeclaringClass(), val); }
/** * Get the value of property {@code name} as a Boolean. * * @param name property name. * @param defaultValue default value. * @return property value as a Boolean, or {@code defaultValue} if * the property does not exist. * @throws IllegalArgumentException if value does not represent a Boolean. */ public Boolean getBoolean(String name, Boolean defaultValue) { final String val = get(name); if (null == val) { return defaultValue; } if (val.equalsIgnoreCase("true")) { return true; } if (val.equalsIgnoreCase("false")) { return false; } throw new IllegalArgumentException(val + "does not represent a boolean"); }
@Test public void testString() { assertNull(opt.get(KEY)); assertNull(opt.get(KEY), null); assertEquals(opt.get(KEY, "default"), "default"); opt.set(KEY, "v"); assertEquals(opt.get(KEY), "v"); assertEquals(opt.get(KEY, null), "v"); assertEquals(opt.get(KEY, "default"), "v"); opt.set(KEY, null); assertNull(opt.get(KEY)); assertNull(opt.get(KEY), null); assertEquals(opt.get(KEY, "default"), "default"); }
public static void checkKV(IFormatReader r, String k, String expv) { MetadataOptions rOpt = r.getMetadataOptions(); assertTrue(rOpt instanceof DynamicMetadataOptions); String v = ((DynamicMetadataOptions) rOpt).get(k); assertNotNull(v); assertEquals(v, expv); }
@Test public void testOptionsExplicit() throws Exception { DynamicMetadataOptions opt = new DynamicMetadataOptions(); opt.set(KEY, VALUE); ImageReader reader = new ImageReader(); reader.setMetadataOptions(opt); reader.setId("test.fake"); MetadataOptions rOpt = reader.getReader().getMetadataOptions(); assertTrue(rOpt instanceof DynamicMetadataOptions); String v = ((DynamicMetadataOptions) rOpt).get(KEY); assertNotNull(v); assertEquals(v, VALUE); reader.close(); }