Class AbstractTrait
- All Implemented Interfaces:
FromSourceLocation
,ToNode
,ToShapeId
,Trait
- Direct Known Subclasses:
ArnReferenceTrait
,ArnTrait
,AuthDefinitionTrait
,AuthorizersTrait
,AuthTrait
,AwsProtocolTrait
,AwsQueryErrorTrait
,CfnResourceTrait
,ClientContextParamsTrait
,ClientDiscoveredEndpointTrait
,ClientEndpointDiscoveryTrait
,CognitoUserPoolsTrait
,ContextParamTrait
,CorsTrait
,DefaultTrait
,DefineConditionKeysTrait
,DeprecatedTrait
,DynamicTrait
,EndpointRuleSetTrait
,EndpointTestsTrait
,EndpointTrait
,EnumTrait
,EnumValueTrait
,ExamplesTrait
,ExternalDocumentationTrait
,HttpApiKeyAuthTrait
,HttpChecksumTrait
,HttpErrorTrait
,HttpMalformedRequestTestsTrait
,HttpRequestTestsTrait
,HttpResponseTestsTrait
,HttpTrait
,IamActionTrait
,IamResourceTrait
,IdRefTrait
,IntegrationTrait
,LengthTrait
,MixinTrait
,MockIntegrationTrait
,OriginalShapeIdTrait
,PaginatedTrait
,PropertyTrait
,ProtocolDefinitionTrait
,RangeTrait
,RecommendedTrait
,ReferencesTrait
,RequestCompressionTrait
,RetryableTrait
,ServiceTrait
,SigV4Trait
,SmokeTestsTrait
,SpecificationExtensionTrait
,StandardPartitionalEndpointsTrait
,StandardRegionalEndpointsTrait
,StaticContextParamsTrait
,StringListTrait
,StringTrait
,TagEnabledTrait
,TaggableTrait
,TraitDefinition
,WaitableTrait
,XmlNamespaceTrait
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Basic provider implementation that returns the name of the provided trait. -
Constructor Summary
ConstructorDescriptionAbstractTrait
(ShapeId id, FromSourceLocation sourceLocation) AbstractTrait
(ShapeId id, Node nodeValue) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Node
The result of toNode is used for hashCodes and equality.boolean
final SourceLocation
Gets the source location of a value.int
hashCode()
protected final void
setNodeCache
(Node value) Sets the node cache of the trait up front, if known.final Node
toNode()
Converts a value to aNode
.final ShapeId
Gets the shape ID of the trait.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.amazon.smithy.model.traits.Trait
isSynthetic
-
Constructor Details
-
AbstractTrait
- Parameters:
id
- ID of the trait.sourceLocation
- Where the trait was defined.
-
AbstractTrait
- Parameters:
id
- ID of the trait.nodeValue
- The node representation of the shape, if known and trusted.
-
-
Method Details
-
toShapeId
Description copied from interface:Trait
Gets the shape ID of the trait. -
getSourceLocation
Description copied from interface:FromSourceLocation
Gets the source location of a value.- Specified by:
getSourceLocation
in interfaceFromSourceLocation
- Returns:
- Returns the source location of the value.
-
toString
-
equals
-
hashCode
public int hashCode() -
toNode
Description copied from interface:ToNode
Converts a value to aNode
. -
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
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.
-