{{! Copyright (c) Meta Platforms, Inc. and its affiliates. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. }} {{> AutoGenerated}} package {{enum:javaPackage}}; import com.facebook.swift.codec.*; import org.apache.thrift.TException; import org.apache.thrift.protocol.TProtocol; import com.facebook.thrift.enums.ThriftEnum; import com.google.common.base.MoreObjects; import java.util.HashMap; import java.util.Map; @SwiftGenerated public class {{enum:javaCapitalName}} extends ThriftEnum<{{enum:javaCapitalName}}> { {{#enum:values}} public static final {{enum:javaCapitalName}} {{enum_value:javaConstantName}} = new {{enum:javaCapitalName}}({{enum_value:value}}); {{/enum:values}} {{#enum:values}} public static final int {{enum_value:javaConstantName}}_VALUE = {{enum_value:value}}; {{/enum:values}} public static final int UNRECOGNIZED_VALUE = {{enum:unused}}; private static final Map hm = new HashMap<>(); private static void init() { {{#enum:values}} hm.put({{enum_value:value}}, new Value({{enum:ordinal++}}, "{{enum_value:javaConstantName}}", {{enum_value:javaConstantName}})); {{/enum:values}} hm.put(UNRECOGNIZED_VALUE, new Value({{enum:ordinal++}}, "UNRECOGNIZED", null)); } static { init(); {{#enum:thrift_uri}} com.facebook.thrift.type.TypeRegistry.add(new com.facebook.thrift.type.Type(new com.facebook.thrift.type.UniversalName("{{enum:thrift_uri}}"), {{enum:javaCapitalName}}.class, {{enum:javaCapitalName}}::read0)); {{/enum:thrift_uri}} } private {{enum:javaCapitalName}}(int value) { this.value = value; } private {{enum:javaCapitalName}}(int value, int unrecognizedValue) { this.value = value; this.unrecognizedValue = unrecognizedValue; } @Override public boolean isValueUnrecognized() { return value == UNRECOGNIZED_VALUE; } @Override public int ordinal() { return hm.get(getValue()).ordinal; } @Override public String name() { return hm.get(getValue()).name; } private static final class Value { private int ordinal; private String name; private {{enum:javaCapitalName}} instance; public Value(int ordinal, String name, {{enum:javaCapitalName}} instance) { this.ordinal = ordinal; this.name = name; this.instance = instance; } } public static {{enum:javaCapitalName}} fromInteger(int n) { Value value = hm.get(n); if (value == null) { return new {{enum:javaCapitalName}}(UNRECOGNIZED_VALUE, n); } return value.instance; } @Override public String toString() { MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this); helper.add("value", this.value); helper.add("unrecognizedValue", this.unrecognizedValue); return helper.toString(); } public static com.facebook.thrift.payload.Reader<{{enum:javaCapitalName}}> asReader() { return {{enum:javaCapitalName}}::read0; } public static {{enum:javaCapitalName}} read0(TProtocol iprot) throws TException { return {{enum:javaCapitalName}}.fromInteger(iprot.readI32()); } }