View Javadoc

1   /*
2    * Copyright 2006-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sourceforge.domian.test.benchmark;
17  
18  
19  /** Immutable chess piece placing value class. */
20  class ChessPiecePlacing {
21  
22      /* Null-based coordinates */
23      private int x, y;
24  
25      ChessPiecePlacing(final int x, final int y) {
26          this.x = x;
27          this.y = y;
28      }
29  
30      ChessPiecePlacing(final int z) {
31          this.x = z / 8;
32          this.y = z % 8;
33      }
34  
35      public int getX() {
36          return this.x;
37      }
38  
39      public int getY() {
40          return this.y;
41      }
42  
43      @Override
44      public String toString() {
45          StringBuilder builder = new StringBuilder();
46          switch (x) {
47              case 0:
48                  builder.append("A");
49                  break;
50              case 1:
51                  builder.append("B");
52                  break;
53              case 2:
54                  builder.append("C");
55                  break;
56              case 3:
57                  builder.append("D");
58                  break;
59              case 4:
60                  builder.append("E");
61                  break;
62              case 5:
63                  builder.append("F");
64                  break;
65              case 6:
66                  builder.append("G");
67                  break;
68              case 7:
69                  builder.append("H");
70                  break;
71          }
72          builder.append(this.y + 1);
73  
74          return builder.toString();
75      }
76  }