Subversion Repository Public Repository

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
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;
    }
}

Commits for litesoft/trunk/GWT_Sandbox/MultiModule/anywhere/src/org/litesoft/sandbox/anywhere/die/Identifier.java

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

540 GeorgeS picture GeorgeS Mon 03 Oct, 2011 04:22:28 +0000