View Javadoc
1   package org.csveed.bean.conversion;
2   
3   import java.util.regex.Matcher;
4   import java.util.regex.Pattern;
5   
6   public class Coordinate {
7   
8       private final Integer x;
9   
10      private final Integer y;
11  
12      public Coordinate(Integer x, Integer y) {
13          this.x = x;
14          this.y = y;
15      }
16  
17      public Integer getX() {
18          return x;
19      }
20  
21      public Integer getY() {
22          return y;
23      }
24  
25      public static Coordinate fromString(String coordinateText) {
26          Pattern r = Pattern.compile("(\\d+)/(\\d+)");
27          Matcher m = r.matcher(coordinateText);
28          if (m.find()) {
29              return new Coordinate(
30                      Integer.parseInt(m.group(1)),
31                      Integer.parseInt(m.group(2))
32              );
33          }
34          return null;
35      }
36  
37      @Override
38      public String toString() {
39          return x + "/" + y;
40      }
41  
42  }