Class ChannelId
Reification of a channel id
with methods to test properties
and compare with other ChannelId
s.
A ChannelId
breaks the channel id into path segments so that, for example,
/foo/bar
breaks into ["foo","bar"]
.
ChannelId
can be wild, when they end with one or two wild characters "*"
;
a ChannelId
is shallow wild if it ends with one wild character (for example /foo/bar/*
)
and deep wild if it ends with two wild characters (for example /foo/bar/**
).
ChannelId
can be a template, when a segment contains variable names surrounded by
braces, for example /foo/{var_name}
. Variable names can only be made of characters
defined by the \w
regular expression character class.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionIf thisChannelId
is a template, and the giventarget
ChannelId
is non-wild and non-template, and the two have the samedepth()
, then binds the variable(s) defined in this template with the values of the segments defined by the targetChannelId
.int
depth()
boolean
getId()
Returns the normalized channel id string.Returns the regular part of this ChannelId: the part of the channel id from the beginning until the first occurrence of a parameter or a wild character.getSegment
(int i) Returns the list of wild channels that match this channel.getWilds()
Deprecated.int
hashCode()
boolean
boolean
static boolean
isBroadcast
(String channelId) boolean
boolean
isMeta()
AChannelId
is a metaChannelId
if it starts with"/meta/"
.static boolean
boolean
isParentOf
(ChannelId id) boolean
AChannelId
is a serviceChannelId
if it starts with"/service/"
.static boolean
boolean
boolean
boolean
isWild()
boolean
Tests whether thisChannelId
matches the givenChannelId
.toString()
-
Field Details
-
WILD
- See Also:
-
DEEPWILD
- See Also:
-
-
Constructor Details
-
ChannelId
Constructs a newChannelId
with the given id- Parameters:
id
- the channel id in string form
-
-
Method Details
-
getId
Returns the normalized channel id string.
Normalization involves trimming white spaces and removing trailing slashes.
- Returns:
- the normalized channel id string
-
isWild
public boolean isWild()- Returns:
- whether this
ChannelId
is eithershallow wild
ordeep wild
-
isShallowWild
-
isDeepWild
-
isMeta
public boolean isMeta()A
ChannelId
is a metaChannelId
if it starts with"/meta/"
.- Returns:
- whether the first segment is "meta"
-
isService
public boolean isService()A
ChannelId
is a serviceChannelId
if it starts with"/service/"
.- Returns:
- whether the first segment is "service"
-
isBroadcast
-
isTemplate
public boolean isTemplate()- Returns:
- whether this
ChannelId
is a template, that is it contains segments that identify a variable name between braces, such as/foo/{var_name}
. - See Also:
-
getParameters
-
equals
-
hashCode
-
matches
Tests whether this
ChannelId
matches the givenChannelId
.If the given
ChannelId
iswild
, then it matches only if it is equal to thisChannelId
.If this
ChannelId
is non-wild, then it matches only if it is equal to the givenChannelId
.Otherwise, this
ChannelId
is either shallow or deep wild, and matchesChannelId
s with the same number of equal segments (if it is shallow wild), orChannelId
s with the same or a greater number of equal segments (if it is deep wild).- Parameters:
channelId
- the channelId to match- Returns:
- true if this
ChannelId
matches the givenChannelId
-
bind
If this
ChannelId
is a template, and the giventarget
ChannelId
is non-wild and non-template, and the two have the samedepth()
, then binds the variable(s) defined in this template with the values of the segments defined by the targetChannelId
.For example:
// template and target match. Map<String, String> bindings = new ChannelId("/a/{var1}/c/{var2}").bind(new ChannelId("/a/foo/c/bar")); bindings: {"var1": "foo", "var2": "bar"} // template has 2 segments, target has only 1 segment. bindings = new ChannelId("/a/{var1}").bind(new ChannelId("/a")) bindings = {} // template has 2 segments, target too many segments. bindings = new ChannelId("/a/{var1}").bind(new ChannelId("/a/b/c")) bindings = {} // same number of segments, but no match on non-variable segments. bindings = new ChannelId("/a/{var1}").bind(new ChannelId("/b/c")) bindings = {}
The returned map may not preserve the order of variables present in the template
ChannelId
.- Parameters:
target
- the non-wild, non-templateChannelId
to bind- Returns:
- a map with the bindings, or an empty map if no binding was possible
- See Also:
-
toString
-
depth
public int depth()- Returns:
- how many segments this
ChannelId
is made of - See Also:
-
isAncestorOf
- Parameters:
id
- the channel to test- Returns:
- whether this
ChannelId
is an ancestor of the givenChannelId
- See Also:
-
isParentOf
- Parameters:
id
- the channel to test- Returns:
- whether this
ChannelId
is the parent of the givenChannelId
- See Also:
-
getParent
- Returns:
- the channel string parent of this
ChannelId
, or null if thisChannelId
has only one segment - See Also:
-
getSegment
- Parameters:
i
- the segment index- Returns:
- the i-nth segment of this channel, or null if no such segment exist
- See Also:
-
getWilds
Deprecated.usegetWildIds()
instead- Returns:
- The list of wilds channels that match this channel, or the empty list if this channel is already wild.
-
getWildIds
Returns the list of wild channels that match this channel.
For channel
/foo/bar/baz
, returns[/foo/bar/*, /foo/bar/**, /foo/**, /**]
.For channel
/foo/bar/*
, returns[/foo/bar/**, /foo/**, /**]
.For channel
/foo/bar/**
, returns[/foo/**, /**]
.For channel
/*
, returns[/**]
.For channel
/**
, returns[]
, an empty list.- Returns:
- The list of wilds channels that match this channel.
-
getAllIds
-
getRegularPart
Returns the regular part of this ChannelId: the part of the channel id from the beginning until the first occurrence of a parameter or a wild character.
Examples:
ChannelId.regularPart Examples Channel Regular Part /foo /foo /foo/* /foo /foo/bar/** /foo/bar /foo/{p} /foo /foo/bar/{p} /foo/bar /* null
/** null
/{p} null
- Returns:
- the regular part of this channel
-
isMeta
-
isService
-
isBroadcast
-
getWildIds()
instead