All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adgear.anoa.read.ThriftRecordWrapper Maven / Gradle / Ivy

Go to download

Core classes for Anoa library, which aims to be a safe, convenient and fast record de/serialization wrapper for the Avro, Thrift and Jackson libraries, using the functional idioms of Java 8. The anoa-core module tries to keep upstream dependencies to a minimum.

There is a newer version: 3.1.2
Show newest version
package com.adgear.anoa.read;

import com.adgear.anoa.AnoaJacksonTypeException;

import org.apache.thrift.TBase;
import org.apache.thrift.TFieldIdEnum;

import java.util.List;

class ThriftRecordWrapper> {

  final protected T record;
  final protected List> fieldWrappers;
  final protected int nRequired;
  private int n = 0;

  ThriftRecordWrapper(T record, List> fieldWrappers, int nRequired) {
    this.record = record;
    this.fieldWrappers = fieldWrappers;
    this.nRequired = nRequired;
  }

  void put(ThriftFieldWrapper fieldWrapper, Object value) {
    if (fieldWrapper.isRequired) {
      ++n;
    }
    record.setFieldValue(fieldWrapper.tFieldIdEnum, value);
  }

  T get() {
    if (n < nRequired) {
      for (ThriftFieldWrapper fieldWrapper : fieldWrappers) {
        if (fieldWrapper.isRequired && !record.isSet(fieldWrapper.tFieldIdEnum)) {
          throw new AnoaJacksonTypeException(
              "Required field not set: " + fieldWrapper.tFieldIdEnum.getFieldName());
        }
      }
    }
    return record;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy