Package liqp

Class LValue

java.lang.Object
liqp.LValue
Direct Known Subclasses:
AndNode, ComparingExpressionNode, ContainsNode, Filter, Insertion, OrNode, WhereImpl

public abstract class LValue extends Object
An abstract class the Filter and Tag classes extend.

It houses some utility methods easily available for said classes.

  • Field Details

    • BREAK

      public static final LValue BREAK
    • CONTINUE

      public static final LValue CONTINUE
    • rubyDateTimeFormat

      public static DateTimeFormatter rubyDateTimeFormat
  • Constructor Details

    • LValue

      public LValue()
  • Method Details

    • areEqual

      public static boolean areEqual(Object a, Object b)
      Returns true iff a and b are equals, where (int) 1 is equal to (double) 1.0
      Parameters:
      a - the first object to compare.
      b - the second object to compare.
      Returns:
      true iff a and b are equals, where (int) 1 is equals to (double) 1.0
    • asArray

      public Object[] asArray(Object value, TemplateContext context)
      Returns this value as an array. If a value is already an array, it is cast to a `Object[]`, if it's a `java.util.Collection`, it is converted to an array and in all other cases, `value` is simply returned as an `Object[]` with a single value in it. This function treat `Map` as single element.
      Parameters:
      value - the value to convert/cast to an array.
      Returns:
      this value as an array.
    • asList

      public List<?> asList(Object value, TemplateContext context)
      Returns this value as a `java.util.List`. If a value is already a `List`, it is returned as-is, if it's a `java.util.Collection` or an array, it is converted to a `List`, and in all other cases, `value` is simply returned as a `List` with a single value in it. This function treats `Map` as a single element.
      Parameters:
      value - the value to convert/cast to an array.
      Returns:
      this value as a list.
    • temporalAsArray

      public static Object[] temporalAsArray(ZonedDateTime time)
    • asTemporal

      public static TemporalAccessor asTemporal(Object value, TemplateContext context)
      This one keeps an original temporal type as is, while `asRubyDate` converts it to ZonedDateTime.
    • asRubyDate

      public static ZonedDateTime asRubyDate(Object value, TemplateContext context)
      Ruby have a single date type, and its equivalent is ZonedDateTime.
    • isTemporal

      public static boolean isTemporal(Object value)
    • mapAsArray

      protected Object[] mapAsArray(Map<?,?> value)
      Usually we need array representation of items, so the asArray(Object, TemplateContext) do the work well. But occasionally we need introspect the object (usually `Map`) as array. So this function do so.
      Parameters:
      value -
      Returns:
    • asBoolean

      public boolean asBoolean(Object value)
      Convert `value` to a boolean. Note that only `nil` and `false` are `false`, all other values are `true`.
      Parameters:
      value - the value to convert.
      Returns:
      `value` as a boolean.
    • asNumber

      public Number asNumber(Object value) throws NumberFormatException
      Returns `value` as a Number. Strings will be coerced into either a Long or Double.
      Parameters:
      value - the value to cast to a Number.
      Returns:
      `value` as a Number.
      Throws:
      NumberFormatException - when `value` is a String which could not be parsed as a Long or Double.
    • asStrictNumber

      public BigDecimal asStrictNumber(Object number)
    • asFormattedNumber

      public static BigDecimal asFormattedNumber(BigDecimal bd)
    • asString

      public String asString(Object value, TemplateContext context)
      Returns `value` as a String.
      Parameters:
      value - the value to convert to a String.
      Returns:
      `value` as a String.
    • asAppendableObject

      public Object asAppendableObject(Object value, TemplateContext context)
      Returns `value` as an object appendable to RenderTransformer.ObjectAppender.
      Parameters:
      value - the value to convert.
      Returns:
      `value` as an appendable object.
    • isArray

      public boolean isArray(Object value)
      Returns true iff `value` is an array or a java.util.Collection.
      Parameters:
      value - the value to check.
      Returns:
      true iff `value` is an array or a java.util.Collection.
    • isInteger

      public boolean isInteger(Object value)
      Returns true iff `value` is a whole number (Integer or Long).
      Parameters:
      value - the value to check.
      Returns:
      true iff `value` is a whole number (Integer or Long).
    • isNumber

      public boolean isNumber(Object value)
      Returns true iff `value` is a Number.
      Parameters:
      value - the value to check.
      Returns:
      true iff `value` is a Number.
    • isString

      public boolean isString(Object value)
      Returns true iff `value` is a String.
      Parameters:
      value - the value to check.
      Returns:
      true iff `value` is a String.
    • isTruthy

      public boolean isTruthy(Object value, TemplateContext context)
    • isFalsy

      public boolean isFalsy(Object value, TemplateContext context)
    • canBeInteger

      public boolean canBeInteger(Object value)
    • canBeDouble

      public boolean canBeDouble(Object value)
    • canBeNumber

      public boolean canBeNumber(Object value)
    • isMap

      public boolean isMap(Object value)
    • asMap

      public Map<String,Object> asMap(Object value)
    • isBlank

      public static boolean isBlank(String string)