Package com.oorian
Class UrlParameters
java.lang.Object
com.oorian.UrlParameters
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a parameter with the specified name and value.getParameter(int index) Returns the parameter value by index (order of appearance in URL).getParameter(String paramName) Returns the parameter value by name.getParameterAsDouble(int index) Returns the parameter value as a Double by index.getParameterAsDouble(String paramName) Returns the parameter value as a Double by name.getParameterAsInt(int index) Returns the parameter value as an Integer by index.getParameterAsInt(String paramName) Returns the parameter value as an Integer by name.getParameterAsLong(int index) Returns the parameter value as a Long by index.getParameterAsLong(String paramName) Returns the parameter value as a Long by name.booleanisEmpty()Checks if there are no URL parameters.intsize()Returns the number of URL parameters.
-
Constructor Details
-
UrlParameters
public UrlParameters()
-
-
Method Details
-
add
Adds a parameter with the specified name and value.- Parameters:
paramName- the parameter nameparamValue- the parameter value
-
getParameter
Returns the parameter value by name.- Parameters:
paramName- the parameter name- Returns:
- the value, or null if not found
-
getParameter
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
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
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
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
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
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
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
-