001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package dev.metaschema.core.configuration;
007
008import edu.umd.cs.findbugs.annotations.NonNull;
009
010/**
011 * Provides a complete, abstract implementation of a generalized feature.
012 * Feature implementations can extend this class the implement configuration
013 * sets for a given purpose.
014 *
015 * @param <V>
016 *          the feature value Java type
017 */
018public abstract class AbstractConfigurationFeature<V> implements IConfigurationFeature<V> {
019  @NonNull
020  private final String name;
021  @NonNull
022  private final Class<V> valueClass;
023  @NonNull
024  private final V defaultValue;
025
026  /**
027   * Construct a new feature with a default value.
028   *
029   * @param name
030   *          the name of the feature
031   * @param valueClass
032   *          the class of the feature's value
033   * @param defaultValue
034   *          the value's default
035   */
036  protected AbstractConfigurationFeature(
037      @NonNull String name,
038      @NonNull Class<V> valueClass,
039      @NonNull V defaultValue) {
040    this.name = name;
041    this.valueClass = valueClass;
042    this.defaultValue = defaultValue;
043  }
044
045  @Override
046  public String getName() {
047    return name;
048  }
049
050  @Override
051  public V getDefault() {
052    return defaultValue;
053  }
054
055  @Override
056  public Class<V> getValueClass() {
057    return valueClass;
058  }
059
060  @Override
061  public String toString() {
062    return new StringBuilder()
063        .append(getName())
064        .append('(')
065        .append(getDefault().toString())
066        .append(')')
067        .toString();
068  }
069}