Class NamespaceName2String

All Implemented Interfaces:
Serializable, Cloneable, Map<NamespaceName,String>

public class NamespaceName2String extends HashMap<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:
  • Constructor Details

    • NamespaceName2String

      public NamespaceName2String()
      Construct an empty map. (This constructor is required by collections framework convention.)
    • NamespaceName2String

      public NamespaceName2String(Map<NamespaceName,String> data)
      Constructs a map with the given data.
  • Method Details

    • from

      public void from(File f, Charset encoding) throws IOException
      Create a map reading the data from the given source. For details of the file format see from(reader).
      Throws:
      IOException
    • from

      public void from(File f) throws IOException
      Create a map reading the data from the given source. Use StandardCharsets.UTF_8 as encoding. For details of the file format see from(reader).
      Throws:
      IOException
    • from

      public void from(InputStream s, Charset encoding) throws IOException
      Create a map reading the data from the given source. For details of the file format see from(reader).
      Throws:
      IOException
    • from

      public void from(Reader r) throws IOException
      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, see NamespaceName.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

      public void from(String k, String v) throws IllegalArgumentException
      Add a key/value pair to the map. The key must follow the inline syntax, see NamespaceName.parseInlineURIFormat(java.lang.String). With double keys, the later overrides the earlier without notice.
      Parameters:
      k - the key must be parseable by NamespaceName.parseInlineURIFormat(String).
      Throws:
      IllegalArgumentException
    • dump

      public void dump(PrintStream p)
      Print this map in a symbolic representation to the print stream.
    • containsPattern

      public boolean containsPattern(String patternMarker)
      Returns whether the pattern marker is contained anywhere in the values of this map. (Prototypical use with xslt style-sheet parameters.)
    • replacePattern

      public NamespaceName2String 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. (Prototypical use with xslt style-sheet parameters.)
    • divideValues

      public void divideValues(Predicate<String> test, NamespaceName2String yes, NamespaceName2String no)
      Pipe all entries in this instance according to the result of test to their values.
      Parameters:
      test - criterium for the division
      yes - where to copy the entry in case of a positive test result
      no - 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.