public class ChannelId extends Object
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.
Modifier and Type | Field and Description |
---|---|
static String |
DEEPWILD |
static String |
WILD |
Constructor and Description |
---|
ChannelId(String id)
Constructs a new
ChannelId with the given id |
Modifier and Type | Method and Description |
---|---|
Map<String,String> |
bind(ChannelId target)
If this
ChannelId is a template, and the given target ChannelId
is non-wild and non-template, and the two have the same depth() , then binds
the variable(s) defined in this template with the values of the segments defined by
the target ChannelId . |
int |
depth() |
boolean |
equals(Object obj) |
List<String> |
getAllIds() |
String |
getId()
Returns the normalized channel id string.
|
List<String> |
getParameters() |
String |
getParent() |
String |
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.
|
String |
getSegment(int i) |
List<String> |
getWildIds()
Returns the list of wild channels that match this channel.
|
List<String> |
getWilds()
Deprecated.
use
getWildIds() instead |
int |
hashCode() |
boolean |
isAncestorOf(ChannelId id) |
boolean |
isBroadcast() |
static boolean |
isBroadcast(String channelId)
|
boolean |
isDeepWild()
|
boolean |
isMeta()
A
ChannelId is a meta ChannelId if it starts with "/meta/" . |
static boolean |
isMeta(String channelId)
|
boolean |
isParentOf(ChannelId id) |
boolean |
isService()
A
ChannelId is a service ChannelId if it starts with "/service/" . |
static boolean |
isService(String channelId)
|
boolean |
isShallowWild()
|
boolean |
isTemplate() |
boolean |
isWild() |
boolean |
matches(ChannelId channelId)
Tests whether this
ChannelId matches the given ChannelId . |
String |
toString() |
public static final String WILD
public static final String DEEPWILD
public ChannelId(String id)
ChannelId
with the given idid
- the channel id in string formpublic String getId()
Returns the normalized channel id string.
Normalization involves trimming white spaces and removing trailing slashes.
public boolean isWild()
ChannelId
is either shallow wild
or deep wild
public boolean isShallowWild()
Shallow wild ChannelId
s end with a single wild character "*"
and match
non wild channels with
the same depth
.
Example: /foo/*
matches /foo/bar
, but not /foo/bar/baz
.
ChannelId
is a shallow wild channel idpublic boolean isDeepWild()
Deep wild ChannelId
s end with a double wild character "**"
and match
non wild channels with
the same or greater depth
.
Example: /foo/**
matches /foo/bar
and /foo/bar/baz
.
ChannelId
is a deep wild channel idpublic boolean isMeta()
A ChannelId
is a meta ChannelId
if it starts with "/meta/"
.
public boolean isService()
A ChannelId
is a service ChannelId
if it starts with "/service/"
.
public boolean isBroadcast()
public boolean isTemplate()
ChannelId
is a template, that is it contains segments
that identify a variable name between braces, such as /foo/{var_name}
.bind(ChannelId)
,
getParameters()
public List<String> getParameters()
isTemplate()
public boolean matches(ChannelId channelId)
Tests whether this ChannelId
matches the given ChannelId
.
If the given ChannelId
is wild
,
then it matches only if it is equal to this ChannelId
.
If this ChannelId
is non-wild,
then it matches only if it is equal to the given ChannelId
.
Otherwise, this ChannelId
is either shallow or deep wild, and
matches ChannelId
s with the same number of equal segments (if it is
shallow wild), or ChannelId
s with the same or a greater number of
equal segments (if it is deep wild).
channelId
- the channelId to matchChannelId
matches the given ChannelId
public Map<String,String> bind(ChannelId target)
If this ChannelId
is a template, and the given target
ChannelId
is non-wild and non-template, and the two have the same depth()
, then binds
the variable(s) defined in this template with the values of the segments defined by
the target ChannelId
.
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
.
target
- the non-wild, non-template ChannelId
to bindisTemplate()
public int depth()
ChannelId
is made ofgetSegment(int)
public boolean isAncestorOf(ChannelId id)
id
- the channel to testChannelId
is an ancestor of the given ChannelId
isParentOf(ChannelId)
public boolean isParentOf(ChannelId id)
id
- the channel to testChannelId
is the parent of the given ChannelId
isAncestorOf(ChannelId)
public String getParent()
ChannelId
,
or null if this ChannelId
has only one segmentisParentOf(ChannelId)
public String getSegment(int i)
i
- the segment indexdepth()
@Deprecated public List<String> getWilds()
getWildIds()
insteadpublic List<String> 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.
public List<String> getAllIds()
getId()
,
getWildIds()
public String 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:
Channel | Regular Part |
---|---|
/foo | /foo |
/foo/* | /foo |
/foo/bar/** | /foo/bar |
/foo/{p} | /foo |
/foo/bar/{p} | /foo/bar |
/* | null |
/** | null |
/{p} | null |
public static boolean isMeta(String channelId)
Helper method to test if the string form of a ChannelId
represents a meta
ChannelId
.
channelId
- the channel id to testpublic static boolean isService(String channelId)
Helper method to test if the string form of a ChannelId
represents a service
ChannelId
.
channelId
- the channel id to testCopyright © 2008–2024 The CometD Project. All rights reserved.