Debian Codegraph @

src/uk/me/parabola/imgfmt/app/net/NumberStyle.java

raw symbols SCIP
1 package uk.me.parabola.imgfmt.app.net;
2
3 import uk.me.parabola.log.Logger;
4
5 /**
6 * The number style down one side of a side of a road.
7 *
8 * @author Steve Ratcliffe
9 */
10 public enum NumberStyle {
11 NONE(0), // No numbers.
12
13 EVEN(1) {
14 @Override
15 public int round(int val, int direction) {
16 if ((val & 1) == 1) return val + direction;
17 return val;
18 }
19 }, // Numbers are even on this side of the road.
20
21 ODD(2) {
22 @Override
23 public int round(int val, int direction) {
24 if ((val & 1) == 0) return val + direction;
25 return val;
26 }
27 }, // Numbers are odd on this side of the road
28
29 BOTH(3), // Both odd and even numbers (can also be used for a range of a single number)
30 ;
31
32 private final int val;
33
34 NumberStyle(int val) {
35 this.val = val;
36 }
37
38 public int getVal() {
39 return val;
40 }
41
42 public int round(int val, int direction) {
43 return val;
44 }
45
46 public static NumberStyle fromInt(int n) {
47 switch (n) {
48 case 0: return NONE;
49 case 1: return EVEN;
50 case 2: return ODD;
51 case 3: return BOTH;
52 default: return NONE;
53 }
54 }
55
56 @Override
57 public String toString() {
58 return super.toString().substring(0, 1);
59 }
60
61 public static NumberStyle fromChar(String string) {
62 switch (string.charAt(0)) {
63 case 'N': return NONE;
64 case 'E': return EVEN;
65 case 'O': return ODD;
66 case 'B': return BOTH;
67 case '0':
68 Logger.defaultLogger.error("zero instead of capital O in number spec");
69 return ODD;
70 default: return NONE;
71 }
72 }
73 }