Class HandlerUtils


  • public class HandlerUtils
    extends Object
    Common functions for ANTLRv4's RuleNode handling.
    Author:
    nils.hoffmann
    • Method Detail

      • asInt

        public static <T extends org.antlr.v4.runtime.tree.RuleNode> Integer asInt​(T context,
                                                                                   Integer defaultValue)
        Parse the provided context's text value as an Integer or use default value.
        Type Parameters:
        T - the type of the context.
        Parameters:
        context - the context.
        defaultValue - the default value.
        Returns:
        the context's text value as an integer, or the default value.
      • maybe

        public static <T> Optional<T> maybe​(T t)
        Wrap t as an optional of nullable.
        Type Parameters:
        T - the type of t.
        Parameters:
        t - the argument.
        Returns:
        an optional.
      • maybeMapOr

        public static <T,​R> R maybeMapOr​(T t,
                                               Function<? super T,​R> mapper,
                                               R r)
        Wrap t as an optional and return r if t is null or empty.
        Type Parameters:
        T - the type of t.
        R - the type of the return value r.
        Parameters:
        t - the argument to wrap.
        mapper - the mapping function to get from t to r, if t is not null.
        r - the default return value.
        Returns:
        the mapped value for t of type R, or the default value r.