Subversion Repository Public Repository

litesoft

Diff Revisions 811 vs 819 for /trunk/Java/core/Anywhere/src/org/litesoft/core/util/UtilsCommon.java

Diff revisions: vs.
  @@ -3,7 +3,6 @@
3 3
4 4 import java.sql.*;
5 5 import java.util.*;
6 - import java.util.Date;
7 6
8 7 import org.litesoft.charstreams.*;
9 8 import org.litesoft.core.simpletypes.nonpublic.*;
  @@ -21,16 +20,6 @@
21 20 {
22 21 }
23 22
24 - public static Date now()
25 - {
26 - return new Date();
27 - }
28 -
29 - public static Timestamp nowTS()
30 - {
31 - return new Timestamp( now().getTime() );
32 - }
33 -
34 23 public static <T extends Enum<T>> T enumFromString( Class<T> pClass, String pEnumAsString )
35 24 {
36 25 if ( pClass != null )
  @@ -66,60 +55,6 @@
66 55 | (pValidBitsOfNewBitFlags & pNewBitFlags);
67 56 }
68 57
69 - public static Boolean toBoolean( String pInput )
70 - {
71 - if ( "YES".equalsIgnoreCase( pInput ) || "Y".equalsIgnoreCase( pInput ) || "TRUE".equalsIgnoreCase( pInput ) || "T".equalsIgnoreCase( pInput ) )
72 - {
73 - return Boolean.TRUE;
74 - }
75 - if ( "NO".equalsIgnoreCase( pInput ) || "N".equalsIgnoreCase( pInput ) || "FALSE".equalsIgnoreCase( pInput ) || "F".equalsIgnoreCase( pInput ) )
76 - {
77 - return Boolean.FALSE;
78 - }
79 - return null;
80 - }
81 -
82 - /**
83 - * Returns a String that represents <i>pThis</i> with english code tail,
84 - * such as "3rd".<p>
85 - * <p/>
86 - * If <i>pThis</i> is non-negative, then append on the appropriate two
87 - * letter <i>english</i> code:<p>
88 - * <pre>
89 - * st,nd,rd,th
90 - * </pre><p>
91 - *
92 - * @param pThis the int to convert.<p>
93 - *
94 - * @return the String representation for <i>pThis</i> and if not negative,
95 - * then appended with the appropriate two letter <i>english</i>
96 - * junk.<p>
97 - */
98 - public static String toNth( int pThis )
99 - {
100 - String rv = Integer.toString( pThis );
101 - if ( pThis < 0 )
102 - {
103 - return rv;
104 - }
105 -
106 - if ( (pThis < 10) || ('1' != rv.charAt( rv.length() - 2 )) ) // not: 10-19 & 110-119, 210-219, ... 1010-1019, ...
107 - {
108 - switch ( rv.charAt( rv.length() - 1 ) )
109 - {
110 - case '1':
111 - return rv + "st";
112 - case '2':
113 - return rv + "nd";
114 - case '3':
115 - return rv + "rd";
116 - default: // 0th and n0th and 4th - 9th and n4th - n9th
117 - break;
118 - }
119 - }
120 - return rv + "th";
121 - }
122 -
123 58 public static String cvtTextForDisplay( String pText )
124 59 {
125 60 if ( pText == null )
  @@ -177,80 +112,6 @@
177 112 return them;
178 113 }
179 114
180 - public static boolean checkIndex( int pIndex, int pMax, boolean pInclusive )
181 - {
182 - return ((0 <= pIndex) && (pIndex < pMax)) || (pInclusive && (pIndex == pMax));
183 - }
184 -
185 - public static void validateIndex( int pIndex, int pMax, boolean pInclusive )
186 - throws IllegalArgumentException
187 - {
188 - if ( !checkIndex( pIndex, pMax, pInclusive ) )
189 - {
190 - throw new IllegalArgumentException( "!( 0 <= " + pIndex + " " + (pInclusive ? "<=" : "<") + " " + pMax + " )" );
191 - }
192 - }
193 -
194 - /**
195 - * return pIndex constained between 0 (inclusive) and pMax (pInclusive). If the effective 'max' is less than 0, then 0 will be returned.
196 - */
197 - public static int constrainIndex( int pIndex, int pMax, boolean pInclusive )
198 - {
199 - if ( (pMax <= pIndex) || (pInclusive && (pIndex == pMax)) )
200 - {
201 - pIndex = pInclusive ? pMax : pMax - 1;
202 - }
203 - return (pIndex < 0) ? 0 : pIndex;
204 - }
205 -
206 - public static String getMax2PlacePercentage( int pPortions )
207 - {
208 - if ( pPortions == 0 )
209 - {
210 - return null;
211 - }
212 - int portion = 10000 / pPortions;
213 - String s = "" + portion;
214 - while ( s.length() < 3 )
215 - {
216 - s = "0" + s;
217 - }
218 - int wholeLen = s.length() - 2;
219 - s = s.substring( 0, wholeLen ) + "." + s.substring( wholeLen );
220 - while ( s.charAt( s.length() - 1 ) == '0' )
221 - {
222 - s = s.substring( 0, s.length() - 1 );
223 - }
224 - if ( s.charAt( s.length() - 1 ) == '.' )
225 - {
226 - s = s.substring( 0, s.length() - 1 );
227 - }
228 - return s + "%";
229 - }
230 -
231 - public static String appendNonEmpties( String pExisting, String pSeparator, String pToAppend )
232 - {
233 - if ( Strings.isNullOrEmpty( pToAppend ) )
234 - {
235 - return Strings.deNull( pExisting ).trim();
236 - }
237 - if ( Strings.isNullOrEmpty( pExisting ) )
238 - {
239 - return pToAppend.trim();
240 - }
241 - return pExisting.trim() + Strings.deNull( pSeparator ) + pToAppend.trim();
242 - }
243 -
244 - public static boolean areNonArraysEqual( boolean pThis, boolean pThat )
245 - {
246 - return (pThis == pThat);
247 - }
248 -
249 - public static boolean areNonArraysEqual( int pThis, int pThat )
250 - {
251 - return (pThis == pThat);
252 - }
253 -
254 115 public static boolean isEmptyString( Object pObject )
255 116 {
256 117 return pObject == null || ((pObject instanceof String) && Strings.isBlank( (String) pObject ));
  @@ -261,19 +122,14 @@
261 122 return isEmptyString( pThis ) && isEmptyString( pThat );
262 123 }
263 124
264 - public static boolean isBooleanNotTrue( Object pObject )
265 - {
266 - return pObject == null || Boolean.FALSE.equals( pObject );
267 - }
268 -
269 125 public static boolean areBothBooleanNotTrue( Object pThis, Object pThat )
270 126 {
271 - return isBooleanNotTrue( pThis ) && isBooleanNotTrue( pThat );
127 + return Booleans.isBooleanNotTrue( pThis ) && Booleans.isBooleanNotTrue( pThat );
272 128 }
273 129
274 130 public static boolean isNullEquivalent( Object pObject )
275 131 {
276 - return isEmptyString( pObject ) || isBooleanNotTrue( pObject );
132 + return isEmptyString( pObject ) || Booleans.isBooleanNotTrue( pObject );
277 133 }
278 134
279 135 public static boolean areBothNullEquivalent( Object pThis, Object pThat )
  @@ -295,11 +151,6 @@
295 151 return (pThis instanceof int[]) && (pThat instanceof int[]) && Integers.areArraysEqual( (int[]) pThis, (int[]) pThat );
296 152 }
297 153
298 - public static int insureNonNegative( int pValue )
299 - {
300 - return (pValue < 0) ? 0 : pValue;
301 - }
302 -
303 154 public static String deNullToString( Object value, Object defaultValue )
304 155 {
305 156 return Strings.deNull( noEmptyToString( value ), noEmptyToString( defaultValue ) );
  @@ -310,11 +161,6 @@
310 161 return Strings.noEmpty( Strings.nullOKtoString( value ) );
311 162 }
312 163
313 - public static int intValue( Integer pInteger, int pDefault )
314 - {
315 - return (pInteger != null) ? pInteger : pDefault;
316 - }
317 -
318 164 public static String trimToLength( String pSource, int pMaxAcceptableLength )
319 165 throws IllegalArgumentException
320 166 {