/** Get property as a string and split on ",". */ public String[] getPropertySplit(String key) { String str = getProperty(key) ; if ( str == null ) return null ; return str.split(",") ; }
/** Get the property value and parse as an integer or return default value. */ public int getPropertyAsInteger(String key, int defaultValue) { String x = getProperty(key) ; if ( x == null ) return defaultValue ; return Integer.parseInt(x) ; }
/** Get property as a string and split on ",", using the default string if not present in the MetaFile. */ public String[] getPropertySplit(String key, String defaultString) { String str = getProperty(key, defaultString) ; return str.split(",") ; }
/** Test whether a property has a value. Null tests equal to not present. */ public boolean propertyEquals(String key, String value) { return Objects.equals(getProperty(key), value) ; }
/** Get property or the default value - also set the default value if not present */ public String getOrSetDefault(String key, String expected) { String x = getProperty(key) ; if ( x == null ) { setProperty(key, expected) ; x = expected ; } return x ; }
/** Check property has the value given - throw exception if not. */ public void checkMetadata(String key, String expected) { String value = getProperty(key) ; if ( ! Objects.equals(value, value) ) inconsistent(key, value, expected) ; }
/** Check property is an expected value or set if missing */ public void checkOrSetMetadata(String key, String expected) { String x = getProperty(key) ; if ( x == null ) { setProperty(key, expected) ; return ; } if ( x.equals(expected) ) return ; inconsistent(key, x, expected) ; }
@Test public void meta2() { clear() ; MetaFile f = new MetaFile("META", testfile) ; f.setProperty("test.value1", "1") ; f.flush(); MetaFile f2 = new MetaFile("META", testfile) ; assertEquals("1", f2.getProperty("test.value1")) ; assertNull(f2.getProperty("test.value.other")) ; }
@Test public void meta2() { clear() ; MetaFile f = new MetaFile("META", testfile) ; f.setProperty("test.value1", "1") ; f.flush(); MetaFile f2 = new MetaFile("META", testfile) ; assertEquals("1", f2.getProperty("test.value1")) ; assertNull(f2.getProperty("test.value.other")) ; }