Package com.google.protobuf

# Class Descriptors.EnumDescriptor

java.lang.Object
com.google.protobuf.Descriptors.GenericDescriptor
com.google.protobuf.Descriptors.EnumDescriptor

All Implemented Interfaces:
  `Internal.EnumLiteMap<Descriptors.EnumValueDescriptor>`

Enclosing class:
  Descriptors

public static final class Descriptors.EnumDescriptor extends Descriptors.GenericDescriptor implements Internal.EnumLiteMap<Descriptors.EnumValueDescriptor>
Describes an enum type.

## Method Summary

Modifier and Type
Method
Description
`Descriptors.EnumValueDescriptor`
`findValueByName(String name)`
Find an enum value by name.
`Descriptors.EnumValueDescriptor`
`findValueByNumber(int number)`
Find an enum value by number.
`Descriptors.EnumValueDescriptor`
`findValueByNumberCreatingIfUnknown(int number)`
Get the enum value for a number.
`Descriptors.Descriptor`
`getContainingType()`
If this is a nested type, get the outer descriptor, otherwise null.
`Descriptors.FileDescriptor`
`getFile()`
Get the `Descriptors.FileDescriptor` containing this descriptor.
`String`
`getFullName()`
Get the type's fully-qualified name.
`int`
`getIndex()`
Get the index of this descriptor within its parent.
`String`
`getName()`
Get the type's unqualified name.
`DescriptorProtos.EnumOptions`
`getOptions()`
Get the `EnumOptions`, defined in `descriptor.proto`.
`List<Descriptors.EnumValueDescriptor>`
`getValues()`
Get a list of defined values for this enum.
`boolean`
`isClosed()`
Determines if the given enum is closed.
`boolean`
`isReservedName(String name)`
Determines if the given field name is reserved.
`boolean`
`isReservedNumber(int number)`
Determines if the given field number is reserved.
`DescriptorProtos.EnumDescriptorProto`
`toProto()`
Convert the descriptor to its protocol message representation.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### getIndex

public int getIndex()
Get the index of this descriptor within its parent.

See Also:
  - `Descriptors.Descriptor.getIndex()`

### toProto

public DescriptorProtos.EnumDescriptorProto toProto()
Convert the descriptor to its protocol message representation.

Specified by:
  `toProto` in class `Descriptors.GenericDescriptor`

### getName

public String getName()
Get the type's unqualified name.

Specified by:
  `getName` in class `Descriptors.GenericDescriptor`

### getFullName

public String getFullName()
Get the type's fully-qualified name.

Specified by:
  `getFullName` in class `Descriptors.GenericDescriptor`
See Also:
  - `Descriptors.Descriptor.getFullName()`

### getFile

public Descriptors.FileDescriptor getFile()
Get the `Descriptors.FileDescriptor` containing this descriptor.

Specified by:
  `getFile` in class `Descriptors.GenericDescriptor`

### isClosed

public boolean isClosed()
Determines if the given enum is closed.

Closed enum means that it:

- Has a fixed set of values, rather than being equivalent to an int32.
- Encountering values not in this set causes them to be treated as unknown fields.
- The first value (i.e., the default) may be nonzero.

WARNING: Some runtimes currently have a quirk where non-closed enums are treated as closed when used as the type of fields defined in a `syntax = proto2;` file. This quirk is not present in all runtimes; as of writing, we know that:

- C++, Java, and C++-based Python share this quirk.
- UPB and UPB-based Python do not.
- PHP and Ruby treat all enums as open regardless of declaration.

Care should be taken when using this function to respect the target runtime's enum handling quirks.

### getContainingType

public Descriptors.Descriptor getContainingType()
If this is a nested type, get the outer descriptor, otherwise null.

### getOptions

public DescriptorProtos.EnumOptions getOptions()
Get the `EnumOptions`, defined in `descriptor.proto`.

### getValues

public List<Descriptors.EnumValueDescriptor> getValues()
Get a list of defined values for this enum.

### isReservedNumber

public boolean isReservedNumber(int number)
Determines if the given field number is reserved.

### isReservedName

public boolean isReservedName(String name)
Determines if the given field name is reserved.

### findValueByName

public Descriptors.EnumValueDescriptor findValueByName(String name)
Find an enum value by name.

Parameters:
  `name` - the unqualified name of the value such as "FOO"
Returns:
  the value's descriptor, or `null` if not found

### findValueByNumber

public Descriptors.EnumValueDescriptor findValueByNumber(int number)
Find an enum value by number. If multiple enum values have the same number, this returns the first defined value with that number.

Specified by:
  `findValueByNumber` in interface `Internal.EnumLiteMap<Descriptors.EnumValueDescriptor>`
Parameters:
  `number` - The value's number.
Returns:
  the value's descriptor, or `null` if not found.

### findValueByNumberCreatingIfUnknown

public Descriptors.EnumValueDescriptor findValueByNumberCreatingIfUnknown(int number)
Get the enum value for a number. If no enum value has this number, construct an EnumValueDescriptor for it.