Package com.oorian

Class Parameter

java.lang.Object
com.oorian.Parameter

public class Parameter extends Object
Represents a single HTTP request parameter that may have multiple values.

Parameter encapsulates a named parameter with support for multiple values, which is common in HTML forms with checkboxes or multi-select elements. It provides type-safe accessors for converting values to various primitive types.

Usage:


 Parameter param = new Parameter("ids", "1");
 param.addValue("2");
 param.addValue("3");
 List<Integer> ids = param.getValuesAsInts(); // [1, 2, 3]
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Parameter

      public Parameter(String name)
      Constructs a Parameter with the specified name and no values.
      Parameters:
      name - the parameter name
    • Parameter

      public Parameter(String name, String value)
      Constructs a Parameter with the specified name and initial value.
      Parameters:
      name - the parameter name
      value - the initial value
  • Method Details

    • addValue

      public void addValue(String value)
      Adds a value to this parameter.
      Parameters:
      value - the value to add
    • getName

      public String getName()
      Returns the parameter name.
      Returns:
      the name
    • getValues

      public List<String> getValues()
      Returns all values as strings.
      Returns:
      list of string values
    • getValuesAsInts

      public List<Integer> getValuesAsInts()
      Returns all values converted to Integers.
      Returns:
      list of Integer values
      Throws:
      NumberFormatException - if any value cannot be parsed
    • getValuesAsLongs

      public List<Long> getValuesAsLongs()
      Returns all values converted to Longs.
      Returns:
      list of Long values
      Throws:
      NumberFormatException - if any value cannot be parsed
    • getValuesAsShorts

      public List<Short> getValuesAsShorts()
      Returns all values converted to Shorts.
      Returns:
      list of Short values
      Throws:
      NumberFormatException - if any value cannot be parsed
    • getValuesAsDoubles

      public List<Double> getValuesAsDoubles()
      Returns all values converted to Doubles.
      Returns:
      list of Double values
      Throws:
      NumberFormatException - if any value cannot be parsed
    • getValuesAsFloats

      public List<Float> getValuesAsFloats()
      Returns all values converted to Floats.
      Returns:
      list of Float values
      Throws:
      NumberFormatException - if any value cannot be parsed
    • getValuesAsBooleans

      public List<Boolean> getValuesAsBooleans()
      Returns all values converted to Booleans.
      Returns:
      list of Boolean values
    • getValue

      public String getValue()
      Returns the first value of this parameter.
      Returns:
      the first value, or null if no values exist
    • getValueAsInt

      public Integer getValueAsInt()
      Returns the first value as an Integer.
      Returns:
      the Integer value, or null if no values exist
      Throws:
      NumberFormatException - if the value cannot be parsed
    • getValueAsLong

      public Long getValueAsLong()
      Returns the first value as a Long.
      Returns:
      the Long value, or null if no values exist
      Throws:
      NumberFormatException - if the value cannot be parsed
    • getValueAsShort

      public Short getValueAsShort()
      Returns the first value as a Short.
      Returns:
      the Short value, or null if no values exist
      Throws:
      NumberFormatException - if the value cannot be parsed
    • getValueAsDouble

      public Double getValueAsDouble()
      Returns the first value as a Double.
      Returns:
      the Double value, or null if no values exist
      Throws:
      NumberFormatException - if the value cannot be parsed
    • getValueAsFloat

      public Float getValueAsFloat()
      Returns the first value as a Float.
      Returns:
      the Float value, or null if no values exist
      Throws:
      NumberFormatException - if the value cannot be parsed
    • getValueAsBoolean

      public Boolean getValueAsBoolean()
      Returns the first value as a Boolean.

      Uses Boolean.parseBoolean(String) which returns true only if the value equals "true" (case-insensitive).

      Returns:
      the Boolean value, or null if no values exist
    • toString

      public String toString()
      Returns a string representation of this parameter.

      The format is: name=[value1, value2, ...]

      Overrides:
      toString in class Object
      Returns:
      formatted string showing name and all values