|
@@ -1,57 +1,45 @@ |
1 |
1 |
|
package org.litesoft.sandbox.anywhere.die; |
2 |
2 |
|
|
3 |
|
- |
public class Identifier |
4 |
|
- |
{ |
|
3 |
+ |
public class Identifier { |
5 |
4 |
|
private Orientation mOrientation; |
6 |
5 |
|
private int mFace; // 1-6 |
7 |
6 |
|
private int mNorthSide; // 1-6 |
8 |
7 |
|
|
9 |
|
- |
Identifier( Orientation pOrientation, int pFace, int pNorthSide ) |
10 |
|
- |
{ |
|
8 |
+ |
Identifier( Orientation pOrientation, int pFace, int pNorthSide ) { |
11 |
9 |
|
mOrientation = pOrientation; |
12 |
10 |
|
mFace = pFace; |
13 |
11 |
|
mNorthSide = pNorthSide; |
14 |
|
- |
if ( (mFace == mNorthSide) || (mNorthSide == getOppositeSide( mFace )) ) |
15 |
|
- |
{ |
|
12 |
+ |
if ( (mFace == mNorthSide) || (mNorthSide == getOppositeSide( mFace )) ) { |
16 |
13 |
|
throw new IllegalArgumentException( "Invalid Identifier: " + this ); |
17 |
14 |
|
} |
18 |
15 |
|
} |
19 |
16 |
|
|
20 |
|
- |
public Orientation getOrientation() |
21 |
|
- |
{ |
|
17 |
+ |
public Orientation getOrientation() { |
22 |
18 |
|
return mOrientation; |
23 |
19 |
|
} |
24 |
20 |
|
|
25 |
|
- |
public int getFace() |
26 |
|
- |
{ |
|
21 |
+ |
public int getFace() { |
27 |
22 |
|
return mFace; |
28 |
23 |
|
} |
29 |
24 |
|
|
30 |
|
- |
public int getNorthSide() |
31 |
|
- |
{ |
|
25 |
+ |
public int getNorthSide() { |
32 |
26 |
|
return mNorthSide; |
33 |
27 |
|
} |
34 |
28 |
|
|
35 |
29 |
|
@Override |
36 |
|
- |
public String toString() |
37 |
|
- |
{ |
|
30 |
+ |
public String toString() { |
38 |
31 |
|
return "" + mFace + mOrientation + mNorthSide; |
39 |
32 |
|
} |
40 |
33 |
|
|
41 |
|
- |
public static Identifier fromString( String pToString ) |
42 |
|
- |
{ |
43 |
|
- |
if ( pToString != null ) |
44 |
|
- |
{ |
45 |
|
- |
if ( (pToString = pToString.trim()).length() != 0 ) |
46 |
|
- |
{ |
47 |
|
- |
try |
48 |
|
- |
{ |
|
34 |
+ |
public static Identifier fromString( String pToString ) { |
|
35 |
+ |
if ( pToString != null ) { |
|
36 |
+ |
if ( (pToString = pToString.trim()).length() != 0 ) { |
|
37 |
+ |
try { |
49 |
38 |
|
return new Identifier( Orientation.valueOf( pToString.substring( 1, 2 ) ), // |
50 |
39 |
|
parseSide( pToString.substring( 0, 1 ) ), // |
51 |
40 |
|
parseSide( pToString.substring( 2, 3 ) ) ); |
52 |
41 |
|
} |
53 |
|
- |
catch ( RuntimeException e ) |
54 |
|
- |
{ |
|
42 |
+ |
catch ( RuntimeException e ) { |
55 |
43 |
|
throw new IllegalArgumentException( "Not a Die Identifier '" + pToString + "'.", e ); |
56 |
44 |
|
} |
57 |
45 |
|
} |
|
@@ -59,18 +47,15 @@ |
59 |
47 |
|
return null; |
60 |
48 |
|
} |
61 |
49 |
|
|
62 |
|
- |
static int parseSide( String pSideNumber ) |
63 |
|
- |
{ |
|
50 |
+ |
static int parseSide( String pSideNumber ) { |
64 |
51 |
|
int zSideNumber = Integer.parseInt( pSideNumber ); |
65 |
|
- |
if ( (1 <= zSideNumber) && (zSideNumber <= 6) ) |
66 |
|
- |
{ |
|
52 |
+ |
if ( (1 <= zSideNumber) && (zSideNumber <= 6) ) { |
67 |
53 |
|
return zSideNumber; |
68 |
54 |
|
} |
69 |
55 |
|
throw new IllegalArgumentException( "Not a valid Die Side value: " + pSideNumber ); |
70 |
56 |
|
} |
71 |
57 |
|
|
72 |
|
- |
static int getOppositeSide( int pSideNumber ) |
73 |
|
- |
{ |
|
58 |
+ |
static int getOppositeSide( int pSideNumber ) { |
74 |
59 |
|
return 7 - pSideNumber; |
75 |
60 |
|
} |
76 |
61 |
|
} |