1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002, 2014 Oracle and/or its affiliates.  All rights reserved.
5  *
6  */
7 
8 package com.sleepycat.je.rep.impl;
9 
10 import com.sleepycat.je.config.ConfigParam;
11 
12 /**
13  * A JE configuration parameter with an enumerated value
14  */
15 public class EnumConfigParam<T extends Enum<T>> extends ConfigParam {
16 
17     /* The class denoting the enum type */
18     private final Class<T> enumClass;
19 
EnumConfigParam(String configName, Enum<T> defaultValue, boolean mutable, boolean forReplication, Class<T> enumClass)20     public EnumConfigParam(String configName,
21                            Enum<T> defaultValue,
22                            boolean mutable,
23                            boolean forReplication,
24                            Class<T> enumClass) {
25         super(configName, defaultValue.name(), mutable, forReplication);
26         this.enumClass = enumClass;
27     }
28 
29     /**
30      * Returns the enumerator associated with the name
31      *
32      * @param enumName the string naming the enumerator
33      *
34      * @return the enumerator
35      */
getEnumerator(String enumName)36     public T getEnumerator(String enumName) {
37         return Enum.valueOf(enumClass, enumName);
38     }
39 
40     @Override
validateValue(String value)41     public void validateValue(String value)
42         throws IllegalArgumentException {
43 
44         /*
45          * If validateValue() is called by through the ConfigParam
46          * constructor, enumVal is not assigned yet, so we guard against
47          * that happening.
48          */
49         if (enumClass != null) {
50             Enum.valueOf(enumClass, value);
51         }
52     }
53 }
54