public final class VObjectPropertyValues extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
VObjectPropertyValues.SemiStructuredValueBuilder
Helper class for building "semi-structured" property values.
|
static class |
VObjectPropertyValues.SemiStructuredValueIterator
Helper class for iterating over the values in a "semi-structured"
property value.
|
static class |
VObjectPropertyValues.StructuredValueBuilder
Helper class for building "structured" property values.
|
static class |
VObjectPropertyValues.StructuredValueIterator
Helper class for iterating over the values in a "structured" property
value.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
escape(String value)
Escapes all special characters within a property value.
|
static List<String> |
parseList(String value)
Parses a "list" property value.
|
static Map<String,List<String>> |
parseMultimap(String value)
Parses a "multimap" property value.
|
static List<String> |
parseSemiStructured(String value)
Parses a "semi-structured" property value.
|
static List<String> |
parseSemiStructured(String value,
int limit)
Parses a "semi-structured" property value.
|
static List<List<String>> |
parseStructured(String value)
Parses a "structured" property value.
|
static String |
unescape(String value)
Unescapes all escaped characters in a property value.
|
static String |
writeList(Collection<?> values)
Generates a "list" property value.
|
static String |
writeMultimap(Map<String,? extends List<?>> multimap)
Writes a "multimap" property value.
|
static String |
writeSemiStructured(List<?> values,
boolean escapeCommas,
boolean includeTrailingSemicolons)
Writes a "semi-structured" property value.
|
static String |
writeStructured(List<? extends List<?>> components,
boolean includeTrailingSemicolons)
Writes a "structured" property value.
|
public static String unescape(String value)
Unescapes all escaped characters in a property value. Escaped newlines are replaced with the local system's newline character sequence.
Example:
String value = "one\\,two\\;three\\nfour";
String unescaped = VObjectPropertyValues.unescape(value);
assertEquals("one,two;three\nfour", unescaped);
value - the value to unescapepublic static String escape(String value)
Escapes all special characters within a property value. These characters are:
\),);)
Newlines are not escaped by this method. They are automatically escaped
by VObjectWriter when the data is serialized.
Example:
String value = "one,two;three\nfour";
String escaped = VObjectPropertyValues.escape(value);
assertEquals("one\\,two\\;three\nfour", escaped);
value - the value to escapepublic static List<String> parseList(String value)
Parses a "list" property value.
List values contain multiple values separated by commas. The order that the values are in usually doesn't matter.
Example:
String value = "one,two\\,three";
List<String> list = VObjectPropertyValues.parseList(value);
assertEquals(Arrays.asList("one", "two,three"), list);
value - the value to parsepublic static String writeList(Collection<?> values)
Generates a "list" property value.
List values contain multiple values separated by commas. The order that the values are in usually doesn't matter.
Each list item's toString() method is called to generate its
string representation. If a list item is null, then "null" will be
outputted.
Example:
List<String> list = Arrays.asList("one", "two", null, "three,four");
String value = VObjectPropertyValues.writeList(list);
assertEquals("one,two,null,three\\,four", value);
values - the values to writepublic static List<String> parseSemiStructured(String value)
Parses a "semi-structured" property value.
Semi-structured values contain multiple values separate by semicolons. Unlike structured values, each value cannot have their own comma-delimited list of sub-values. The order that the values are in usually matters.
Example:
String value = "one;two\\;three,four";
List<String> values = VObjectPropertyValues.parseSemiStructured(value);
assertEquals(Arrays.asList("one", "two;three,four"), values);
value - the value to parsepublic static List<String> parseSemiStructured(String value, int limit)
Parses a "semi-structured" property value.
Semi-structured values contain multiple values separate by semicolons. Unlike structured values, each value cannot have their own comma-delimited list of sub-values. The order that the values are in usually matters.
Example:
String value = "one;two;three";
List<String> values = VObjectPropertyValues.parseSemiStructured(value, 2);
assertEquals(Arrays.asList("one", "two;three"), values);
value - the value to parselimit - the max number of items to parsepublic static String writeSemiStructured(List<?> values, boolean escapeCommas, boolean includeTrailingSemicolons)
Writes a "semi-structured" property value.
Semi-structured values contain multiple values separate by semicolons. Unlike structured values, each value cannot have their own comma-delimited list of sub-values. The order that the values are in usually matters.
Example:
List<String> list = Arrays.asList("one", null, "two;three", "");
String value = VObjectPropertyValues.writeSemiStructured(list, false);
assertEquals("one;null;two\\;three", value);
value = VObjectPropertyValues.writeSemiStructured(list, true);
assertEquals("one;null;two\\;three;", value);
values - the values to writeescapeCommas - true to escape comma characters, false not to.
Old-style syntax does not expect commas to be escaped in semi-structured
values.includeTrailingSemicolons - true to include the semicolon delimiters
for empty values at the end of the values list, false to trim thempublic static List<List<String>> parseStructured(String value)
Parses a "structured" property value.
Structured values are essentially 2-D arrays. They contain multiple components separated by semicolons, and each component can have multiple values separated by commas. The order that the components are in matters, but the order that each component's list of values are in usually doesn't matter.
Example:
String value = "one;two,three;four\\,five\\;six";
List<List<String>> values = VObjectPropertyValues.parseStructured(value);
assertEquals(Arrays.asList(
Arrays.asList("one"),
Arrays.asList("two", "three"),
Arrays.asList("four,five;six")
), values);
value - the value to parsepublic static String writeStructured(List<? extends List<?>> components, boolean includeTrailingSemicolons)
Writes a "structured" property value.
Structured values are essentially 2-D arrays. They contain multiple components separated by semicolons, and each component can have multiple values separated by commas. The order that the components are in matters, but the order that each component's list of values are in usually doesn't matter.
The toString() method of each component value is called to
generate its string representation. If a value is null, then "null" will
be outputted.
Example:
List<List<?>> values = Arrays.asList(
Arrays.asList("one"),
Arrays.asList("two", "three", null),
Arrays.asList("four,five;six"),
Arrays.asList()
);
String value = VObjectPropertyValues.writeStructured(values, false);
assertEquals("one;two,three,null;four\\,five\\;six", value);
value = VObjectPropertyValues.writeStructured(values, true);
assertEquals("one;two,three,null;four\\,five\\;six;", value);
components - the components to writeincludeTrailingSemicolons - true to include the semicolon delimiters
for empty components at the end of the written value, false to trim thempublic static Map<String,List<String>> parseMultimap(String value)
Parses a "multimap" property value.
Multimap values are collections of key/value pairs whose keys can be multi-valued. Key/value pairs are separated by semicolons. Values are separated by commas. Keys are converted to uppercase.
Example:
String value = "one=two;THREE=four,five\\,six\\;seven";
Map<String, List<String>> multimap = VObjectPropertyValues.parseMultimap(value);
Map<String, List<String>> expected = new HashMap<String, List<String>>();
expected.put("ONE", Arrays.asList("two"));
expected.put("THREE", Arrays.asList("four", "five,six;seven"));
assertEquals(expected, multimap);
value - the value to parsepublic static String writeMultimap(Map<String,? extends List<?>> multimap)
Writes a "multimap" property value.
Multimap values are collections of key/value pairs whose keys can be multi-valued. Key/value pairs are separated by semicolons. Values are separated by commas. Keys are converted to uppercase.
Each value's toString() method is called to generate its string
representation. If a value is null, then "null" will be outputted.
Example:
Map<String, List<?>> input = new LinkedHashMap<String, List<?>>();
input.put("one", Arrays.asList("two"));
input.put("THREE", Arrays.asList("four", "five,six;seven"));
String value = VObjectPropertyValues.writeMultimap(input);
assertEquals("ONE=two;THREE=four,five\\,six\\;seven", value);
multimap - the multimap to writeCopyright © 2016–2018 Michael Angstadt. All rights reserved.