public abstract class AbstractTrait extends java.lang.Object implements Trait
This implementation provides an equals(java.lang.Object)
and hashCode()
that should work for most traits that extend from this base class. Note
that equality for traits that extend from this type are not based on the
concrete class, but rather the trait name and the trait's ToNode
representation.
The Node value of a trait can be provided when the trait is created
using setNodeCache(Node)
. Note that when setting the node cache,
the equality and hashcode of the trait are impacted because they are by
default based on thetoNode()
value of a trait. This typically
isn't an issue until model transformations are performed that modify a
trait. In these cases, the original node value of the trait might differ
from the updated trait even if they are semantically the same value (for
example, if the only change to the trait is modifying its source location,
or if a property of the trait was explicitly set to false, but false is
omitted when serializing the updated trait to a node value). If this use
case needs to be accounted for, you must override equals and hashCode of
the trait.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractTrait.Provider
Basic provider implementation that returns the name of the
provided trait.
|
Constructor and Description |
---|
AbstractTrait(ShapeId id,
FromSourceLocation sourceLocation) |
AbstractTrait(ShapeId id,
Node nodeValue) |
Modifier and Type | Method and Description |
---|---|
protected abstract Node |
createNode()
The result of toNode is used for hashCodes and equality.
|
boolean |
equals(java.lang.Object other) |
SourceLocation |
getSourceLocation()
Gets the source location of a value.
|
int |
hashCode() |
protected void |
setNodeCache(Node value)
Sets the node cache of the trait up front, if known.
|
Node |
toNode()
Converts a value to a
Node . |
ShapeId |
toShapeId()
Gets the shape ID of the trait.
|
java.lang.String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
flatMapStream, getIdiomaticTraitName, getIdiomaticTraitName, isSynthetic, makeAbsoluteName, makeAbsoluteName
public AbstractTrait(ShapeId id, FromSourceLocation sourceLocation)
id
- ID of the trait.sourceLocation
- Where the trait was defined.public final ShapeId toShapeId()
Trait
public final SourceLocation getSourceLocation()
FromSourceLocation
getSourceLocation
in interface FromSourceLocation
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public final Node toNode()
ToNode
Node
.protected abstract Node createNode()
protected final void setNodeCache(Node value)
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.
value
- Value to set.