Selector

public final class Selector implements Comparable<Selector>

A zenoh Selector is a string which is the conjunction of an path expression identifying a set of keys and some optional parts allowing to refine the set of Paths and associated Values. Structure of a selector:

/s1/s2/../sn?x>1&y<2&..&z=4(p1=v1;p2=v2;..;pn=vn)#a;x;y;..;z
|          | |            | |                  |  |        |
|-- expr --| |-- filter --| |--- properties ---|  |fragment|

where:

  • expr: is a path expression. I.e. a string similar to a Path but with character ‘*’ allowed. A single ‘*’ matches any set of characters in a path, except ‘/’. While “**” matches any set of characters in a path, including ‘/’. A path expression can be absolute (i.e. starting with a ‘/’) or relative to a Workspace.
  • filter: a list of predicates separated by ‘&’ allowing to perform filtering on the Value associated with the matching keys. Each predicate has the form “field``operator``value” where:
    • field is the name of a field in the value (is applicable and is existing. otherwise the predicate is false)
    • operator is one of a comparison operators: `` , <= , >= , = , !=
    • value is the the value to compare the field’s value with
  • fragment: a list of fields names allowing to return a sub-part of each value. This feature only applies to structured values using a “self-describing” encoding, such as JSON or XML. It allows to select only some fields within the structure. A new structure with only the selected fields will be used in place of the original value.

NOTE: the filters and fragments are not yet supported in current zenoh version.

See also: Workspace.get(Selector), Workspace.subscribe(Selector,Listener)

Constructors

Selector

public Selector(String s)

Create a Selector from a string such as “/zenoh/examples/**?(name=Bob)”.

Parameters:
  • p – the string

Methods

addPrefix

public Selector addPrefix(Path prefix)

Returns a new Selector made of the concatenation of the specified prefix and this Selector.

Parameters:
  • prefix – the prefix to add.
Returns:

a new Selector made of the prefix plus this Selector.

compareTo

public int compareTo(Selector s)

equals

public boolean equals(Object object)

getFilter

public String getFilter()

Return the filter expression of this Selector. I.e. the substring after the ‘?’ character and before the ‘(‘ character (or until end of string).

Returns:the filter expression or an empty string if not present.

getFragment

public String getFragment()

Return the fragment expression of this Selector. I.e. the substring after the ‘#’ character.

Returns:the fragment expression or an empty string if not present.

getOptionalPart

protected String getOptionalPart()

getPath

public String getPath()

Return the path expression of this Selector. I.e. the substring before the ‘?’ character.

Returns:the path expression.

getProperties

public String getProperties()

Return the properties expression of this Selector. I.e. the substring enclosed between ‘(‘ and ‘)’ after the ‘?’ character.

Returns:the properties expression or an empty string if not present.

hashCode

public int hashCode()

isRelative

public boolean isRelative()

Returns true if the Selector is relative (i.e. it doesn’t start with ‘/’)

Returns:true if the Selector is relative.

toString

public String toString()