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

com.rapleaf.jack.store.field.JsEnumNameField Maven / Gradle / Ivy

package com.rapleaf.jack.store.field;

import java.util.function.BiFunction;
import java.util.function.Function;

import com.rapleaf.jack.store.JsRecord;
import com.rapleaf.jack.store.iface.InsertValue;

/**
 * Convert enum to name using {@link Enum#name}
 * Convert name to enum using {@link Enum#valueOf}
 */
public class JsEnumNameField> extends AbstractJsField {

  JsEnumNameField(String key, Function nameToEnumFunction, InsertValue putMethod, BiFunction getMethod) {
    super(key, convertPutMethod(putMethod), convertGetMethod(nameToEnumFunction, getMethod));
  }

  private static  InsertValue convertPutMethod(InsertValue putMethod) {
    return (executor, key, value) -> putMethod.apply(executor, key, value.name());
  }

  private static > BiFunction convertGetMethod(Function nameToEnumFunction, BiFunction getMethod) {
    return (record, key) -> {
      String enumName = getMethod.apply(record, key);
      return nameToEnumFunction.apply(enumName);
    };
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy