ThriftFieldGetter extends AbstractFieldGetter<T, V> { @Override @SuppressWarnings("unchecked") public Optional<V> apply(T input) { if (input.isSet(fieldId)) { return Optional.of((V) input.getFieldValue(fieldId)); } else { return Optional.absent(); } } ThriftFieldGetter(Class<T> structClass, F fieldId, Class<V> valueClass); @Override @SuppressWarnings("unchecked") Optional<V> apply(T input);  }
@Test public void testStructFieldGetter() { JobKey jobKey = new JobKey(); FieldGetter<JobConfiguration, JobKey> fieldGetter = new ThriftFieldGetter<>(JobConfiguration.class, _Fields.KEY, JobKey.class); JobConfiguration jobConfiguration = new JobConfiguration().setKey(jobKey); assertSame(jobKey, fieldGetter.apply(jobConfiguration).orNull()); }
@Test public void testStructFieldGetterUnsetField() { FieldGetter<JobConfiguration, TaskConfig> fieldGetter = new ThriftFieldGetter<>(JobConfiguration.class, _Fields.TASK_CONFIG, TaskConfig.class); JobConfiguration jobConfiguration = new JobConfiguration().setInstanceCount(5); assertNull(fieldGetter.apply(jobConfiguration).orNull()); }