Class IndexStringTable

  • All Implemented Interfaces:
    Macro

    public class IndexStringTable
    extends java.lang.Object
    implements Macro
    Get an indexed element from a string table.

    A string table is a string in which certain characters are separators. These separators divide the string into substrings. The substrings can also be string tables that use different separator characters.

    In the simplest one dimensional form a string table is a string that is separated by | characters. Each element of the this table can itself be a table that uses the character /. The tables in this string table are separated by :, then - and finally . (dot). These are the default values for the table separators on the different levels.

    Usually there is no need for so many redirections. The macro get has numeric arguments and then the string, which is a string table. The numeric arguments are indices. The string should start with the top level separator, which is | by default.

    For example

         {{#get 1 2 |a/b/c|h/k/j|o/z}}
     
    will result j because that is the third element of the second table. (Indexing starts with zero.)

    The use of the macro can be handy when a for loop has to go through linked elements. For example we want to iterate through some methods and argument types attached to it. The following example is from a real life project:

         {{#eval{{ @for nameOfTheMethod in (truncate|int|int,substring|int|int,
                                               between|String|String,mid|int|int,
                                               prependIfMissing|CharSequence|CharSequence...,
                                               pad|int|char)=
             public Chain {{#get 0 |nameOfTheMethod}}(final {{#get 1 |nameOfTheMethod}} arg1,final {{#get 2 |nameOfTheMethod}} arg2) {
                 return copy(Str.this.{{#get 0 |nameOfTheMethod}}(arg1,arg2)).new Chain();
             } }}}}
     

    The separators by default are the characters |/:-. in this order as the separation digs deeper along the indices. This default can be overridden defining the user defined macro $getsep. When this macro is defined the first character will be used as a separator character on the top level, the second on the next and so on.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String evaluate​(Input in, Processor processor)  
      java.lang.String getId()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IndexStringTable

        public IndexStringTable()