Class Parameters

java.lang.Object
com.jbstrap.core.Parameters
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
GaugeChartSection

public class Parameters extends Object implements Serializable
Class for storing parameters and transporting them
Since:
4.0
Author:
JBStrap
See Also:
  • Constructor Details

    • Parameters

      public Parameters()
  • Method Details

    • add

      public Parameters add(String name, Object value)
      Adds the specified parameter
      Parameters:
      name - The name of the parameter to be added. If the specified name already exists, it will be overwritten
      value - The parameter value
      Returns:
      The object containing the parameter
      Throws:
      NullPointerException - If the parameter name was specified as null
    • remove

      public Parameters remove(String name)
      Removes the specified parameter
      Parameters:
      name - The name of the parameter to be removed
      Returns:
      The object containing the parameters
      Throws:
      NullPointerException - If the name was specified as null
    • get

      public <T> T get(String name)
      Gets the value of the specified parameter
      Type Parameters:
      T - The parameter value's type
      Parameters:
      name - The parameter name
      Returns:
      The parameter value or null, if the parameter was not found
      Throws:
      NullPointerException - If the parameter name was specified as null
    • getAsString

      public final String getAsString(String name)
      Gets the specified parameter's value as a string
      Parameters:
      name - The parameter name
      Returns:
      The parameter value as a String or null if the parameter was not found
      Throws:
      NullPointerException - If the parameter name was specified as null
    • getAsDate

      public final Date getAsDate(String name)
      Gets the specified parameter's value as a Date. If the parameter isn't a Date, it will be interpreted in the "yyyy-MM-dd HH:mm:ss" date format if possible
      Parameters:
      name - The parameter name
      Returns:
      The parameter value as a Date or null if the parameter was not found or couldn't be interpreted as a date
      Throws:
      NullPointerException - If the parameter name was specified as null
      ParseException - If the beginning of the specified string cannot be parsed.
    • getAsDate

      public final Date getAsDate(String name, String format)
      Gets the specified parameter's value as a Date, in the specified format
      Parameters:
      name - The parameter name
      format - The date format to be used. If specified as null, the format will be "yyyy-MM-dd HH:mm:ss"
      Returns:
      The parameter value as a date or null, if the specified parameter was not found, or couldn't be interpreted as a date
      Throws:
      NullPointerException - If the parameter name was specified as null
      ParseException - If the beginning of the specified string cannot be parsed.
    • getAsNumber

      public final Number getAsNumber(String name)
      Gets the specified parameter's value as a Number
      Parameters:
      name - The parameter name
      Returns:
      The parameter value as a Number or null, if the specified parameter was not found, or couldn't be interpreted as a Number
      Throws:
      NullPointerException - If the parameter name was specified as null
      ParseException - If the beginning of the specified string cannot be parsed.
    • getAsLong

      public final Long getAsLong(String name)
      Gets the specified parameter's value as a Long
      Parameters:
      name - The parameter name
      Returns:
      The parameter value as a Long or null, if the specified parameter was not found, or couldn't be interpreted as a Long
      Throws:
      NullPointerException - If the parameter name was specified as null
      ParseException - If the beginning of the specified string cannot be parsed.
    • getAsDouble

      public final Double getAsDouble(String name)
      Gets the specified parameter's value as a Double
      Parameters:
      name - The parameter name
      Returns:
      The parameter value as a Double or null, if the specified parameter was not found, or couldn't be interpreted as a Double
      Throws:
      NullPointerException - If the parameter name was specified as null
      ParseException - If the beginning of the specified string cannot be parsed.
    • getAsInteger

      public final Integer getAsInteger(String name)
      Gets the specified parameter's value as an Integer
      Parameters:
      name - The parameter name
      Returns:
      The parameter value as an Integer or null, if the specified parameter was not found, or couldn't be interpreted as a Double
      Throws:
      NullPointerException - If the parameter name was specified as null
      ParseException - If the beginning of the specified string cannot be parsed.
    • getAsBoolean

      public Boolean getAsBoolean(String name)
      Gets the specified parameter's value as a Boolean value
      Parameters:
      name - The parameter name
      Returns:
      The parameter value as a Boolean value or null, if the specified parameter was not found, or couldn't be interpreted as a Boolean value
      Throws:
      NullPointerException - If the parameter name was specified as null
    • getNames

      public List<String> getNames()
      Gets a list of every parameter name, that are stored in the object.
      Returns:
      A list of every parameter name, that are stored in the object. If the object is empty (ie, doesn't contain any parameters), it will return with an empty list
    • copy

      public Parameters copy()
      Creates a perfect copy of the object
      Returns:
      The new object, that is a perfect copy the original
    • merge

      public Parameters merge(Parameters... sources)
      Merges the object with the specified parameters
      Parameters:
      sources - The objects containing the parameters that will be merged. The merging will be done in the order the parameters were specified. If one of the specified objects contains a parameter, that has a name that is already present in the Parameters class, the older one will be overwritten by the new, specified one.
      Returns:
      The object containing the parameters
    • isEmpty

      public boolean isEmpty()
      Determines if the object is empty. It's considered empty, if it was created, but has no parameters
      Returns:
      true,if the object has no parameters. Otherwise false
    • clear

      public Parameters clear()
      Delete all previously specified values from the parameter object.
      Returns:
      The object containing the parameter
    • equals

      public boolean equals(Object obj)

      Determines if the specified object is equal with the Parameters object.

      The two objects are considered equal if:

      • The specified object is not null
      • The specified object is a Parameters class, or a descendant of one
      • The cardinality of the two are the same
      • Every specified parameter is the same as the ones in the Parameters class

      Overrides:
      equals in class Object
    • toString

      public String toString()
      Returns a string representation of the object.
      Overrides:
      toString in class Object
    • serialize

      public String serialize() throws IOException
      Throws:
      IOException
    • deserialize

      public static Parameters deserialize(String source) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException