Class MiscFunctions

java.lang.Object
org.deltava.taglib.functions.MiscFunctions

public class MiscFunctions extends Object
A JSP Function Library to store miscellaneous functions.
Since:
1.0
Version:
11.0
Author:
Luke
  • Method Details

    • get

      public static <T> T get(List<T> l, int idx)
      A JSP-friendly function to get an element from a List. Equivalent to List.get(int).
      Parameters:
      l - the List containing the elements
      idx - the element position within the List
      Returns:
      the element, or null if an invalid index is specified
    • first

      public static <T> T first(Collection<T> c)
      Returns the first object in a Collection.
      Parameters:
      c - the Collection
      Returns:
      the first Object returned by the Collection's iterator.
    • subset

      public static <T> Collection<T> subset(Collection<T> c, int size)
      Returns a subset of a Collection.
      Parameters:
      c - the Collection
      size - the number of entries to return
      Returns:
      a Collection with the specified number of entries, or less if c is smaller than size
    • contains

      public static <T> boolean contains(Collection<T> c, T obj)
      A JSP-friendly function to check if an object exists within a Collection.
      Parameters:
      c - the Collection
      obj - the Object
      Returns:
      TRUE if c is not null and c.contains(obj), otherwise FALSE
      See Also:
    • escape

      public static String escape(String s)
      "Escape" a string by stripping out all inline HTML.
      Parameters:
      s - the String to format
      Returns:
      the escaped String
      See Also:
    • replace

      public static String replace(String s, String old, String n)
      Performs a search and replace operation.
      Parameters:
      s - the string to update
      old - the subtext to remove
      n - the subtext to replace with
      Returns:
      the updated string
      Since:
      1.1
    • splice

      public static String splice(Collection<?> c, String delim)
      Concatenates a series of list elements into a String.
      Parameters:
      c - a Collection of objects
      delim - the delimiter
      Returns:
      a delimited String
    • toHex

      public static String toHex(long val)
      Converts a number to hexadecimal.
      Parameters:
      val - the number to convert
      Returns:
      the converted number, with "0x" prepended to it
      See Also:
    • toLower

      public static String toLower(String s)
      Converts a string to lower case.
      Parameters:
      s - the string to convert
      Returns:
      the lower case string, or null
    • toUpper

      public static String toUpper(String s)
      Converts a string to upper case.
      Parameters:
      s - the string to convert
      Returns:
      the upper case string, or null
    • toRGBA

      public static String toRGBA(int c, float a)
      Generates a CSS color with alpha.
      Parameters:
      c - the RGB color
      a - the alpha factor from 0 to 1
      Returns:
      a CSS color with alpha
    • format

      public static String format(Temporal dt, String fmt)
      Formats a Date into a String for use in a JSP Tag parameter.
      Parameters:
      dt - the date/time value
      fmt - the format pattern
      Returns:
      the formatted date/time
    • difference

      public static long difference(Temporal t1, Temporal t2)
      Displays the time difference between two date/times.
      Parameters:
      t1 - the first date/time
      t2 - the second date/time
      Returns:
      the difference in seconds, or 0 if either date is null