Class AbstractTrait

    • Constructor Detail

      • AbstractTrait

        public AbstractTrait​(ShapeId id,
                             FromSourceLocation sourceLocation)
        Parameters:
        id - ID of the trait.
        sourceLocation - Where the trait was defined.
      • AbstractTrait

        public AbstractTrait​(ShapeId id,
                             Node nodeValue)
        Parameters:
        id - ID of the trait.
        nodeValue - The node representation of the shape, if known and trusted.
    • Method Detail

      • toShapeId

        public final ShapeId toShapeId()
        Description copied from interface: Trait
        Gets the shape ID of the trait.
        Specified by:
        toShapeId in interface ToShapeId
        Specified by:
        toShapeId in interface Trait
        Returns:
        Returns the fully-qualified shape ID of the trait.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toNode

        public final Node toNode()
        Description copied from interface: ToNode
        Converts a value to a Node.
        Specified by:
        toNode in interface ToNode
        Returns:
        Returns the creates Node.
      • createNode

        protected abstract Node createNode()
        The result of toNode is used for hashCodes and equality. Subclasses must implement createNode to turn the trait into a Node. This is then cached for subsequent retrievals.
        Returns:
        Returns the trait as a node.
      • setNodeCache

        protected final void setNodeCache​(Node value)
        Sets the node cache of the trait up front, if known.

        This is useful for maintaining a trait value exactly as provided in a model file, allowing for validation to detect extraneous properties, and removing the need to create the node again when calling createNode.

        Parameters:
        value - Value to set.