java.lang.Object
java.lang.Record
de.cuioss.http.security.data.URLParameter
- Record Components:
name- The parameter name (e.g., "userId", "page", "filter")value- The parameter value (e.g., "12345", "admin", "active")
Immutable record representing a URL query parameter with name and value.
This record encapsulates the key-value pair structure of URL query parameters, providing a type-safe way to handle parameter data in HTTP security validation.
Design Principles
- Immutability - All fields are final and the record cannot be modified
- Type Safety - Strongly typed representation of parameter data
- Null Safety - Explicit handling of null values with clear semantics
- Value Semantics - Records provide automatic equals/hashCode/toString
Usage Examples
// Create a parameter
URLParameter param = new URLParameter("userId", "12345");
// Access components
String name = param.name(); // "userId"
String value = param.value(); // "12345"
// Use in validation
validator.validate(param.name(), ValidationType.PARAMETER_NAME);
validator.validate(param.value(), ValidationType.PARAMETER_VALUE);
// Parameters are value objects
URLParameter param2 = new URLParameter("userId", "12345");
assert param.equals(param2); // true
Null Handling
Both name and value can be null to represent edge cases in HTTP parsing, though null parameter names are typically invalid in well-formed URLs.
Security Considerations
This record is a simple data container. Security validation should be applied
to the name and value components separately using appropriate validators for
ValidationType.PARAMETER_NAME and ValidationType.PARAMETER_VALUE.
- Since:
- 1.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionURLParameter(@Nullable String name, @Nullable String value) Creates an instance of aURLParameterrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanhasName()Checks if this parameter has a non-null, non-empty name.booleanhasValue()Checks if this parameter has a non-null, non-empty value.booleanisFlag()Checks if this parameter represents a flag (has name but no meaningful value).@Nullable Stringname()Returns the value of thenamerecord component.nameOrDefault(String defaultName) Returns the parameter name, or a default value if the name is null.Returns a string representation suitable for URL encoding.final StringtoString()Returns a string representation of this record class.@Nullable Stringvalue()Returns the value of thevaluerecord component.valueOrDefault(String defaultValue) Returns the parameter value, or a default value if the value is null.static URLParameterwithEmptyValue(String name) Creates a URLParameter with empty value.
-
Constructor Details
-
Method Details
-
withEmptyValue
Creates a URLParameter with empty value. Useful for parameters that appear without values (e.g., "?flag" instead of "?flag=value").- Parameters:
name- The parameter name, should not be null- Returns:
- A URLParameter with the specified name and empty string value
-
hasName
Checks if this parameter has a non-null, non-empty name.- Returns:
- true if the name is not null and not empty
-
hasValue
Checks if this parameter has a non-null, non-empty value.- Returns:
- true if the value is not null and not empty
-
isFlag
Checks if this parameter represents a flag (has name but no meaningful value). A parameter is considered a flag if it has a name but the value is null or empty.- Returns:
- true if this appears to be a flag parameter
-
nameOrDefault
Returns the parameter name, or a default value if the name is null.- Parameters:
defaultName- The default name to return if name is null- Returns:
- The parameter name or the default
-
valueOrDefault
Returns the parameter value, or a default value if the value is null.- Parameters:
defaultValue- The default value to return if value is null- Returns:
- The parameter value or the default
-
toParameterString
Returns a string representation suitable for URL encoding. Note: This does not perform actual URL encoding - use appropriate encoding utilities for that purpose.- Returns:
- A string in the format "name=value" or "name" for flag parameters
-
withName
-
withValue
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
value
Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-