litesoft
@ 151
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 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.orsup.base; import java.io.*; import org.litesoft.orsup.selection.*; public abstract class PersistentObjectUniqueKey implements Serializable { static final long serialVersionUID = -112354983213548313L; protected static final char NULL_CHAR = '!'; protected static final char DATA_CHAR = '+'; private static final String NULL_STRING = "" + NULL_CHAR; private transient Integer mCachedHashCode = null; private transient String mCachedToString = null; @Override public final boolean equals( Object pThem ) { return (this == pThem) || ((pThem instanceof PersistentObjectUniqueKey) && equalsNotNullNotUs( (PersistentObjectUniqueKey) pThem )); } public final boolean equals( PersistentObjectUniqueKey pThem ) { return (this == pThem) || ((pThem != null) && equalsNotNullNotUs( pThem )); } @Override public final int hashCode() { if ( mCachedHashCode == null ) { mCachedHashCode = calcHashCode(); // Boxing } return mCachedHashCode; // Unboxing } @Override public final String toString() { if ( mCachedToString == null ) { mCachedToString = generateToStringForConstructor(); } return mCachedToString; } public static Long nullifyfromStringToLong( String pIDfromString ) throws IllegalArgumentException { pIDfromString = nullifyfromString( pIDfromString ); return (pIDfromString == null) ? 0L : new Long( pIDfromString ); } public static String nullifyfromString( String pIDfromString ) throws IllegalArgumentException { if ( NULL_STRING.equals( pIDfromString ) ) { return null; } if ( (pIDfromString != null) && (pIDfromString.length() > 0) && (pIDfromString.charAt( 0 ) == DATA_CHAR) ) { return pIDfromString.substring( 1 ); } throw new IllegalArgumentException( "Unacceptable encoding of ID: '" + pIDfromString + "'" ); } protected final String idToString( Object pID ) { return (pID == null) ? NULL_STRING : "" + DATA_CHAR + pID; } abstract protected int calcHashCode(); abstract protected boolean equalsNotNullNotUs( PersistentObjectUniqueKey pThem ); abstract protected String generateToStringForConstructor(); abstract public WhereClause convertToWC(); } |