Package eu.bandm.tools.util.xml
Class NamespaceName2String
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<NamespaceName,
String>
Maintains a map from
NamespaceName
to String
,
and reads different file formats.
Can freely be manipulated from outside without harm, like any map,
but the specialized methods provided here are more convenient.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an empty map.Constructs a map with the given data. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsPattern
(String patternMarker) Returns whether the pattern marker is contained anywhere in the values of this map.void
divideValues
(Predicate<String> test, NamespaceName2String yes, NamespaceName2String no) Pipe all entries in this instance according to the result of test to their values.void
dump
(PrintStream p) Print this map in a symbolic representation to the print stream.<A,
B> void fillFromOptions
(MessageReceiver<SimpleMessage<?>> msg, @Opt List<A> files, @Opt List<B> pairs) Add the pairs from the files and then the pairs directly contained in a command line option.void
Create a map reading the data from the given source.void
Create a map reading the data from the given source.void
from
(InputStream s, Charset encoding) Create a map reading the data from the given source.void
Create a map reading the data from the given source.void
Add a key/value pair to the map.replacePattern
(String patternMarker, String value) Return a new copy in the data of which all occurences of the patternMarker are replaced by the given value.Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
NamespaceName2String
public NamespaceName2String()Construct an empty map. (This constructor is required by collections framework convention.) -
NamespaceName2String
Constructs a map with the given data.
-
-
Method Details
-
from
Create a map reading the data from the given source. For details of the file format seefrom(reader)
.- Throws:
IOException
-
from
Create a map reading the data from the given source. UseStandardCharsets.UTF_8
as encoding. For details of the file format seefrom(reader)
.- Throws:
IOException
-
from
Create a map reading the data from the given source. For details of the file format seefrom(reader)
.- Throws:
IOException
-
from
Create a map reading the data from the given source. Each line must start with a namespace name used as a key. The key is limited by a single blank. It must follow the inline syntax, seeNamespaceName.parseInlineURIFormat(java.lang.String)
. The rest of the line, after that separating single blank, is the value stored with the key. With duplicate keys, the later overrides the earlier without notice.Empty lines or lines starting with a "
#
" are ignored as comments.- Throws:
IOException
-
from
Add a key/value pair to the map. The key must follow the inline syntax, seeNamespaceName.parseInlineURIFormat(java.lang.String)
. With double keys, the later overrides the earlier without notice.- Parameters:
k
- the key must be parseable byNamespaceName.parseInlineURIFormat(String)
.- Throws:
IllegalArgumentException
-
dump
Print this map in a symbolic representation to the print stream. -
containsPattern
Returns whether the pattern marker is contained anywhere in the values of this map. (Prototypical use with xslt style-sheet parameters.) -
replacePattern
Return a new copy in the data of which all occurences of the patternMarker are replaced by the given value. (Prototypical use with xslt style-sheet parameters.) -
divideValues
Pipe all entries in this instance according to the result of test to their values.- Parameters:
test
- criterium for the divisionyes
- where to copy the entry in case of a positive test resultno
- where to copy the entry in case of a negative test result
-
fillFromOptions
public <A,B> void fillFromOptions(MessageReceiver<SimpleMessage<?>> msg, @Opt @Opt List<A> files, @Opt @Opt List<B> pairs) Add the pairs from the files and then the pairs directly contained in a command line option. A file later in the list has priority over its predecessors; explicit assignments from the command line option have priority over the files' contents.Since the options compiler generates totally independent classes for each application, this code must use reflection to get the getter methods. Exceptions caused by reflection application are translated to error messages.
- Type Parameters:
A
- the type of value objects. Must provide a method "get_0()
" which delivers a String which is a file name.B
- the type of value objects. Must provide methods "get_0()
" and "get_1()
" which deliver the NamespaceName key and a String value.
-