/** * Casts the specified value into a value list. * <p> * If <code>value</code> is <code>null</code>, this method will return <code>null</code>. * </p> * @param value value to cast to a value list. * @param separator string used to separate data in tokens. * @return <code>value</code> as a value list. */ public static ValueList getListValue(String value, String separator) { return value == null ? null : new ValueList(value, separator); }
/** * Casts the specified value into a string. * @param value value to cast as a string. * @param separator string to use as a separator. * @return <code>value</code> as a string. */ public static String getValue(List<String> value, String separator) { return ValueList.toString(value, separator); }
/** * Returns the value found at the specified index of the list as a float. * @param index index of the value to retrieve. * @return the value found at the specified index of the list as a float. * @throws NumberFormatException if the value cannot be cast to a float. */ public float floatValueAt(int index) { return ConfigurationSection.getFloatValue(valueAt(index)); }
/** * Tests the {@link ValueList#integerValueAt(int)} method. * @param values test data. */ protected void testIntegerValues(ValueList values) { assert values.size() == 7; for(int i = 0; i < 7; i++) assert i + 1 == values.integerValueAt(i); }
/** * Tests the {@link ValueList#floatValueAt(int)} method. * @param values test data. */ protected void testFloatValues(ValueList values) { assert values.size() == 7; for(int i = 0; i < 7; i++) assert i + 1.5 == values.floatValueAt(i); }
/** * Tests the {@link ValueList#doubleValueAt(int)} method. * @param values test data. */ protected void testDoubleValues(ValueList values) { assert values.size() == 7; for(int i = 0; i < 7; i++) assert i + 1.5 == values.doubleValueAt(i); }
/** * Tests the {@link ValueList#booleanValueAt(int)} method. * @param values test data. */ protected void testBooleanValues(ValueList values) { assert values.size() == 7; for(int i = 0; i < 7; i++) assert (i % 2 == 0) == values.booleanValueAt(i); }
/** * Returns the value found at the specified index of the list as a string. * @param index index of the value to retrieve. * @return the value found at the specified index of the list as a string. */ public String valueAt(int index) { return get(index); }
/** * Creates a new <code>ValueList</code> initialised with the specified data. * @param data data contained by the list. * @param separator string used to separate <code>data</code> in tokens. */ public ValueList(String data, String separator) { StringTokenizer tokenizer; tokenizer = new StringTokenizer(data, separator); while(tokenizer.hasMoreTokens()) add(tokenizer.nextToken()); }
/** * Returns the value found at the specified index of the list as a {@link ValueList}. * @param index index of the value to retrieve. * @param separator string used to split the value into tokens. * @return the value found at the specified index of the list as a {@link ValueList}. */ public ValueList listValueAt(int index, String separator) { return ConfigurationSection.getListValue(valueAt(index), separator); }
/** * Tests list events. */ @Test public void testListEvents() { ConfigurationEvent event; // Makes sure the value passed to the constructor is properly returned. event = new ConfigurationEvent(conf, VARIABLE_NAME, ValueList.toString(LIST_VALUE, ";")); assert LIST_VALUE.equals(event.getListValue(";")); // Makes sure unset values are returned as null. event = new ConfigurationEvent(conf, VARIABLE_NAME, null); assert null == event.getListValue(";"); }
/** * Returns the value found at the specified index of the list as an integer. * @param index index of the value to retrieve. * @return the value found at the specified index of the list as an integer. * @throws NumberFormatException if the value cannot be cast to an integer. */ public int integerValueAt(int index) { return ConfigurationSection.getIntegerValue(valueAt(index)); }
/** * Returns the value found at the specified index of the list as a long. * @param index index of the value to retrieve. * @return the value found at the specified index of the list as a long. * @throws NumberFormatException if the value cannot be cast to a long. */ public long longValueAt(int index) { return ConfigurationSection.getLongValue(valueAt(index)); }