|
@@ -15,41 +15,6 @@ |
15 |
15 |
|
{ |
16 |
16 |
|
} |
17 |
17 |
|
|
18 |
|
- |
public static <T extends Enum<T>> T enumFromString( Class<T> pClass, String pEnumAsString ) |
19 |
|
- |
{ |
20 |
|
- |
if ( pClass != null ) |
21 |
|
- |
{ |
22 |
|
- |
if ( null != (pEnumAsString = Strings.noEmpty( pEnumAsString )) ) |
23 |
|
- |
{ |
24 |
|
- |
try |
25 |
|
- |
{ |
26 |
|
- |
return Enum.valueOf( pClass, pEnumAsString ); |
27 |
|
- |
} |
28 |
|
- |
catch ( IllegalArgumentException ex ) |
29 |
|
- |
{ |
30 |
|
- |
// Bad String |
31 |
|
- |
} |
32 |
|
- |
} |
33 |
|
- |
} |
34 |
|
- |
return null; |
35 |
|
- |
} |
36 |
|
- |
|
37 |
|
- |
/** |
38 |
|
- |
* Calculate the new "AccumulatedBitFlags" by Overriding the appropriate bit flags in |
39 |
|
- |
* pPreviousAccumulatedBitFlags (based on the bits in pValidBitsOfNewBitFlags) from the pNewBitFlags. |
40 |
|
- |
* |
41 |
|
- |
* @param pPreviousAccumulatedBitFlags Bit Flags to be selectively overriden. |
42 |
|
- |
* @param pValidBitsOfNewBitFlags The '1' bits will indicate which bids to override. |
43 |
|
- |
* @param pNewBitFlags The source of the override Bit Flags. |
44 |
|
- |
* |
45 |
|
- |
* @return The new "AccumulatedBitFlags". |
46 |
|
- |
*/ |
47 |
|
- |
public static int mutateAccumulatedBitFlags( int pPreviousAccumulatedBitFlags, int pValidBitsOfNewBitFlags, int pNewBitFlags ) |
48 |
|
- |
{ |
49 |
|
- |
return (pPreviousAccumulatedBitFlags & (~pValidBitsOfNewBitFlags)) // |
50 |
|
- |
| (pValidBitsOfNewBitFlags & pNewBitFlags); |
51 |
|
- |
} |
52 |
|
- |
|
53 |
18 |
|
public static String cvtTextForDisplay( String pText ) |
54 |
19 |
|
{ |
55 |
20 |
|
if ( pText == null ) |
|
@@ -107,292 +72,10 @@ |
107 |
72 |
|
return them; |
108 |
73 |
|
} |
109 |
74 |
|
|
110 |
|
- |
public static boolean isEmptyString( Object pObject ) |
111 |
|
- |
{ |
112 |
|
- |
return pObject == null || ((pObject instanceof String) && Strings.isBlank( (String) pObject )); |
113 |
|
- |
} |
114 |
|
- |
|
115 |
|
- |
public static boolean areBothEmptyStrings( Object pThis, Object pThat ) |
116 |
|
- |
{ |
117 |
|
- |
return isEmptyString( pThis ) && isEmptyString( pThat ); |
118 |
|
- |
} |
119 |
|
- |
|
120 |
|
- |
public static boolean areBothBooleanNotTrue( Object pThis, Object pThat ) |
121 |
|
- |
{ |
122 |
|
- |
return Booleans.isBooleanNotTrue( pThis ) && Booleans.isBooleanNotTrue( pThat ); |
123 |
|
- |
} |
124 |
|
- |
|
125 |
|
- |
public static boolean isNullEquivalent( Object pObject ) |
126 |
|
- |
{ |
127 |
|
- |
return isEmptyString( pObject ) || Booleans.isBooleanNotTrue( pObject ); |
128 |
|
- |
} |
129 |
|
- |
|
130 |
|
- |
public static boolean areBothNullEquivalent( Object pThis, Object pThat ) |
131 |
|
- |
{ |
132 |
|
- |
return isNullEquivalent( pThis ) && isNullEquivalent( pThat ); |
133 |
|
- |
} |
134 |
|
- |
|
135 |
|
- |
public static boolean areEqual( Object pThis, Object pThat ) |
136 |
|
- |
{ |
137 |
|
- |
if ( Objects.areNonArraysEqual( pThis, pThat ) ) |
138 |
|
- |
{ |
139 |
|
- |
return true; |
140 |
|
- |
} |
141 |
|
- |
// Both CAN'T be null |
142 |
|
- |
if ( (pThis instanceof Object[]) && (pThat instanceof Object[]) ) |
143 |
|
- |
{ |
144 |
|
- |
return Objects.areArraysEqual( (Object[]) pThis, (Object[]) pThat ); |
145 |
|
- |
} |
146 |
|
- |
return (pThis instanceof int[]) && (pThat instanceof int[]) && Integers.areArraysEqual( (int[]) pThis, (int[]) pThat ); |
147 |
|
- |
} |
148 |
|
- |
|
149 |
|
- |
public static String deNullToString( Object value, Object defaultValue ) |
150 |
|
- |
{ |
151 |
|
- |
return Strings.deNull( noEmptyToString( value ), noEmptyToString( defaultValue ) ); |
152 |
|
- |
} |
153 |
|
- |
|
154 |
|
- |
public static String noEmptyToString( Object value ) |
155 |
|
- |
{ |
156 |
|
- |
return Strings.noEmpty( Strings.nullOKtoString( value ) ); |
157 |
|
- |
} |
158 |
|
- |
|
159 |
|
- |
public static String combine( String pSeparator, Object... pObjects ) |
160 |
|
- |
{ |
161 |
|
- |
if ( Objects.isNullOrEmpty( pObjects ) ) |
162 |
|
- |
{ |
163 |
|
- |
return null; |
164 |
|
- |
} |
165 |
|
- |
StringBuilder sb = new StringBuilder(); |
166 |
|
- |
|
167 |
|
- |
sb.append( pObjects[0] ); |
168 |
|
- |
|
169 |
|
- |
for ( int i = 1; i < pObjects.length; i++ ) |
170 |
|
- |
{ |
171 |
|
- |
sb.append( pSeparator ); |
172 |
|
- |
sb.append( pObjects[i] ); |
173 |
|
- |
} |
174 |
|
- |
return sb.toString(); |
175 |
|
- |
} |
176 |
|
- |
|
177 |
|
- |
public static void assertNotEqual( String pObjectName, long pNotExpected, long pActual ) |
178 |
|
- |
throws IllegalArgumentException |
179 |
|
- |
{ |
180 |
|
- |
if ( pNotExpected == pActual ) |
181 |
|
- |
{ |
182 |
|
- |
throw new IllegalArgumentException( pObjectName + ": '" + pNotExpected + "' Not allowed" ); |
183 |
|
- |
} |
184 |
|
- |
} |
185 |
|
- |
|
186 |
|
- |
public static void assertTrue( String pValueDescription, boolean pActual ) |
187 |
|
- |
throws IllegalArgumentException |
188 |
|
- |
{ |
189 |
|
- |
if ( !pActual ) |
190 |
|
- |
{ |
191 |
|
- |
throw new IllegalArgumentException( pValueDescription + ": Expected to be true" ); |
192 |
|
- |
} |
193 |
|
- |
} |
194 |
|
- |
|
195 |
|
- |
/** |
196 |
|
- |
* Assert that "value" is not null or when converted to a String is not |
197 |
|
- |
* empty and then return resulting "value" trimmed. |
198 |
|
- |
* |
199 |
|
- |
* @param what "field" was the problem on |
200 |
|
- |
* @param value to check |
201 |
|
- |
* |
202 |
|
- |
* @return value converted to a String minus any leading and trailing spaces |
203 |
|
- |
*/ |
204 |
|
- |
public static String assertNoEmptyToString( String what, Object value ) |
205 |
|
- |
{ |
206 |
|
- |
String strValue = noEmptyToString( value ); |
207 |
|
- |
if ( strValue == null ) |
208 |
|
- |
{ |
209 |
|
- |
Strings.errorNullOrEmpty( what, String.valueOf( Objects.justClassNameOf( value ) ) ); |
210 |
|
- |
} |
211 |
|
- |
return strValue; |
212 |
|
- |
} |
213 |
|
- |
|
214 |
|
- |
/** |
215 |
|
- |
* Assert that "value" is not null or empty (if it is a String) and return |
216 |
|
- |
* "value" trimmed (if it is a String). |
217 |
|
- |
* |
218 |
|
- |
* @param what "field" was the problem on |
219 |
|
- |
* @param value to check |
220 |
|
- |
* |
221 |
|
- |
* @return value minus any leading and trailing spaces |
222 |
|
- |
*/ |
223 |
|
- |
public static <T> T assertNotNullOrEmpty( String what, T value ) |
224 |
|
- |
{ |
225 |
|
- |
if ( value == null ) |
226 |
|
- |
{ |
227 |
|
- |
Strings.errorNullOrEmpty( what, String.valueOf( Objects.justClassNameOf( value ) ) ); |
228 |
|
- |
} |
229 |
|
- |
if ( value instanceof String ) |
230 |
|
- |
{ |
231 |
|
- |
value = cast( Strings.assertNotNullNotEmpty( what, value.toString() ) ); |
232 |
|
- |
} |
233 |
|
- |
return value; |
234 |
|
- |
} |
235 |
|
- |
|
236 |
|
- |
public static String displayFormatFlag( boolean pFlag, String pTrueString ) |
237 |
|
- |
{ |
238 |
|
- |
return pFlag ? pTrueString : ""; |
239 |
|
- |
} |
240 |
|
- |
|
241 |
|
- |
public static boolean endsWithPathSep( String pPath ) |
242 |
|
- |
{ |
243 |
|
- |
return (pPath != null) && Characters.isPathSep( pPath.charAt( pPath.length() - 1 ) ); |
244 |
|
- |
} |
245 |
|
- |
|
246 |
|
- |
public static int lastPathSepAt( String pPath ) |
247 |
|
- |
{ |
248 |
|
- |
if ( pPath != null ) |
249 |
|
- |
{ |
250 |
|
- |
for ( int at = pPath.length(); --at >= 0; ) |
251 |
|
- |
{ |
252 |
|
- |
if ( Characters.isPathSep( pPath.charAt( at ) ) ) |
253 |
|
- |
{ |
254 |
|
- |
return at; |
255 |
|
- |
} |
256 |
|
- |
} |
257 |
|
- |
} |
258 |
|
- |
return -1; |
259 |
|
- |
} |
260 |
|
- |
|
261 |
|
- |
public static String forwardSlashPath( String pPath ) |
262 |
|
- |
{ |
263 |
|
- |
return pPath.replace( '\\', '/' ); |
264 |
|
- |
} |
265 |
|
- |
|
266 |
75 |
|
// Groups |
267 |
76 |
|
|
268 |
77 |
|
// Object Group: |
269 |
78 |
|
|
270 |
|
- |
public static String padIt( int pMinDesiredLength, Object pIt ) |
271 |
|
- |
{ |
272 |
|
- |
return Strings.padIt( pMinDesiredLength, "" + pIt ); |
273 |
|
- |
} |
274 |
|
- |
|
275 |
|
- |
public static String iTpad( Object pIt, int pMinDesiredLength ) |
276 |
|
- |
{ |
277 |
|
- |
return Strings.iTpad( "" + pIt, pMinDesiredLength ); |
278 |
|
- |
} |
279 |
|
- |
|
280 |
|
- |
public static boolean isAnyTrue( Boolean... pToSearch ) |
281 |
|
- |
{ |
282 |
|
- |
if ( pToSearch != null ) |
283 |
|
- |
{ |
284 |
|
- |
for ( Boolean zBoolean : pToSearch ) |
285 |
|
- |
{ |
286 |
|
- |
if ( Boolean.TRUE.equals( zBoolean ) ) |
287 |
|
- |
{ |
288 |
|
- |
return true; |
289 |
|
- |
} |
290 |
|
- |
} |
291 |
|
- |
} |
292 |
|
- |
return false; |
293 |
|
- |
} |
294 |
|
- |
|
295 |
|
- |
public static boolean isOneOf( String pToFind, String[] pToSearch ) |
296 |
|
- |
{ |
297 |
|
- |
return isObjectOneOf( pToFind, pToSearch ); |
298 |
|
- |
} |
299 |
|
- |
|
300 |
|
- |
public static boolean isOneOf( Object pToFind, Object[] pToSearch ) |
301 |
|
- |
{ |
302 |
|
- |
return isObjectOneOf( pToFind, pToSearch ); |
303 |
|
- |
} |
304 |
|
- |
|
305 |
|
- |
private static boolean isObjectOneOf( Object pToFind, Object[] pToSearch ) |
306 |
|
- |
{ |
307 |
|
- |
if ( pToSearch != null ) |
308 |
|
- |
{ |
309 |
|
- |
for ( int i = pToSearch.length; --i >= 0; ) |
310 |
|
- |
{ |
311 |
|
- |
if ( areEqual( pToFind, pToSearch[i] ) ) |
312 |
|
- |
{ |
313 |
|
- |
return true; |
314 |
|
- |
} |
315 |
|
- |
} |
316 |
|
- |
} |
317 |
|
- |
return false; |
318 |
|
- |
} |
319 |
|
- |
|
320 |
|
- |
public static String toStringNullToEmpty( Object pObject ) |
321 |
|
- |
{ |
322 |
|
- |
if ( pObject != null ) |
323 |
|
- |
{ |
324 |
|
- |
String rv = pObject.toString(); |
325 |
|
- |
if ( rv != null ) |
326 |
|
- |
{ |
327 |
|
- |
return rv; |
328 |
|
- |
} |
329 |
|
- |
} |
330 |
|
- |
return ""; |
331 |
|
- |
} |
332 |
|
- |
|
333 |
|
- |
public static String toStringOrNull( Object pObject ) |
334 |
|
- |
{ |
335 |
|
- |
return Strings.noEmpty( (pObject != null) ? pObject.toString() : null ); |
336 |
|
- |
} |
337 |
|
- |
|
338 |
|
- |
public static String toString( Object pObject ) |
339 |
|
- |
{ |
340 |
|
- |
if ( pObject != null ) |
341 |
|
- |
{ |
342 |
|
- |
String rv = pObject.toString(); |
343 |
|
- |
if ( rv != null ) |
344 |
|
- |
{ |
345 |
|
- |
return rv; |
346 |
|
- |
} |
347 |
|
- |
} |
348 |
|
- |
return null; |
349 |
|
- |
} |
350 |
|
- |
|
351 |
|
- |
public static String optionsToString( Object[] pObjects ) |
352 |
|
- |
{ |
353 |
|
- |
if ( pObjects == null ) |
354 |
|
- |
{ |
355 |
|
- |
return "No Options Available"; |
356 |
|
- |
} |
357 |
|
- |
StringBuilder sb = new StringBuilder( "Valid Options are" ); |
358 |
|
- |
String prefix = ": "; |
359 |
|
- |
//noinspection ForLoopReplaceableByForEach |
360 |
|
- |
for ( int i = 0; i < pObjects.length; i++ ) |
361 |
|
- |
{ |
362 |
|
- |
sb.append( prefix ).append( pObjects[i] ); |
363 |
|
- |
prefix = ", "; |
364 |
|
- |
} |
365 |
|
- |
return sb.toString(); |
366 |
|
- |
} |
367 |
|
- |
|
368 |
|
- |
public static String toString( Object[] pObjects ) |
369 |
|
- |
{ |
370 |
|
- |
if ( pObjects == null ) |
371 |
|
- |
{ |
372 |
|
- |
return "null"; |
373 |
|
- |
} |
374 |
|
- |
return new StringBuilder().append( '<' ).append( pObjects.length ).append( ':' ).append( toString( pObjects, "," ) ).append( '>' ).toString(); |
375 |
|
- |
} |
376 |
|
- |
|
377 |
|
- |
public static String toString( Object[] pObjects, String separator ) |
378 |
|
- |
{ |
379 |
|
- |
if ( pObjects == null ) |
380 |
|
- |
{ |
381 |
|
- |
return "null"; |
382 |
|
- |
} |
383 |
|
- |
StringBuilder sb = new StringBuilder(); |
384 |
|
- |
if ( pObjects.length > 0 ) |
385 |
|
- |
{ |
386 |
|
- |
sb.append( pObjects[0] ); |
387 |
|
- |
//noinspection ForLoopReplaceableByForEach |
388 |
|
- |
for ( int i = 1; i < pObjects.length; i++ ) |
389 |
|
- |
{ |
390 |
|
- |
sb.append( separator ).append( pObjects[i] ); |
391 |
|
- |
} |
392 |
|
- |
} |
393 |
|
- |
return sb.toString(); |
394 |
|
- |
} |
395 |
|
- |
|
396 |
79 |
|
@SuppressWarnings({"unchecked", "ManualArrayToCollectionCopy", "MismatchedQueryAndUpdateOfCollection"}) |
397 |
80 |
|
public static <T> Collection<T> convert( Collection<T> pCollectionToFill, Object[] pObjects ) |
398 |
81 |
|
{ |
|
@@ -426,13 +109,6 @@ |
426 |
109 |
|
pBuffer.append( (pValue == null) ? "null" : pValue ); |
427 |
110 |
|
} |
428 |
111 |
|
|
429 |
|
- |
public static String printStackTraceToString( Throwable pThrowable ) |
430 |
|
- |
{ |
431 |
|
- |
ExceptionStackTracePrintStream ps = new ExceptionStackTracePrintStream(); |
432 |
|
- |
pThrowable.printStackTrace( ps ); |
433 |
|
- |
return ps.toString(); |
434 |
|
- |
} |
435 |
|
- |
|
436 |
112 |
|
public static String normalizeCtrlChars( String pText ) |
437 |
113 |
|
{ |
438 |
114 |
|
if ( pText != null ) |
|
@@ -490,7 +166,7 @@ |
490 |
166 |
|
} |
491 |
167 |
|
if ( path.length() != 0 ) |
492 |
168 |
|
{ |
493 |
|
- |
String fsp = forwardSlashPath( path ); |
|
169 |
+ |
String fsp = Paths.forwardSlash( path ); |
494 |
170 |
|
if ( sb.length() == 0 ) |
495 |
171 |
|
{ |
496 |
172 |
|
sb.append( fsp ); |
|
@@ -661,42 +337,10 @@ |
661 |
337 |
|
|
662 |
338 |
|
// Array / varArgs |
663 |
339 |
|
|
664 |
|
- |
public static String combine( String pSeparator, List<String> pStrings ) |
665 |
|
- |
{ |
666 |
|
- |
//noinspection SuspiciousToArrayCall |
667 |
|
- |
return combine( pSeparator, (Object[]) pStrings.toArray( new String[pStrings.size()] ) ); |
668 |
|
- |
} |
669 |
|
- |
|
670 |
|
- |
public static String combineObjects( String pSeparator, List<?> pObjects ) |
671 |
|
- |
{ |
672 |
|
- |
return combine( pSeparator, pObjects.toArray() ); |
673 |
|
- |
} |
674 |
|
- |
|
675 |
340 |
|
// Objects: |
676 |
341 |
|
|
677 |
342 |
|
// Object Group: |
678 |
343 |
|
|
679 |
|
- |
public static boolean areNotNull( Object... pToChecks ) |
680 |
|
- |
{ |
681 |
|
- |
if ( pToChecks == null ) |
682 |
|
- |
{ |
683 |
|
- |
return false; |
684 |
|
- |
} |
685 |
|
- |
for ( Object toCheck : pToChecks ) |
686 |
|
- |
{ |
687 |
|
- |
if ( toCheck == null ) |
688 |
|
- |
{ |
689 |
|
- |
return false; |
690 |
|
- |
} |
691 |
|
- |
} |
692 |
|
- |
return true; |
693 |
|
- |
} |
694 |
|
- |
|
695 |
|
- |
public static boolean hasText( Object pValue ) |
696 |
|
- |
{ |
697 |
|
- |
return (pValue != null) && (pValue.toString().trim().length() != 0); |
698 |
|
- |
} |
699 |
|
- |
|
700 |
344 |
|
public static SimpleDate forceEndOfMonth( SimpleDate pSimpleDate ) |
701 |
345 |
|
{ |
702 |
346 |
|
if ( pSimpleDate != null ) |
|
@@ -709,10 +353,4 @@ |
709 |
353 |
|
} |
710 |
354 |
|
return pSimpleDate; |
711 |
355 |
|
} |
712 |
|
- |
|
713 |
|
- |
@SuppressWarnings({"unchecked"}) |
714 |
|
- |
public static <T> T cast( Object o ) |
715 |
|
- |
{ |
716 |
|
- |
return (T) o; |
717 |
|
- |
} |
718 |
356 |
|
} |