MATSIM
utils
objectattributes
attributeconverters
CoordConverter.java
Go to the documentation of this file.
1
2
/* *********************************************************************** *
3
* project: org.matsim.*
4
* CoordConverter.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
.apache.logging.log4j.LogManager;
25
import
org
.apache.logging.log4j.Logger;
26
import
org
.
matsim
.
api
.
core
.
v01
.
Coord
;
27
import
org
.
matsim
.
utils
.
objectattributes
.
AttributeConverter
;
28
29
public
class
CoordConverter
implements
AttributeConverter
<Coord> {
30
private
final
Logger
log
= LogManager.getLogger(
CoordConverter
.class);
31
32
@Override
33
public
Coord
convert
(String value) {
34
String s = value.replace(
"("
,
""
);
35
s = s.replace(
")"
,
""
);
36
String[] sa = s.split(
";"
);
37
return
new
Coord
(Double.parseDouble(sa[0]), Double.parseDouble(sa[1]));
38
}
39
40
@Override
41
public
String
convertToString
(Object o) {
42
if
(!(o instanceof
Coord
)){
43
log.error(
"Object is not of type Coord: "
+ o.getClass().toString());
44
return
null;
45
}
46
Coord c = (Coord)o;
47
48
return
String.format(
"(%s;%s)"
, Double.toString(c.
getX
()), Double.toString(c.
getY
()));
49
}
50
51
}
org
org.matsim.utils.objectattributes.attributeconverters.CoordConverter.convertToString
String convertToString(Object o)
Definition:
CoordConverter.java:41
org.matsim.utils
org.matsim.utils.objectattributes
org.matsim.api
org.matsim.api.core.v01.Coord
Definition:
Coord.java:35
org.matsim.utils.objectattributes.attributeconverters.CoordConverter
Definition:
CoordConverter.java:29
org.matsim.api.core
org.matsim.api.core.v01.Coord.getX
double getX()
Definition:
Coord.java:86
org.matsim
org.matsim.utils.objectattributes.attributeconverters.CoordConverter.log
final Logger log
Definition:
CoordConverter.java:30
org.matsim.api.core.v01.Coord.getY
double getY()
Definition:
Coord.java:90
org.matsim.api.core.v01
Definition:
BasicLocation.java:20
org.matsim.utils.objectattributes.AttributeConverter
Definition:
AttributeConverter.java:30
org.matsim.utils.objectattributes.attributeconverters.CoordConverter.convert
Coord convert(String value)
Definition:
CoordConverter.java:33
Generated by
1.8.13