public interface Route
sections.
Route objects are immutable, but handful of methods are provided to create derivations.
| Modifier and Type | Method and Description |
|---|---|
Route |
add(Object key)
Creates a new route, copies this route's backing array, adds the given key at the end and returns the new route
created from the new array.
|
static Route |
addTo(Route route,
Object key)
Performs the same operation on the given route as
add(Object) (and returns the result); if the
given route is null, creates and returns a single-key route containing only the given key. |
boolean |
equals(Object o) |
static Route |
from(Object... route)
Constructs route from the given array of keys/key arguments, enabling usage of wide-range data types as keys.
|
static Route |
from(Object key)
Constructs route from the given single key, enabling usage of wide-range data types as keys.
|
static Route |
fromSingleKey(Object key)
Constructs route from the given single key, enabling usage of wide-range data types as keys.
|
static Route |
fromString(String route)
Constructs a route from the given string route, by splitting it by
GeneralSettings.DEFAULT_ROUTE_SEPARATOR. |
static Route |
fromString(String route,
char separator)
Constructs a route from the given string route, by splitting it by the given separator.
|
static Route |
fromString(String route,
RouteFactory routeFactory)
Constructs a route from the given string route, by splitting it by separator supplied by the factory.
|
Object |
get(int i)
Returns key in this route (from the backing array), at the given position.
|
int |
hashCode() |
String |
join(char separator)
Joins the route's keys with the given separator.
|
int |
length()
Returns the length of the route (backing array) - amount of keys forming this route.
|
Route |
parent()
Returns the parent route of this one.
|
@NotNull static Route from(@NotNull Object... route)
The given array cannot contain null keys.
Empty array is considered illegal and will throw an IllegalArgumentException. Call with null
supplied as the route argument (e.g. from((Object[]) null)) will throw a NullPointerException.
The given keys are traversed in order as they were specified. Assuming route ["x", 1], processor
attempts to get section at key "x" in the section from which the getter/setter... method was called;
and then value at key 1 in that section.
If varargs format is used and there is only one argument, it will automatically be interpreted as call to from(Object), saving time and memory consumption.
If passing an array as the only key, do not forget to cast it to Object, otherwise it will be
interpreted as multi-key route according to the array's contents. Alternatively, to avoid confusion, use fromSingleKey(Object).
As routes are immutable objects, to save resources, it is recommended to create individual routes only once and then reuse them.
route - the route array@NotNull static Route from(@NotNull Object key)
The given key cannot be null.
Alternatively, to avoid confusion, use fromSingleKey(Object).
As routes are immutable objects, to save resources, it is recommended to create individual routes only once and then reuse them.
key - the single element in the returned routealias@NotNull static Route fromSingleKey(@NotNull Object key)
The given key cannot be null.
This method is an alias of from(Object).
As routes are immutable objects, to save resources, it is recommended to create individual routes only once and then reuse them.
key - the single element in the returned route@NotNull static Route fromString(@NotNull String route)
GeneralSettings.DEFAULT_ROUTE_SEPARATOR.
To split using a custom separator, please use fromString(String, char).
As string routes can also be used to access data, you should never convert string routes using this method, except some situations where it is allowed.
The given keys are traversed in order as they were specified. Assuming route ["x", "y"], processor
attempts to get section at key "x" in the section from which the getter/setter... method was called;
and then value at key "y" in that section.
As routes are immutable objects, to save resources, it is recommended to create that certain route only once and then reuse it.
route - the string route to split (in format a.b for separator '.' to create
route
[a, b])@NotNull static Route fromString(@NotNull String route, char separator)
Specifying the same separator again and again might sometimes violate the DRY principle - if that's the case, use
RouteFactory instead.
As string routes can also be used to access data, you should never convert string routes using this method, except some situations where it is allowed.
The given keys are traversed in order as they were specified. Assuming route ["x", "y"], processor
attempts to get section at key "x" in the section from which the getter/setter... method was called;
and then value at key "y" in that section.
As routes are immutable objects, to save resources, it is recommended to create that certain route only once and then reuse it.
route - the string route to split (in format a.b for separator '.' to create
route [a, b])separator - separator to split the route by@NotNull static Route fromString(@NotNull String route, @NotNull RouteFactory routeFactory)
This is an alias, use RouteFactory instead.
As string routes can also be used to access data, you should never convert string routes using this method, except some situations where it is allowed.
The given keys are traversed in order as they were specified. Assuming route ["x", "y"], processor
attempts to get section at key "x" in the section from which the getter/setter... method was called;
and then value at key "y" in that section.
As routes are immutable objects, to save resources, it is recommended to create that certain route only once and then reuse it.
route - the string route to split (in format a.b for separator '.' to
create route [a, b])routeFactory - supplies the separator to split the route by@NotNull static Route addTo(@Nullable Route route, @NotNull Object key)
add(Object) (and returns the result); if the
given route is null, creates and returns a single-key route containing only the given key.
The given key cannot be null.
The given keys should be immutable; otherwise, it is required that the caller never modifies them.
route - the route to add another key (element) to, or null to create new onekey - the key to add, or create a single key route fromadd(Object)@NotNull String join(char separator)
separator - the separator to join withint length()
@NotNull Object get(int i)
length().i - the index@NotNull Route add(@NotNull Object key)
The given key cannot be null, it is required to verify that.
It is in the caller's best interest to never modify the objects given (and their contents), as it might cause several issues (inequalities between routes...).
key - the key to add@NotNull Route parent()
More formally, creates a new route and copies this route's backing array without the last element.
Please note that if this route's length() is 1, invoking this method will create an IllegalArgumentException, as it is illegal to have empty routes. See more at from(Object...).
Copyright © 2022. All rights reserved.