litesoft
@ 939
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.core.simpletypes.nonpublic; import org.litesoft.commonfoundation.base.*; import org.litesoft.commonfoundation.typeutils.*; /** * @noinspection EqualsAndHashcode, deprecation */ public abstract class AbstractXY<T extends AbstractXY> extends CompareSupport<T> implements SimpleType { private /* final */ int mX, mY; @SuppressWarnings({"deprecation", "UnusedDeclaration"}) @Deprecated /** for Serialization */ protected AbstractXY() { } protected AbstractXY( int pX, int pY ) { mX = validate( "X", pX ); mY = validate( "Y", pY ); } public int getX() { return mX; } public int getY() { return mY; } public int hashCode() { return hashCodeEm( calcHashCode( mX ), // calcHashCode( mY ) ); } protected boolean LLequals( AbstractXY them ) { return (this == them) || // ((them != null) // && equal( this.mX, them.mX ) // && equal( this.mY, them.mY ) // ); } /** * Row (Y) then Column (X) */ protected int LLcompareTo( AbstractXY them ) { return compareEm( compare( this.mY, them.mY ), // compare( this.mX, them.mX ) ); } abstract protected int validate( String pWhat, int pValue ); private static IllegalArgumentException populateProblem( String pWhat, String pWhy ) { return new IllegalArgumentException( pWhat + "XY from string value" + pWhy ); } private static int parseValue( String pWhat, String pXorY, String pValue ) { if ( (pValue = pValue.trim()).length() == 0 ) { throw populateProblem( pWhat, ": did not have a '" + pXorY + "' value" ); } try { return Integer.parseInt( pValue ); } catch ( NumberFormatException e ) { throw populateProblem( pWhat, ", '" + pXorY + "' value: " + e.getMessage() ); } } protected T copyParse( String pWhat, String pToString ) { if ( pToString == null ) { throw populateProblem( pWhat, Objects.NOT_ALLOWED_TO_BE_NULL ); } pToString = pToString.trim(); if ( !pToString.startsWith( "(" ) ) { throw populateProblem( pWhat, ": did not start with '('" ); } if ( !pToString.startsWith( "(" ) ) { throw populateProblem( pWhat, ": did not end with ')'" ); } int zCommaAt = pToString.indexOf( ',' ); if ( zCommaAt == -1 ) { throw populateProblem( pWhat, ": No X-Y sep ','" ); } return copy( parseValue( pWhat, "X", pToString.substring( 1, zCommaAt ) ), parseValue( pWhat, "Y", pToString.substring( zCommaAt + 1, pToString.length() - 1 ) ) ); } private T copy( int pX, int pY ) { return Cast.it( ((pX == mX) && (pY == mY)) ? this : clone( pX, pY ) ); } protected abstract AbstractXY clone( int pX, int pY ); public String toString() { return "(" + mX + "," + mY + ")"; } } |
Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/simpletypes/nonpublic/AbstractXY.java
Revision | Author | Commited | Message |
---|---|---|---|
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
917 Diff | GeorgeS | Sun 08 Dec, 2013 20:49:56 +0000 | 1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model! |
849 Diff | GeorgeS | Tue 11 Sep, 2012 17:11:59 +0000 | Clean up serialization |
848 Diff | GeorgeS | Mon 10 Sep, 2012 22:44:31 +0000 | ! |
821 Diff | GeorgeS | Sun 19 Aug, 2012 00:08:41 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |