Class SimpleTupleFormat

java.lang.Object
org.apache.commons.geometry.core.internal.SimpleTupleFormat

public class SimpleTupleFormat extends Object
Class for performing simple formatting and parsing of real number tuples.
  • Constructor Details

    • SimpleTupleFormat

      public SimpleTupleFormat(String prefix, String suffix)
      Constructs a new instance with the default string separator (a comma) and the given prefix and suffix.
      Parameters:
      prefix - String used to signal the start of a tuple; if null, no string is expected at the start of the tuple
      suffix - String used to signal the end of a tuple; if null, no string is expected at the end of the tuple
    • SimpleTupleFormat

      protected SimpleTupleFormat(String separator, String prefix, String suffix)
      Simple constructor.
      Parameters:
      separator - String used to separate tuple values; must not be null.
      prefix - String used to signal the start of a tuple; if null, no string is expected at the start of the tuple
      suffix - String used to signal the end of a tuple; if null, no string is expected at the end of the tuple
  • Method Details

    • getSeparator

      public String getSeparator()
      Return the string used to separate tuple values.
      Returns:
      the value separator string
    • getPrefix

      public String getPrefix()
      Return the string used to signal the start of a tuple. This value may be null.
      Returns:
      the string used to begin each tuple or null
    • getSuffix

      public String getSuffix()
      Returns the string used to signal the end of a tuple. This value may be null.
      Returns:
      the string used to end each tuple or null
    • format

      public String format(double a)
      Return a tuple string with the given value.
      Parameters:
      a - value
      Returns:
      1-tuple string
    • format

      public String format(double a1, double a2)
      Return a tuple string with the given values.
      Parameters:
      a1 - first value
      a2 - second value
      Returns:
      2-tuple string
    • format

      public String format(double a1, double a2, double a3)
      Return a tuple string with the given values.
      Parameters:
      a1 - first value
      a2 - second value
      a3 - third value
      Returns:
      3-tuple string
    • format

      public String format(double a1, double a2, double a3, double a4)
      Return a tuple string with the given values.
      Parameters:
      a1 - first value
      a2 - second value
      a3 - third value
      a4 - fourth value
      Returns:
      4-tuple string
    • parse

      public <T> T parse(String str, DoubleFunction1N<T> fn)
      Parse the given string as a 1-tuple and passes the tuple values to the given function. The function output is returned.
      Type Parameters:
      T - function return type
      Parameters:
      str - the string to be parsed
      fn - function that will be passed the parsed tuple values
      Returns:
      object returned by fn
      Throws:
      IllegalArgumentException - if the input string format is invalid
    • parse

      public <T> T parse(String str, DoubleFunction2N<T> fn)
      Parse the given string as a 2-tuple and passes the tuple values to the given function. The function output is returned.
      Type Parameters:
      T - function return type
      Parameters:
      str - the string to be parsed
      fn - function that will be passed the parsed tuple values
      Returns:
      object returned by fn
      Throws:
      IllegalArgumentException - if the input string format is invalid
    • parse

      public <T> T parse(String str, DoubleFunction3N<T> fn)
      Parse the given string as a 3-tuple and passes the parsed values to the given function. The function output is returned.
      Type Parameters:
      T - function return type
      Parameters:
      str - the string to be parsed
      fn - function that will be passed the parsed tuple values
      Returns:
      object returned by fn
      Throws:
      IllegalArgumentException - if the input string format is invalid
    • getDefault

      public static SimpleTupleFormat getDefault()
      Return an instance configured with default values. Tuples in this format are enclosed by parentheses and separated by commas. Ex:
       "(1.0)"
       "(1.0, 2.0)"
       "(1.0, 2.0, 3.0)"
       
      Returns:
      instance configured with default values