|
@@ -1,55 +1,55 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.aokeyhole.objects.support; |
3 |
|
- |
|
4 |
|
- |
public abstract class AbstractBase { |
5 |
|
- |
public static final String[] EMPTY_STRINGS = new String[0]; |
6 |
|
- |
|
7 |
|
- |
public static boolean areEqual( Object p1, Object p2 ) { |
8 |
|
- |
return (p1 == p2) || // Identity the same or both null |
9 |
|
- |
((p1 != null) && p1.equals( p2 )); |
10 |
|
- |
} |
11 |
|
- |
|
12 |
|
- |
public static String trimEmptyToNull( String pSource ) { |
13 |
|
- |
if ( pSource != null ) { |
14 |
|
- |
pSource = pSource.trim(); |
15 |
|
- |
if ( pSource.length() != 0 ) { |
16 |
|
- |
return pSource; |
17 |
|
- |
} |
18 |
|
- |
} |
19 |
|
- |
return null; |
20 |
|
- |
} |
21 |
|
- |
|
22 |
|
- |
public static String objectToString( Object pObject ) { |
23 |
|
- |
return (pObject == null) ? null : pObject.toString(); |
24 |
|
- |
} |
25 |
|
- |
|
26 |
|
- |
public static String deNull( String pString ) { |
27 |
|
- |
return (pString == null) ? "" : pString; |
28 |
|
- |
} |
29 |
|
- |
|
30 |
|
- |
public static boolean allDigits( String pInput ) { |
31 |
|
- |
for ( int i = 0; i < pInput.length(); i++ ) { |
32 |
|
- |
char c = pInput.charAt( i ); |
33 |
|
- |
if ( (c < '0') || ('9' < c) ) { |
34 |
|
- |
return false; |
35 |
|
- |
} |
36 |
|
- |
} |
37 |
|
- |
return true; |
38 |
|
- |
} |
39 |
|
- |
|
40 |
|
- |
public static String deSpace( String pString ) { |
41 |
|
- |
int spAt = pString.indexOf( ' ' ); |
42 |
|
- |
if ( spAt == -1 ) { |
43 |
|
- |
return pString; |
44 |
|
- |
} |
45 |
|
- |
StringBuilder sb = new StringBuilder( pString ); |
46 |
|
- |
while ( spAt < sb.length() ) { |
47 |
|
- |
if ( ' ' == sb.charAt( spAt ) ) { |
48 |
|
- |
sb.deleteCharAt( spAt ); |
49 |
|
- |
} else { |
50 |
|
- |
spAt++; |
51 |
|
- |
} |
52 |
|
- |
} |
53 |
|
- |
return sb.toString(); |
54 |
|
- |
} |
55 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.aokeyhole.objects.support; |
|
3 |
+ |
|
|
4 |
+ |
public abstract class AbstractBase { |
|
5 |
+ |
public static final String[] EMPTY_STRINGS = new String[0]; |
|
6 |
+ |
|
|
7 |
+ |
public static boolean areEqual( Object p1, Object p2 ) { |
|
8 |
+ |
return (p1 == p2) || // Identity the same or both null |
|
9 |
+ |
((p1 != null) && p1.equals( p2 )); |
|
10 |
+ |
} |
|
11 |
+ |
|
|
12 |
+ |
public static String trimEmptyToNull( String pSource ) { |
|
13 |
+ |
if ( pSource != null ) { |
|
14 |
+ |
pSource = pSource.trim(); |
|
15 |
+ |
if ( pSource.length() != 0 ) { |
|
16 |
+ |
return pSource; |
|
17 |
+ |
} |
|
18 |
+ |
} |
|
19 |
+ |
return null; |
|
20 |
+ |
} |
|
21 |
+ |
|
|
22 |
+ |
public static String objectToString( Object pObject ) { |
|
23 |
+ |
return (pObject == null) ? null : pObject.toString(); |
|
24 |
+ |
} |
|
25 |
+ |
|
|
26 |
+ |
public static String deNull( String pString ) { |
|
27 |
+ |
return (pString == null) ? "" : pString; |
|
28 |
+ |
} |
|
29 |
+ |
|
|
30 |
+ |
public static boolean allDigits( String pInput ) { |
|
31 |
+ |
for ( int i = 0; i < pInput.length(); i++ ) { |
|
32 |
+ |
char c = pInput.charAt( i ); |
|
33 |
+ |
if ( (c < '0') || ('9' < c) ) { |
|
34 |
+ |
return false; |
|
35 |
+ |
} |
|
36 |
+ |
} |
|
37 |
+ |
return true; |
|
38 |
+ |
} |
|
39 |
+ |
|
|
40 |
+ |
public static String deSpace( String pString ) { |
|
41 |
+ |
int spAt = pString.indexOf( ' ' ); |
|
42 |
+ |
if ( spAt == -1 ) { |
|
43 |
+ |
return pString; |
|
44 |
+ |
} |
|
45 |
+ |
StringBuilder sb = new StringBuilder( pString ); |
|
46 |
+ |
while ( spAt < sb.length() ) { |
|
47 |
+ |
if ( ' ' == sb.charAt( spAt ) ) { |
|
48 |
+ |
sb.deleteCharAt( spAt ); |
|
49 |
+ |
} else { |
|
50 |
+ |
spAt++; |
|
51 |
+ |
} |
|
52 |
+ |
} |
|
53 |
+ |
return sb.toString(); |
|
54 |
+ |
} |
|
55 |
+ |
} |