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
146
147
148
149
150
151
152
package org.litesoft.prioritizer.client.support;

public enum PriorityGroup {
    Initial( 0 ),
    Low( 2000, 0, false ),
    MediumLow( 4000, 2000 ),
    Medium( 6000, 4000 ),
    MediumHigh( 8000, 6000 ),
    High( 9990, 8000 ),
    Critical( 10000, 9990 );

    public static final float TOP_EXCLUSIVE_VALUE = 10000f;
    public static final float BOTTOM_INCLUSIVE_VALUE = 0f;

    private float mRangeTop;
    private boolean mTopInclusive;
    private float mRangeBottom;
    private boolean mBottomInclusive;

    public PriorityGroup higherGroup() {
        return (Critical == this) ? this : values()[ordinal() + 1];
    }

    public static PriorityGroup from( Float pValue ) {
        if ( (pValue == null) || (pValue < BOTTOM_INCLUSIVE_VALUE) ) {
            return Initial;
        }
        for ( PriorityGroup zValue : values() ) {
            if ( zValue.isInRange( pValue ) ) {
                return zValue;
            }
        }
        return Critical;
    }

    PriorityGroup( float pRangeTop, boolean pTopInclusive, float pRangeBottom, boolean pBottomInclusive ) {
        mRangeTop = pRangeTop;
        mTopInclusive = pTopInclusive;
        mRangeBottom = pRangeBottom;
        mBottomInclusive = pBottomInclusive;
    }

    PriorityGroup( float pRangeTop, float pRangeBottom, boolean pBottomInclusive ) {
        this( pRangeTop, false, pRangeBottom, pBottomInclusive );
    }

    PriorityGroup( float pRangeTop, float pRangeBottom ) {
        this( pRangeTop, pRangeBottom, true );
    }

    PriorityGroup( float pRangeValue ) {
        this( pRangeValue, true, pRangeValue, true );
    }

    public float getRangeTop() {
        return mRangeTop;
    }

    public boolean isTopInclusive() {
        return mTopInclusive;
    }

    public float getRangeBottom() {
        return mRangeBottom;
    }

    public boolean isBottomInclusive() {
        return mBottomInclusive;
    }

    public float getMidRange() {
        return (getRangeTop() + getRangeBottom()) / 2;
    }

    public boolean isInRange( float pValue ) {
        return isNotTooSmall( pValue ) && isNotTooLarge( pValue );
    }

    public Range getRangeAssumingExclusive() {
        return new Range( getRangeBottom(), getRangeTop() );
    }

    public static PriorityGroup deNull( PriorityGroup pGroup, PriorityGroup pDefault ) {
        return (pGroup != null) ? pGroup : pDefault;
    }

    /**
     * @param pValues - are !null & are NOT to be decending in value between any two sequential pairs
     */
    public static float[] rePrioritizeBetween( Float pBottomExclusive, Float pTopExclusive, Float... pValues ) {
        return new Range( pBottomExclusive, pTopExclusive ).update().rePrioritizeBetween( pValues );
    }

    private boolean isNotTooLarge( float pValue ) {
        return mTopInclusive ? (pValue <= mRangeTop) : (pValue < mRangeTop);
    }

    private boolean isNotTooSmall( float pValue ) {
        return mBottomInclusive ? (mRangeBottom <= pValue) : (mRangeBottom < pValue);
    }

    public static class Range {
        private float mBottomExclusive, mTopExclusive;

        public Range( Float pBottomExclusive, Float pTopExclusive ) {
            mBottomExclusive = normalize( pBottomExclusive, BOTTOM_INCLUSIVE_VALUE );
            mTopExclusive = normalize( pTopExclusive, TOP_EXCLUSIVE_VALUE );

            if ( mTopExclusive <= mBottomExclusive ) {
                throw new IllegalArgumentException( "Bottom (" + mBottomExclusive + ") must be less than Top (" + mTopExclusive + ")" );
            }
        }

        private static float normalize( Float pValue, float pDefault ) {
            return (pValue != null) && (BOTTOM_INCLUSIVE_VALUE <= pValue) && (pValue < TOP_EXCLUSIVE_VALUE) ? pValue : pDefault;
        }

        public float getTopExclusive() {
            return mTopExclusive;
        }

        public float getBottomExclusive() {
            return mBottomExclusive;
        }

        public Range update() {
            PriorityGroup zGroup = from( mBottomExclusive );
            if ( mBottomExclusive == zGroup.getRangeTop() ) {
                zGroup = zGroup.higherGroup();
                mBottomExclusive = zGroup.getRangeBottom();
            }
            if ( zGroup != from( mTopExclusive ) ) {
                mTopExclusive = zGroup.getRangeTop();
            }
            return this;
        }

        /**
         * @param pValues - are !null & are NOT to be decending in value between any two sequential pairs
         */
        public float[] rePrioritizeBetween( Float... pValues ) {
            int zValuesLength = (pValues == null) ? 0 : pValues.length;
            float[] rvs = new float[zValuesLength];
            float zDelta = (mTopExclusive - mBottomExclusive) / (zValuesLength + 1);
            float zRunningValue = mTopExclusive;
            for ( int i = 0; i < zValuesLength; i++ ) {
                rvs[i] = zRunningValue -= zDelta;
            }
            return rvs;
        }
    }
}

Commits for litesoft/trunk/GWT_Sandbox/Prioritizer/src/org/litesoft/prioritizer/client/support/PriorityGroup.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

480 Diff Diff GeorgeS picture GeorgeS Sun 04 Sep, 2011 02:38:20 +0000

Progress on common User Support...

398 GeorgeS picture GeorgeS Mon 15 Aug, 2011 19:57:47 +0000