Package com.oorian

Class UrlParameters

java.lang.Object
com.oorian.UrlParameters

public class UrlParameters extends Object
Container for URL path parameters extracted from RESTful route patterns.

UrlParameters stores parameters extracted from URL path segments, such as those defined in @Page(path="/users/{id}/posts/{postId}"). Parameters can be accessed by name or by position (index).

Usage:


 // For URL pattern /users/{userId}/orders/{orderId}
 // and request /users/123/orders/456
 UrlParameters params = getUrlParameters();
 Long userId = params.getParameterAsLong("userId");   // 123
 Long orderId = params.getParameterAsLong(1);          // 456 (by index)
 
Since:
2023
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • UrlParameters

      public UrlParameters()
  • Method Details

    • add

      public void add(String paramName, String paramValue)
      Adds a parameter with the specified name and value.
      Parameters:
      paramName - the parameter name
      paramValue - the parameter value
    • getParameter

      public String getParameter(String paramName)
      Returns the parameter value by name.
      Parameters:
      paramName - the parameter name
      Returns:
      the value, or null if not found
    • getParameter

      public String getParameter(int index)
      Returns the parameter value by index (order of appearance in URL).
      Parameters:
      index - the zero-based index
      Returns:
      the value, or null if index is out of bounds
    • getParameterAsInt

      public Integer getParameterAsInt(int index)
      Returns the parameter value as an Integer by index.
      Parameters:
      index - the zero-based index
      Returns:
      the Integer value, or null if not found
      Throws:
      NumberFormatException - if the value cannot be parsed
    • getParameterAsLong

      public Long getParameterAsLong(int index)
      Returns the parameter value as a Long by index.
      Parameters:
      index - the zero-based index
      Returns:
      the Long value, or null if not found
      Throws:
      NumberFormatException - if the value cannot be parsed
    • getParameterAsDouble

      public Double getParameterAsDouble(int index)
      Returns the parameter value as a Double by index.
      Parameters:
      index - the zero-based index
      Returns:
      the Double value, or null if not found
      Throws:
      NumberFormatException - if the value cannot be parsed
    • getParameterAsInt

      public Integer getParameterAsInt(String paramName)
      Returns the parameter value as an Integer by name.
      Parameters:
      paramName - the parameter name
      Returns:
      the Integer value, or null if not found
      Throws:
      NumberFormatException - if the value cannot be parsed
    • getParameterAsLong

      public Long getParameterAsLong(String paramName)
      Returns the parameter value as a Long by name.
      Parameters:
      paramName - the parameter name
      Returns:
      the Long value, or null if not found
      Throws:
      NumberFormatException - if the value cannot be parsed
    • getParameterAsDouble

      public Double getParameterAsDouble(String paramName)
      Returns the parameter value as a Double by name.
      Parameters:
      paramName - the parameter name
      Returns:
      the Double value, or null if not found
      Throws:
      NumberFormatException - if the value cannot be parsed
    • isEmpty

      public boolean isEmpty()
      Checks if there are no URL parameters.
      Returns:
      true if empty
    • size

      public int size()
      Returns the number of URL parameters.
      Returns:
      the parameter count