View Javadoc
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  import java.util.regex.Matcher;
14  import java.util.regex.Pattern;
15  
16  /**
17   * The Class Coordinate.
18   */
19  public class Coordinate {
20  
21      /** The x. */
22      private final Integer x;
23  
24      /** The y. */
25      private final Integer y;
26  
27      /**
28       * Instantiates a new coordinate.
29       *
30       * @param x
31       *            the x
32       * @param y
33       *            the y
34       */
35      public Coordinate(Integer x, Integer y) {
36          this.x = x;
37          this.y = y;
38      }
39  
40      /**
41       * Gets the x.
42       *
43       * @return the x
44       */
45      public Integer getX() {
46          return x;
47      }
48  
49      /**
50       * Gets the y.
51       *
52       * @return the y
53       */
54      public Integer getY() {
55          return y;
56      }
57  
58      /**
59       * From string.
60       *
61       * @param coordinateText
62       *            the coordinate text
63       *
64       * @return the coordinate
65       */
66      public static Coordinate fromString(String coordinateText) {
67          Pattern r = Pattern.compile("(\\d+)/(\\d+)");
68          Matcher m = r.matcher(coordinateText);
69          if (m.find()) {
70              return new Coordinate(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)));
71          }
72          return null;
73      }
74  
75      @Override
76      public String toString() {
77          return x + "/" + y;
78      }
79  
80  }