1 /*
2 * CSVeed (https://github.com/42BV/CSVeed)
3 *
4 * Copyright 2013-2023 CSVeed.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of The Apache Software License,
8 * Version 2.0 which accompanies this distribution, and is available at
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 */
11 package org.csveed.bean.conversion;
12
13 /**
14 * The Class EnumConverter.
15 *
16 * @param <T>
17 * the generic type
18 */
19 public class EnumConverter<T extends Enum> extends AbstractConverter<T> {
20
21 /** The enum class. */
22 public final Class<T> enumClass;
23
24 /**
25 * Instantiates a new enum converter.
26 *
27 * @param enumClass
28 * the enum class
29 */
30 public EnumConverter(Class<T> enumClass) {
31 super(enumClass);
32 this.enumClass = enumClass;
33 }
34
35 @Override
36 public T fromString(String text) throws Exception {
37 return (T) Enum.valueOf(this.enumClass, text);
38 }
39
40 @Override
41 public String toString(T value) throws Exception {
42 return value.toString();
43 }
44
45 }