Interface Label


public interface Label
A label is a grouping facility for 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.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static Label
    label(String name)
    Instantiates a new Label with the given name.
    Returns the name of the label.
  • Method Details

    • name

      String name()
      Returns the name of the label. The name uniquely identifies a label, i.e. two different Label instances with different object identifiers (and possibly even different classes) are semantically equivalent if they have equal names.
      Returns:
      the name of the label
    • label

      static Label label(String name)
      Instantiates a new Label with the given name.
      Parameters:
      name - the name of the label
      Returns:
      a Label instance for the given name
      Throws:
      IllegalArgumentException - if name is null