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

cdc.util.prefs.defaults.EnumPreference Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package cdc.util.prefs.defaults;

import java.util.prefs.Preferences;

import cdc.util.prefs.AbstractPreference;

/**
 * Enum preference (node, key) pair.
 *
 * @author Damien Carbonne
 * @param  The enum type.
 */
public class EnumPreference> extends AbstractPreference {
    public EnumPreference(Class valueClass,
                          Preferences node,
                          String key,
                          E def) {
        super(valueClass,
              node,
              key,
              def,
              Object::toString,
              s -> {
                  for (final E value : valueClass.getEnumConstants()) {
                      if (value.toString().equals(s)) {
                          return value;
                      }
                  }
                  return null;
              });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy