MATSIM
utils
objectattributes
attributeconverters
EnumConverter.java
Go to the documentation of this file.
1
2
/* *********************************************************************** *
3
* project: org.matsim.*
4
* EnumConverter.java
5
* *
6
* *********************************************************************** *
7
* *
8
* copyright : (C) 2019 by the members listed in the COPYING, *
9
* LICENSE and WARRANTY file. *
10
* email : info at matsim dot org *
11
* *
12
* *********************************************************************** *
13
* *
14
* This program is free software; you can redistribute it and/or modify *
15
* it under the terms of the GNU General Public License as published by *
16
* the Free Software Foundation; either version 2 of the License, or *
17
* (at your option) any later version. *
18
* See also COPYING, LICENSE and WARRANTY file *
19
* *
20
* *********************************************************************** */
21
22
package
org.matsim.utils.objectattributes.attributeconverters;
23
24
import
org
.
matsim
.
utils
.
objectattributes
.
AttributeConverter
;
25
30
public
class
EnumConverter
<E
extends
Enum<E>> implements
AttributeConverter
<E> {
31
private
final
Class<E>
clazz
;
32
33
public
EnumConverter
(
final
Class<E> clazz ) {
34
this.clazz =
clazz
;
35
}
36
37
@Override
38
public
E
convert
(
final
String value ) {
39
return
Enum.valueOf( clazz , value );
40
}
41
42
@Override
43
public
String
convertToString
(
final
Object o ) {
44
if
(o.getClass() !=
clazz
)
throw
new
IllegalArgumentException(
"got "
+o.getClass().getCanonicalName()+
", expected "
+clazz.getCanonicalName() );
45
return
((Enum) o).name();
46
}
47
}
org
org.matsim.utils
org.matsim.utils.objectattributes
org.matsim.utils.objectattributes.attributeconverters.EnumConverter
Definition:
EnumConverter.java:30
org.matsim.utils.objectattributes.attributeconverters.EnumConverter.convertToString
String convertToString(final Object o)
Definition:
EnumConverter.java:43
org.matsim.utils.objectattributes.attributeconverters.EnumConverter.clazz
final Class< E > clazz
Definition:
EnumConverter.java:31
org.matsim.utils.objectattributes.attributeconverters.EnumConverter.EnumConverter
EnumConverter(final Class< E > clazz)
Definition:
EnumConverter.java:33
org.matsim
org.matsim.utils.objectattributes.attributeconverters.EnumConverter.convert
E convert(final String value)
Definition:
EnumConverter.java:38
org.matsim.utils.objectattributes.AttributeConverter
Definition:
AttributeConverter.java:30
Generated by
1.8.13