Class IndexStringTable

java.lang.Object
javax0.jamal.extensions.IndexStringTable
All Implemented Interfaces:
javax0.jamal.api.Identified, javax0.jamal.api.Macro, javax0.jamal.api.ServiceLoaded

public class IndexStringTable
extends Object
implements javax0.jamal.api.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 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.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface javax0.jamal.api.Identified

    javax0.jamal.api.Identified.Undefined

    Nested classes/interfaces inherited from interface javax0.jamal.api.Macro

    javax0.jamal.api.Macro.Stateful
  • Field Summary

    Fields inherited from interface javax0.jamal.api.Identified

    DEFAULT_MACRO, MACRO_NAME_ARG1, MACRO_NAME_ARG2

    Fields inherited from interface javax0.jamal.api.Macro

    FETCH
  • Constructor Summary

    Constructors 
    Constructor Description
    IndexStringTable()  
  • Method Summary

    Modifier and Type Method Description
    String evaluate​(javax0.jamal.api.Input in, javax0.jamal.api.Processor processor)  
    String getId()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface javax0.jamal.api.Macro

    fetch, getIds, prefetch
  • Constructor Details

  • Method Details

    • evaluate

      public String evaluate​(javax0.jamal.api.Input in, javax0.jamal.api.Processor processor) throws javax0.jamal.api.BadSyntax
      Specified by:
      evaluate in interface javax0.jamal.api.Macro
      Throws:
      javax0.jamal.api.BadSyntax
    • getId

      public String getId()
      Specified by:
      getId in interface javax0.jamal.api.Identified
      Specified by:
      getId in interface javax0.jamal.api.Macro