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