Class EnumShape
- java.lang.Object
-
- software.amazon.smithy.model.shapes.Shape
-
- software.amazon.smithy.model.shapes.SimpleShape
-
- software.amazon.smithy.model.shapes.StringShape
-
- software.amazon.smithy.model.shapes.EnumShape
-
- All Implemented Interfaces:
java.lang.Comparable<Shape>
,FromSourceLocation
,ToShapeId
,Tagged
,ToSmithyBuilder<StringShape>
public final class EnumShape extends StringShape
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EnumShape.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> R
accept(ShapeVisitor<R> cases)
Dispatches the shape to the appropriateShapeVisitor
method.java.util.Optional<EnumShape>
asEnumShape()
static EnumShape.Builder
builder()
static boolean
canConvertToEnum(StringShape shape, boolean synthesizeEnumNames)
Determines whether a given string shape can be converted to an enum shape.java.util.Optional<Trait>
findTrait(ShapeId id)
Attempts to find a trait applied to the shape by name.static java.util.Optional<EnumShape>
fromStringShape(StringShape shape)
Converts a baseStringShape
to anEnumShape
if possible.static java.util.Optional<EnumShape>
fromStringShape(StringShape shape, boolean synthesizeNames)
Converts a baseStringShape
to anEnumShape
if possible.java.util.Map<java.lang.String,MemberShape>
getAllMembers()
Gets the members of the shape, including mixin members.java.util.Map<java.lang.String,java.lang.String>
getEnumValues()
Gets a map of enum member names to their corresponding values.ShapeType
getType()
Gets the type of the shape.EnumShape.Builder
toBuilder()
Take this object and create a builder that contains all of the current property values of this object.-
Methods inherited from class software.amazon.smithy.model.shapes.StringShape
asStringShape
-
Methods inherited from class software.amazon.smithy.model.shapes.Shape
asBigDecimalShape, asBigIntegerShape, asBlobShape, asBooleanShape, asByteShape, asDocumentShape, asDoubleShape, asFloatShape, asIntegerShape, asIntEnumShape, asListShape, asLongShape, asMapShape, asMemberShape, asOperationShape, asResourceShape, asServiceShape, asSetShape, asShortShape, asStructureShape, asTimestampShape, asUnionShape, compareTo, equals, expectTrait, findMemberTrait, findTrait, getAllTraits, getId, getIntroducedTraits, getMember, getMemberNames, getMemberTrait, getMixins, getRequiredMembers, getSourceLocation, getTags, getTrait, hashCode, hasTrait, hasTrait, hasTrait, isBigDecimalShape, isBigIntegerShape, isBlobShape, isBooleanShape, isByteShape, isDocumentShape, isDoubleShape, isEnumShape, isFloatShape, isIntegerShape, isIntEnumShape, isListShape, isLongShape, isMapShape, isMemberShape, isOperationShape, isResourceShape, isServiceShape, isSetShape, isShortShape, isStringShape, isStructureShape, isTimestampShape, isUnionShape, members, shapeToBuilder, toShapeId, toString, validateMemberShapeIds, validateMixins
-
-
-
-
Method Detail
-
getEnumValues
public java.util.Map<java.lang.String,java.lang.String> getEnumValues()
Gets a map of enum member names to their corresponding values.- Returns:
- A map of member names to enum values.
-
getAllMembers
public java.util.Map<java.lang.String,MemberShape> getAllMembers()
Gets the members of the shape, including mixin members.- Overrides:
getAllMembers
in classShape
- Returns:
- Returns the immutable member map.
-
findTrait
public java.util.Optional<Trait> findTrait(ShapeId id)
Description copied from class:Shape
Attempts to find a trait applied to the shape by name.
-
builder
public static EnumShape.Builder builder()
-
toBuilder
public EnumShape.Builder toBuilder()
Description copied from interface:ToSmithyBuilder
Take this object and create a builder that contains all of the current property values of this object.- Specified by:
toBuilder
in interfaceToSmithyBuilder<StringShape>
- Overrides:
toBuilder
in classStringShape
- Returns:
- a builder for type T
-
accept
public <R> R accept(ShapeVisitor<R> cases)
Description copied from class:Shape
Dispatches the shape to the appropriateShapeVisitor
method.- Overrides:
accept
in classStringShape
- Type Parameters:
R
- Return type of the accept.- Parameters:
cases
- ShapeVisitor to use.- Returns:
- Returns the result.
-
asEnumShape
public java.util.Optional<EnumShape> asEnumShape()
- Overrides:
asEnumShape
in classShape
- Returns:
- Optionally returns the shape as a
EnumShape
.
-
fromStringShape
public static java.util.Optional<EnumShape> fromStringShape(StringShape shape, boolean synthesizeNames)
Converts a baseStringShape
to anEnumShape
if possible. The result will be empty if the given shape doesn't have theEnumTrait
, if the enum doesn't have names and name synthesization is disabled, or if a name cannot be synthesized.- Parameters:
shape
- A baseStringShape
to convert.synthesizeNames
- Whether names should be synthesized if possible.- Returns:
- Optionally returns an
EnumShape
equivalent of the given shape.
-
fromStringShape
public static java.util.Optional<EnumShape> fromStringShape(StringShape shape)
Converts a baseStringShape
to anEnumShape
if possible. The result will be empty if the given shape doesn't have theEnumTrait
or if the enum definitions don't have names.- Parameters:
shape
- A baseStringShape
to convert.- Returns:
- Optionally returns an
EnumShape
equivalent of the given shape.
-
canConvertToEnum
public static boolean canConvertToEnum(StringShape shape, boolean synthesizeEnumNames)
Determines whether a given string shape can be converted to an enum shape.- Parameters:
shape
- The string shape to be converted.synthesizeEnumNames
- Whether synthesizing enum names should be accounted for.- Returns:
- Returns true if the string shape can be converted to an enum shape.
-
getType
public ShapeType getType()
Description copied from class:Shape
Gets the type of the shape.- Overrides:
getType
in classStringShape
- Returns:
- Returns the type;
-
-