Class Relationship
- java.lang.Object
-
- software.amazon.smithy.model.neighbor.Relationship
-
public final class Relationship extends java.lang.Object
Represent a direct relationship between two shapes.A relationship is a connection between two shapes. See
RelationshipType
for documentation on the possible types of relationships.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Relationship
create(Shape shape, RelationshipType relationshipType, Shape neighborShape)
Constructs a valid shape relationship where the neighbor is present.static Relationship
createInvalid(Shape shape, RelationshipType relationshipType, ShapeId neighborShapeId)
Constructs an invalid shape relationship where the neighbor is not present.boolean
equals(java.lang.Object other)
Shape
expectNeighborShape()
Gets the neighbor shape or throws if it doesn't exist.RelationshipDirection
getDirection()
Gets the direction of the relationship.java.util.Optional<Shape>
getNeighborShape()
Gets the optional neighbor shape; the neighbor shape may be empty when the neighbor shape id was not in the model.ShapeId
getNeighborShapeId()
Gets the shape id of the neighbor shape.RelationshipType
getRelationshipType()
Gets the relationship type.java.util.Optional<java.lang.String>
getSelectorLabel()
Gets the token that is used inSelector
expressions when referring to the relationship or an emptyOptional
if this relationship is not used in a selector.Shape
getShape()
Gets the starting shape in the relationship.int
hashCode()
java.lang.String
toString()
-
-
-
Method Detail
-
create
public static Relationship create(Shape shape, RelationshipType relationshipType, Shape neighborShape)
Constructs a valid shape relationship where the neighbor is present.- Parameters:
shape
- The shape the relationship originates from.relationshipType
- The relationshipType of relationship.neighborShape
- The shape the relationship targets.- Returns:
- Returns the created Relationship.
-
createInvalid
public static Relationship createInvalid(Shape shape, RelationshipType relationshipType, ShapeId neighborShapeId)
Constructs an invalid shape relationship where the neighbor is not present.- Parameters:
shape
- The shape the relationship originates from.relationshipType
- The relationshipType of relationship.neighborShapeId
- The shape the relationship targets.- Returns:
- Returns the created Relationship.
-
getShape
public Shape getShape()
Gets the starting shape in the relationship.- Returns:
- Returns the shape the relationship is from.
-
getRelationshipType
public RelationshipType getRelationshipType()
Gets the relationship type.- Returns:
- Returns the relationship type.
-
getNeighborShapeId
public ShapeId getNeighborShapeId()
Gets the shape id of the neighbor shape.- Returns:
- Returns the shape id of the neighbor shape.
-
getNeighborShape
public java.util.Optional<Shape> getNeighborShape()
Gets the optional neighbor shape; the neighbor shape may be empty when the neighbor shape id was not in the model.- Returns:
- Returns the optional neighbor shape.
-
expectNeighborShape
public Shape expectNeighborShape()
Gets the neighbor shape or throws if it doesn't exist.- Returns:
- Returns the neighbor shape.
- Throws:
ExpectationNotMetException
- if the neighbor is missing.
-
getSelectorLabel
public java.util.Optional<java.lang.String> getSelectorLabel()
Gets the token that is used inSelector
expressions when referring to the relationship or an emptyOptional
if this relationship is not used in a selector.- Returns:
- Returns the optionally present selector token for this relationship.
-
getDirection
public RelationshipDirection getDirection()
Gets the direction of the relationship.A
RelationshipDirection.DIRECTED
direction is formed from a shape that defines a reference to another shape (for example, when a resource defines operations or resources it contains).A
RelationshipDirection.INVERTED
relationship is a relationship from a shape to a shape that defines a relationship to it. The target of such a relationship doesn't define the relationship, but is the target of the relationship.- Returns:
- Returns the direction of the relationship.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-