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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.core.util;

import org.litesoft.commonfoundation.base.*;

abstract class NoEqualsBase<E, C extends Comparable<C>>
{
    protected final NoEqualsHelper<E, C> mHelper;

    protected NoEqualsBase( NoEqualsHelper<E, C> pHelper )
    {
        mHelper = pHelper;
    }

    @SuppressWarnings({"unchecked"})
    protected static final class Wrapper<E, C extends Comparable<C>> implements Comparable<Wrapper<E, C>>
    {
        private final NoEqualsHelper<E, C> mHelper;
        private final E mObjectWithProxyValue;

        public Wrapper( NoEqualsHelper<E, C> pHelper, E pObjectWithProxyValue )
        {
            mHelper = pHelper;
            mObjectWithProxyValue = pObjectWithProxyValue;
        }

        public E getObject()
        {
            return mObjectWithProxyValue;
        }

        public C getProxyValue()
        {
            return mHelper.getProxyValue( mObjectWithProxyValue );
        }

        @Override
        public boolean equals( Object them )
        {
            return (this == them) || ((them != null) && //
                                      this.getClass().equals( them.getClass() ) && //
                                      LLNotNullEquals( (Wrapper<E, C>) them ));
        }

        public boolean equals( Wrapper<E, C> them )
        {
            return (this == them) || ((them != null) && //
                                      LLNotNullEquals( them ));
        }

        private boolean LLNotNullEquals( Wrapper<E, C> them )
        {
            return areEqual( this.getProxyValue(), them.getProxyValue() );
        }

        @Override
        public int hashCode()
        {
            Comparable<?> zProxyValue = getProxyValue();
            return (zProxyValue == null) ? 0 : zProxyValue.hashCode();
        }

        @Override
        public int compareTo( Wrapper<E, C> them )
        {
            return compare( this.getProxyValue(), them.getProxyValue() );
        }

        @Override
        public String toString()
        {
            return mObjectWithProxyValue.toString();
        }

        /**
         * @return >0, 0, <0 as pThis > pThem, pThis == pThem, pThis < pThem
         */
        private int compare( C pThis, C pThem )
        {
            if ( pThis == pThem )
            {
                return 0; // the same (or both null)
            }
            if ( pThis == null ) // null - !null
            {
                return -1;
            }
            if ( pThem == null ) // !null - null
            {
                return 1;
            }
            return pThis.compareTo( pThem );
        }
    }

    @SuppressWarnings("unchecked")
    protected Wrapper<E, C>[] array( int pSize )
    {
        return new Wrapper[pSize];
    }

    protected Wrapper<E, C> wrap( E pObject )
    {
        return new Wrapper<E, C>( mHelper, pObject );
    }

    protected E unwrap( Wrapper<E, C> pWrapper )
    {
        return (pWrapper != null) ? pWrapper.mObjectWithProxyValue : null;
    }

    protected Wrapper<E, C> wrapNotNull( E pObject )
    {
        validateNotNull( pObject );
        return wrap( pObject );
    }

    protected void validateNotNull( Object o )
    {
        if ( o == null )
        {
            throw new NullPointerException();
        }
    }

    protected E castNotNull( Object o )
    {
        validateNotNull( o );
        if ( mHelper.isInstance( o ) )
        {
            return castNullOK( o );
        }
        throw new ClassCastException( "Unexpected object type '" + o.getClass() + "', expected '" + mHelper.getObjectType() + "' from object: " + o );
    }

    protected E castNullOK( Object o )
    {
        return Cast.it( o );
    }

    protected static boolean areEqual( Object p1, Object p2 )
    {
        return (p1 == p2) || ((p1 != null) && p1.equals( p2 ));
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/util/NoEqualsBase.java

Diff revisions: vs.
Revision Author Commited Message
947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

822 Diff Diff GeorgeS picture GeorgeS Sun 19 Aug, 2012 01:03:51 +0000
726 Diff Diff GeorgeS picture GeorgeS Thu 14 Jun, 2012 13:33:38 +0000
587 Diff Diff GeorgeS picture GeorgeS Fri 02 Dec, 2011 11:55:12 +0000

Accordion...

584 GeorgeS picture GeorgeS Fri 18 Nov, 2011 17:53:52 +0000