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

com.davidbracewell.enum_value.template Maven / Gradle / Ivy

Go to download

Annotation processors for DynamicEnums to automatically create boilerplate code.

There is a newer version: 0.3
Show newest version
import com.davidbracewell.DynamicEnum;
import com.davidbracewell.EnumValue;
import com.davidbracewell.string.StringUtils;

import java.io.ObjectStreamException;
import java.util.Collection;

$JAVADOC
public final class $TYPE_NAME extends EnumValue $IMPLEMENTS {

  private static final DynamicEnum<$TYPE_NAME> index = new DynamicEnum<>();
  private static final long serialVersionUID = 1L;

  private $TYPE_NAME(String name) {
    super(name);
  }

  /**
   * Creates a new $TYPE_NAME Type or retrieves an already existing one for a given name
   *
   * @param name the name
   * @return the $TYPE_NAME type
   */
  public static $TYPE_NAME create(String name) {
    if (StringUtils.isNullOrBlank(name)) {
      throw new IllegalArgumentException(name + " is invalid");
    }
    return index.register(new $TYPE_NAME(name));
  }

  /**
   * Determine if an $TYPE_NAME exists for the given name
   *
   * @param name the name
   * @return True if it exists, otherwise False
   */
  public static boolean isDefined(String name) {
    return index.isDefined(name);
  }

  /**
   * Gets the $TYPE_NAME from its name. Throws an IllegalArgumentException if the name is not valid.
   *
   * @param name the name as a string
   * @return the $TYPE_NAME for the string
   */
  public static $TYPE_NAME valueOf(String name) {
    return index.valueOf(name);
  }

  /**
   * Returns the values for this dynamic enum
   *
   * @return All known $TYPE_NAME
   */
  public static Collection<$TYPE_NAME> values() {
    return index.values();
  }

  private Object readResolve() throws ObjectStreamException {
    if (isDefined(name())) {
      return index.valueOf(name());
    }
    Object o = index.register(this);
    return o;
  }


}//END OF $TYPE_NAME




© 2015 - 2025 Weber Informatics LLC | Privacy Policy