Class ShapeIndex
- java.lang.Object
-
- software.amazon.smithy.model.shapes.ShapeIndex
-
- All Implemented Interfaces:
software.amazon.smithy.utils.ToSmithyBuilder<ShapeIndex>
public final class ShapeIndex extends java.lang.Object implements software.amazon.smithy.utils.ToSmithyBuilder<ShapeIndex>
Provides an index ofShape
s in a Smithy model byShapeId
.The
ShapeIndex
represents a Smithy model in a flat graph-like index. Shapes reference other shapes by shape ID, and these shape IDs are used then matched with shapes in aShapeIndex
. Using this kind of graph-like structure rather than a something more like a tree allows for a fast iteration over all shapes in a model, allows for shapes to reference other shapes without requiring cyclic references, and maps cleanly to the mental model of a Smithy model definition (that is, shape IDs are used to connect shapes to other shapes, allow traits to be applied to shapes, and are used to suppress validation events). However, this does come with the trade-off that theShapeIndex
may be an an invalid state when it is accessed. As such, aShapeIndex
should be thoroughly validated before it is utilized.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ShapeIndex.Builder
Builder used to construct a ShapeIndex.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ShapeIndex.Builder
builder()
boolean
equals(java.lang.Object other)
java.util.Optional<Shape>
getShape(ShapeId id)
int
hashCode()
java.util.stream.Stream<Shape>
shapes()
Gets a stream ofShape
s in the index.<T extends Shape>
java.util.stream.Stream<T>shapes(java.lang.Class<T> shapeType)
Gets a stream of shapes in the index of a specific typeT
.ShapeIndex.Builder
toBuilder()
java.util.Set<Shape>
toSet()
Converts the ShapeIndex to an immutable Set of shapes.
-
-
-
Method Detail
-
builder
public static ShapeIndex.Builder builder()
-
toBuilder
public ShapeIndex.Builder toBuilder()
- Specified by:
toBuilder
in interfacesoftware.amazon.smithy.utils.ToSmithyBuilder<ShapeIndex>
-
getShape
public java.util.Optional<Shape> getShape(ShapeId id)
- Parameters:
id
- Shape to retrieve by ID.- Returns:
- Returns the optional shape.
-
shapes
public java.util.stream.Stream<Shape> shapes()
Gets a stream ofShape
s in the index.- Returns:
- Returns a stream of shapes.
-
shapes
public <T extends Shape> java.util.stream.Stream<T> shapes(java.lang.Class<T> shapeType)
Gets a stream of shapes in the index of a specific typeT
.The provided shapeType class must exactly match the class of a shape in the shape index in order to be returned from this method; that is, the provided class must be a concrete subclass of
Shape
and not an abstract class likeNumberShape
.- Type Parameters:
T
- Shape type to stream from the index.- Parameters:
shapeType
- Shape typeT
to retrieve.- Returns:
- A stream of shapes of
T
matchingshapeType
.
-
toSet
public java.util.Set<Shape> toSet()
Converts the ShapeIndex to an immutable Set of shapes.- Returns:
- Returns an unmodifiable set of Shapes in the index.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
-