public interface Label
Node
where all nodes having a label
are part of the same group. Labels on nodes are optional and any node can
have an arbitrary number of labels attached to it.
Objects of classes implementing this interface can be used as label
representations in your code.
It's very important to note that a label is uniquely identified
by its name, not by any particular instance that implements this interface.
This means that the proper way to check if two labels are equal
is by invoking equals()
on their names
, NOT by
using Java's identity operator (==
) or equals()
on
the Label
instances. A consequence of this is that you can NOT
use Label
instances in hashed collections such as
HashMap
and HashSet
.
However, you usually want to check whether a specific node
instance has a certain label. That is best achieved with the
Node.hasLabel(Label)
method.
For labels that your application know up front you should specify using an enum,
and since the name is accessed using the name()
method it fits nicely.
public enum MyLabels implements Label
{
PERSON,
RESTAURANT;
}
For labels that your application don't know up front you can make use of
label(String)
, or your own implementation of this interface,
as it's just the name that matters.
Node
Modifier and Type | Method and Description |
---|---|
static Label |
label(String name)
Instantiates a new Label with the given name.
|
String |
name()
Returns the name of the label.
|
String name()
equal
names.static Label label(String name)
name
- the name of the labelLabel
instance for the given nameIllegalArgumentException
- if name is null
Copyright © 2002–2016 The Neo4j Graph Database Project. All rights reserved.