public ThriftEnumMetadataBuilder(Class<T> enumClass) { this.enumClass = enumClass; this.enumName = extractEnumName(enumClass); }
/** * Gets the ThriftEnumMetadata for the specified enum class. If the enum class contains a method * annotated with @ThriftEnumValue, the value of this method will be used for the encoded thrift * value; otherwise the Enum.ordinal() method will be used. */ public <T extends Enum<T>> ThriftEnumMetadata<?> getThriftEnumMetadata(Class<?> enumClass) { ThriftEnumMetadata<?> enumMetadata = enums.get(enumClass); if (enumMetadata == null) { enumMetadata = new ThriftEnumMetadataBuilder<>((Class<T>) enumClass).build(); ThriftEnumMetadata<?> current = enums.putIfAbsent(enumClass, enumMetadata); if (current != null) { enumMetadata = current; } } return enumMetadata; }
/** * Gets the ThriftEnumMetadata for the specified enum class. If the enum class contains a method * annotated with @ThriftEnumValue, the value of this method will be used for the encoded thrift * value; otherwise the Enum.ordinal() method will be used. */ public <T extends Enum<T>> ThriftEnumMetadata<?> getThriftEnumMetadata(Class<?> enumClass) { ThriftEnumMetadata<?> enumMetadata = enums.get(enumClass); if (enumMetadata == null) { enumMetadata = new ThriftEnumMetadataBuilder<>((Class<T>) enumClass).build(); ThriftEnumMetadata<?> current = enums.putIfAbsent(enumClass, enumMetadata); if (current != null) { enumMetadata = current; } } return enumMetadata; }
@Test public void testEnum() throws Exception { ThriftEnumMetadata<Fruit> fruitEnumMetadata = new ThriftEnumMetadataBuilder<>(Fruit.class).build(); ThriftEnumMetadata<Letter> letterEnumMetadata = new ThriftEnumMetadataBuilder<>(Letter.class).build(); testRoundTripSerialize(Fruit.CHERRY); testRoundTripSerialize(Letter.C); testRoundTripSerialize(enumType(fruitEnumMetadata), Fruit.CHERRY); testRoundTripSerialize(enumType(letterEnumMetadata), Letter.C); testRoundTripSerialize(list(enumType(fruitEnumMetadata)), ImmutableList.copyOf(Fruit.values())); testRoundTripSerialize(list(enumType(letterEnumMetadata)), ImmutableList.copyOf(Letter.values())); }
public ThriftEnumMetadataBuilder(Class<T> enumClass) { this.enumClass = enumClass; this.enumName = extractEnumName(enumClass); }