|
@@ -10,7 +10,6 @@ |
10 |
10 |
|
import org.litesoft.core.simpletypes.temporal.*; |
11 |
11 |
|
import org.litesoft.core.simpletypes.temporal.nonpublic.*; |
12 |
12 |
|
import org.litesoft.core.typeutils.*; |
13 |
|
- |
import org.litesoft.core.util.stringmatching.*; |
14 |
13 |
|
|
15 |
14 |
|
public class UtilsCommon extends EqualSupport |
16 |
15 |
|
{ |
|
@@ -18,11 +17,6 @@ |
18 |
17 |
|
public static final String CANNOT_BE_NEGATIVE = " cannot be negative"; |
19 |
18 |
|
public static final String NOT_ALLOWED_TO_BE_NULL = ": Not allowed to be null"; |
20 |
19 |
|
|
21 |
|
- |
public static final String ASCII_127 = "DEL"; |
22 |
|
- |
public static final String[] ASCII_LOW_32 = |
23 |
|
- |
new String[]{"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", "DLE", "DC1", "DC2", "DC3", |
24 |
|
- |
"DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"}; |
25 |
|
- |
|
26 |
20 |
|
protected UtilsCommon() |
27 |
21 |
|
{ |
28 |
22 |
|
} |
|
@@ -165,7 +159,7 @@ |
165 |
159 |
|
break; |
166 |
160 |
|
} |
167 |
161 |
|
sb.append( '[' ); |
168 |
|
- |
sb.append( cvtCharForDisplay( c ) ); |
|
162 |
+ |
sb.append( Characters.cvtCharForDisplay( c ) ); |
169 |
163 |
|
sb.append( ']' ); |
170 |
164 |
|
break; |
171 |
165 |
|
} |
|
@@ -173,32 +167,6 @@ |
173 |
167 |
|
return sb.toString(); |
174 |
168 |
|
} |
175 |
169 |
|
|
176 |
|
- |
private static String cvtCharForDisplay( char pChar ) |
177 |
|
- |
{ |
178 |
|
- |
if ( pChar < 0 ) // is this even possible? |
179 |
|
- |
{ |
180 |
|
- |
return "-" + cvtCharForDisplay( (char) -pChar ); |
181 |
|
- |
} |
182 |
|
- |
if ( pChar < ' ' ) |
183 |
|
- |
{ |
184 |
|
- |
return ASCII_LOW_32[pChar]; |
185 |
|
- |
} |
186 |
|
- |
if ( pChar < 127 ) |
187 |
|
- |
{ |
188 |
|
- |
return String.valueOf( pChar ); |
189 |
|
- |
} |
190 |
|
- |
if ( pChar == 127 ) |
191 |
|
- |
{ |
192 |
|
- |
return ASCII_127; |
193 |
|
- |
} |
194 |
|
- |
if ( pChar < 256 ) |
195 |
|
- |
{ |
196 |
|
- |
return "HiBit-" + cvtCharForDisplay( (char) (pChar - 128) ); |
197 |
|
- |
} |
198 |
|
- |
|
199 |
|
- |
return "x" + Integer.toString( pChar, 16 ); // toHex |
200 |
|
- |
} |
201 |
|
- |
|
202 |
170 |
|
public static Object[] convert( int pEntries, Enumeration<Object> pEnumeration ) |
203 |
171 |
|
{ |
204 |
172 |
|
Object[] them = new Object[pEntries]; |
|
@@ -235,94 +203,6 @@ |
235 |
203 |
|
return (pIndex < 0) ? 0 : pIndex; |
236 |
204 |
|
} |
237 |
205 |
|
|
238 |
|
- |
public static char toHexDigit( int pZeroTo15 ) |
239 |
|
- |
{ |
240 |
|
- |
pZeroTo15 &= 15; |
241 |
|
- |
return (pZeroTo15 < 0) || (15 < pZeroTo15) ? '?' : HEX.charAt( pZeroTo15 ); |
242 |
|
- |
} |
243 |
|
- |
|
244 |
|
- |
/** |
245 |
|
- |
* Attempt to interpret (char) pHex as a Hex Character |
246 |
|
- |
* |
247 |
|
- |
* @return -1 if not a HEX character, otherwise the 0-15 |
248 |
|
- |
*/ |
249 |
|
- |
public static int hexFor( char pHex ) |
250 |
|
- |
{ |
251 |
|
- |
return HEX.indexOf( Character.toUpperCase( pHex ) ); |
252 |
|
- |
} |
253 |
|
- |
|
254 |
|
- |
public static int fromHexDigit( char pHex ) |
255 |
|
- |
throws IllegalArgumentException |
256 |
|
- |
{ |
257 |
|
- |
int rv = hexFor( pHex ); |
258 |
|
- |
if ( rv == -1 ) |
259 |
|
- |
{ |
260 |
|
- |
throw new IllegalArgumentException( "Not a Hex digit '" + pHex + "': " + (int) pHex ); |
261 |
|
- |
} |
262 |
|
- |
return rv; |
263 |
|
- |
} |
264 |
|
- |
|
265 |
|
- |
private static final String HEX = "0123456789ABCDEF"; |
266 |
|
- |
|
267 |
|
- |
public static char[] charToHex( char c ) |
268 |
|
- |
{ |
269 |
|
- |
char[] rv = new char[4]; |
270 |
|
- |
int cv = c; |
271 |
|
- |
for ( int i = 3; i >= 0; i-- ) |
272 |
|
- |
{ |
273 |
|
- |
rv[i] = toHexDigit( cv ); |
274 |
|
- |
cv /= 16; |
275 |
|
- |
} |
276 |
|
- |
return rv; |
277 |
|
- |
} |
278 |
|
- |
|
279 |
|
- |
public static char charFromHex( char[] pHex ) |
280 |
|
- |
throws IllegalArgumentException |
281 |
|
- |
{ |
282 |
|
- |
int rv = 0; |
283 |
|
- |
for ( char c : pHex ) |
284 |
|
- |
{ |
285 |
|
- |
rv = (rv * 16) + fromHexDigit( c ); |
286 |
|
- |
} |
287 |
|
- |
return (char) rv; |
288 |
|
- |
} |
289 |
|
- |
|
290 |
|
- |
public static String toHex( byte[] pBytes ) |
291 |
|
- |
{ |
292 |
|
- |
if ( pBytes == null ) |
293 |
|
- |
{ |
294 |
|
- |
return null; |
295 |
|
- |
} |
296 |
|
- |
StringBuilder sb = new StringBuilder( pBytes.length + pBytes.length ); |
297 |
|
- |
for ( byte zByte : pBytes ) |
298 |
|
- |
{ |
299 |
|
- |
sb.append( toHexDigit( zByte >>> 4 ) ); |
300 |
|
- |
sb.append( toHexDigit( zByte ) ); |
301 |
|
- |
} |
302 |
|
- |
return sb.toString(); |
303 |
|
- |
} |
304 |
|
- |
|
305 |
|
- |
public static byte[] fromHex( String pString ) |
306 |
|
- |
{ |
307 |
|
- |
if ( pString == null ) |
308 |
|
- |
{ |
309 |
|
- |
return null; |
310 |
|
- |
} |
311 |
|
- |
if ( (pString.length() & 1) == 1 ) |
312 |
|
- |
{ |
313 |
|
- |
throw new IllegalArgumentException( "Can't be HEX as it is 'Odd' Length: '" + pString + "'" ); |
314 |
|
- |
} |
315 |
|
- |
int zCharAt = 0; |
316 |
|
- |
byte[] zBytes = new byte[pString.length() / 2]; |
317 |
|
- |
for ( int i = 0; i < zBytes.length; i++ ) |
318 |
|
- |
{ |
319 |
|
- |
int z1st = fromHexDigit( pString.charAt( zCharAt++ ) ); |
320 |
|
- |
int z2nd = fromHexDigit( pString.charAt( zCharAt++ ) ); |
321 |
|
- |
zBytes[i] = (byte) ((z1st << 4) + z2nd); |
322 |
|
- |
} |
323 |
|
- |
return zBytes; |
324 |
|
- |
} |
325 |
|
- |
|
326 |
206 |
|
public static String getMax2PlacePercentage( int pPortions ) |
327 |
207 |
|
{ |
328 |
208 |
|
if ( pPortions == 0 ) |
|
@@ -527,7 +407,7 @@ |
527 |
407 |
|
for ( int i = 0; i < pToBeAssert.length(); i++ ) |
528 |
408 |
|
{ |
529 |
409 |
|
char c = pToBeAssert.charAt( i ); |
530 |
|
- |
if ( !(is7BitAsciiAlpha( c )) ) |
|
410 |
+ |
if ( !(Characters.is7BitAsciiAlpha( c )) ) |
531 |
411 |
|
{ |
532 |
412 |
|
throw new IllegalArgumentException( pObjectName + ": '" + c + "' Not a 7 Bit Ascii Alpha at: " + i ); |
533 |
413 |
|
} |
|
@@ -641,7 +521,7 @@ |
641 |
521 |
|
String strValue = noEmptyToString( value ); |
642 |
522 |
|
if ( strValue == null ) |
643 |
523 |
|
{ |
644 |
|
- |
Strings.errorNullOrEmpty( what, String.valueOf( justClassNameOf( value ) ) ); |
|
524 |
+ |
Strings.errorNullOrEmpty( what, String.valueOf( Objects.justClassNameOf( value ) ) ); |
645 |
525 |
|
} |
646 |
526 |
|
return strValue; |
647 |
527 |
|
} |
|
@@ -659,7 +539,7 @@ |
659 |
539 |
|
{ |
660 |
540 |
|
if ( value == null ) |
661 |
541 |
|
{ |
662 |
|
- |
Strings.errorNullOrEmpty( what, String.valueOf( justClassNameOf( value ) ) ); |
|
542 |
+ |
Strings.errorNullOrEmpty( what, String.valueOf( Objects.justClassNameOf( value ) ) ); |
663 |
543 |
|
} |
664 |
544 |
|
if ( value instanceof String ) |
665 |
545 |
|
{ |
|
@@ -725,7 +605,7 @@ |
725 |
605 |
|
|
726 |
606 |
|
public static boolean endsWithPathSep( String pPath ) |
727 |
607 |
|
{ |
728 |
|
- |
return (pPath != null) && isPathSep( pPath.charAt( pPath.length() - 1 ) ); |
|
608 |
+ |
return (pPath != null) && Characters.isPathSep( pPath.charAt( pPath.length() - 1 ) ); |
729 |
609 |
|
} |
730 |
610 |
|
|
731 |
611 |
|
public static int lastPathSepAt( String pPath ) |
|
@@ -734,7 +614,7 @@ |
734 |
614 |
|
{ |
735 |
615 |
|
for ( int at = pPath.length(); --at >= 0; ) |
736 |
616 |
|
{ |
737 |
|
- |
if ( isPathSep( pPath.charAt( at ) ) ) |
|
617 |
+ |
if ( Characters.isPathSep( pPath.charAt( at ) ) ) |
738 |
618 |
|
{ |
739 |
619 |
|
return at; |
740 |
620 |
|
} |
|
@@ -743,11 +623,6 @@ |
743 |
623 |
|
return -1; |
744 |
624 |
|
} |
745 |
625 |
|
|
746 |
|
- |
public static boolean isPathSep( char pChar ) |
747 |
|
- |
{ |
748 |
|
- |
return (pChar == '/') || (pChar == '\\') || (pChar == ':'); |
749 |
|
- |
} |
750 |
|
- |
|
751 |
626 |
|
public static String forwardSlashPath( String pPath ) |
752 |
627 |
|
{ |
753 |
628 |
|
return pPath.replace( '\\', '/' ); |
|
@@ -999,7 +874,7 @@ |
999 |
874 |
|
} |
1000 |
875 |
|
for ( int i = 0; i < pString.length(); i++ ) |
1001 |
876 |
|
{ |
1002 |
|
- |
if ( !is7BitAsciiAlpha( pString.charAt( i ) ) ) |
|
877 |
+ |
if ( !Characters.is7BitAsciiAlpha( pString.charAt( i ) ) ) |
1003 |
878 |
|
{ |
1004 |
879 |
|
return false; |
1005 |
880 |
|
} |
|
@@ -1015,7 +890,7 @@ |
1015 |
890 |
|
} |
1016 |
891 |
|
for ( int i = 0; i < pString.length(); i++ ) |
1017 |
892 |
|
{ |
1018 |
|
- |
if ( !isAlphaNumeric( pString.charAt( i ) ) ) |
|
893 |
+ |
if ( !Characters.isAlphaNumeric( pString.charAt( i ) ) ) |
1019 |
894 |
|
{ |
1020 |
895 |
|
return false; |
1021 |
896 |
|
} |
|
@@ -1031,7 +906,7 @@ |
1031 |
906 |
|
} |
1032 |
907 |
|
for ( int i = 0; i < pString.length(); i++ ) |
1033 |
908 |
|
{ |
1034 |
|
- |
if ( !isNumeric( pString.charAt( i ) ) ) |
|
909 |
+ |
if ( !Characters.isNumeric( pString.charAt( i ) ) ) |
1035 |
910 |
|
{ |
1036 |
911 |
|
return false; |
1037 |
912 |
|
} |
|
@@ -1051,13 +926,13 @@ |
1051 |
926 |
|
return false; |
1052 |
927 |
|
} |
1053 |
928 |
|
|
1054 |
|
- |
if ( !isValidAttributeIdentifierStartCharacter( pIdentifier.charAt( 0 ) ) ) |
|
929 |
+ |
if ( !Characters.isValidAttributeIdentifierStartCharacter( pIdentifier.charAt( 0 ) ) ) |
1055 |
930 |
|
{ |
1056 |
931 |
|
return false; |
1057 |
932 |
|
} |
1058 |
933 |
|
for ( int i = 1; i < pIdentifier.length(); i++ ) |
1059 |
934 |
|
{ |
1060 |
|
- |
if ( !isValidAttributeIdentifierRestCharacter( pIdentifier.charAt( i ) ) ) |
|
935 |
+ |
if ( !Characters.isValidAttributeIdentifierRestCharacter( pIdentifier.charAt( i ) ) ) |
1061 |
936 |
|
{ |
1062 |
937 |
|
return false; |
1063 |
938 |
|
} |
|
@@ -1065,38 +940,6 @@ |
1065 |
940 |
|
return true; |
1066 |
941 |
|
} |
1067 |
942 |
|
|
1068 |
|
- |
private static boolean isValidAttributeIdentifierStartCharacter( char pChar ) |
1069 |
|
- |
{ |
1070 |
|
- |
// return Character.isJavaIdentifierStart( pChar ); |
1071 |
|
- |
return (('A' <= pChar) && (pChar <= 'Z')); |
1072 |
|
- |
} |
1073 |
|
- |
|
1074 |
|
- |
private static boolean isValidAttributeIdentifierRestCharacter( char pChar ) |
1075 |
|
- |
{ |
1076 |
|
- |
// return Character.isJavaIdentifierPart( pChar ); |
1077 |
|
- |
return isAlphaNumeric( pChar ); |
1078 |
|
- |
} |
1079 |
|
- |
|
1080 |
|
- |
public static boolean isAlphaNumeric( char pChar ) |
1081 |
|
- |
{ |
1082 |
|
- |
return isAlpha( pChar ) || isNumeric( pChar ); |
1083 |
|
- |
} |
1084 |
|
- |
|
1085 |
|
- |
public static boolean isAlpha( char pChar ) |
1086 |
|
- |
{ |
1087 |
|
- |
return is7BitAsciiAlpha( pChar ); |
1088 |
|
- |
} |
1089 |
|
- |
|
1090 |
|
- |
public static boolean isNumeric( char pChar ) |
1091 |
|
- |
{ |
1092 |
|
- |
return ('0' <= pChar) && (pChar <= '9'); |
1093 |
|
- |
} |
1094 |
|
- |
|
1095 |
|
- |
public static boolean is7BitAsciiAlpha( char pChar ) |
1096 |
|
- |
{ |
1097 |
|
- |
return (('A' <= pChar) && (pChar <= 'Z')) || (('a' <= pChar) && (pChar <= 'z')); |
1098 |
|
- |
} |
1099 |
|
- |
|
1100 |
943 |
|
@SuppressWarnings({"unchecked", "ManualArrayToCollectionCopy", "MismatchedQueryAndUpdateOfCollection"}) |
1101 |
944 |
|
public static <T> Collection<T> convert( Collection<T> pCollectionToFill, Object[] pObjects ) |
1102 |
945 |
|
{ |
|
@@ -1108,112 +951,6 @@ |
1108 |
951 |
|
return pCollectionToFill; |
1109 |
952 |
|
} |
1110 |
953 |
|
|
1111 |
|
- |
/** |
1112 |
|
- |
* This method strips the package name off the fully qualified class name of the pObject returning just the substring |
1113 |
|
- |
* beginning one character beyond the last "." (And removes the wrapping Class names if Any). |
1114 |
|
- |
* |
1115 |
|
- |
* @return the substring beginning one character beyond the last "$"; null or no "$" just returns justClassName( pFullyQualifiedClassName ) |
1116 |
|
- |
*/ |
1117 |
|
- |
public static String justSimpleName( Object pObject ) |
1118 |
|
- |
{ |
1119 |
|
- |
return justSimpleName( (pObject != null) ? pObject.getClass() : null ); |
1120 |
|
- |
} |
1121 |
|
- |
|
1122 |
|
- |
/** |
1123 |
|
- |
* This method strips the package name off the fully qualified class name of the pObject returning just the substring |
1124 |
|
- |
* beginning one character beyond the last "." (And removes the wrapping Class names if Any). |
1125 |
|
- |
* |
1126 |
|
- |
* @return the substring beginning one character beyond the last "$"; null or no "$" just returns justClassName( pFullyQualifiedClassName ) |
1127 |
|
- |
*/ |
1128 |
|
- |
public static String justSimpleName( Class pClass ) |
1129 |
|
- |
{ |
1130 |
|
- |
return justSimpleName( (pClass != null) ? pClass.getName() : null ); |
1131 |
|
- |
} |
1132 |
|
- |
|
1133 |
|
- |
/** |
1134 |
|
- |
* This method strips the package name off a fully qualified class name returning just the substring |
1135 |
|
- |
* beginning one character beyond the last "." (And removes the wrapping Class names if Any). |
1136 |
|
- |
* |
1137 |
|
- |
* @return the substring beginning one character beyond the last "$"; null or no "$" just returns justClassName( pFullyQualifiedClassName ) |
1138 |
|
- |
*/ |
1139 |
|
- |
public static String justSimpleName( String pFullyQualifiedClassName ) |
1140 |
|
- |
{ |
1141 |
|
- |
int zAt = (pFullyQualifiedClassName != null) ? pFullyQualifiedClassName.lastIndexOf( '$' ) : -1; |
1142 |
|
- |
return (zAt != -1) ? pFullyQualifiedClassName.substring( zAt + 1 ) : justClassName( pFullyQualifiedClassName ); |
1143 |
|
- |
} |
1144 |
|
- |
|
1145 |
|
- |
/** |
1146 |
|
- |
* This method strips the package name off a fully qualified class name returning just the substring |
1147 |
|
- |
* beginning one character beyond the last ".". |
1148 |
|
- |
* |
1149 |
|
- |
* @return the substring beginning one character beyond the last "."; null or no "." just returns pFullyQualifiedClassName |
1150 |
|
- |
*/ |
1151 |
|
- |
public static String justClassName( String pFullyQualifiedClassName ) |
1152 |
|
- |
{ |
1153 |
|
- |
int zAt = (pFullyQualifiedClassName != null) ? pFullyQualifiedClassName.lastIndexOf( '.' ) : -1; |
1154 |
|
- |
return (zAt != -1) ? pFullyQualifiedClassName.substring( zAt + 1 ) : pFullyQualifiedClassName; |
1155 |
|
- |
} |
1156 |
|
- |
|
1157 |
|
- |
/** |
1158 |
|
- |
* This method strips the package name off a fully qualified class name returning just the substring |
1159 |
|
- |
* beginning one character beyond the last ".". |
1160 |
|
- |
* |
1161 |
|
- |
* @return the substring beginning one character beyond the last "."; null or no "." just returns |
1162 |
|
- |
*/ |
1163 |
|
- |
public static String justClassName( Class<?> pClass ) |
1164 |
|
- |
{ |
1165 |
|
- |
return (pClass != null) ? justClassName( pClass.getName() ) : null; |
1166 |
|
- |
} |
1167 |
|
- |
|
1168 |
|
- |
/** |
1169 |
|
- |
* This method strips the package name off the class name of the pObject returning just the substring |
1170 |
|
- |
* beginning one character beyond the last ".". |
1171 |
|
- |
* |
1172 |
|
- |
* @see #justClassName(Class) |
1173 |
|
- |
*/ |
1174 |
|
- |
public static String justClassNameOf( Object pObject ) |
1175 |
|
- |
{ |
1176 |
|
- |
return (pObject != null) ? justClassName( pObject.getClass() ) : null; |
1177 |
|
- |
} |
1178 |
|
- |
|
1179 |
|
- |
/** |
1180 |
|
- |
* This method strips the package name off the class name of the pObject returning just the substring |
1181 |
|
- |
* beginning one character beyond the last ".", and if it ends with "Impl" remove that. |
1182 |
|
- |
* |
1183 |
|
- |
* @see #justClassName(Class) |
1184 |
|
- |
*/ |
1185 |
|
- |
public static String justClassNameNoImplOf( Object pObject ) |
1186 |
|
- |
{ |
1187 |
|
- |
String zName = justClassNameOf( pObject ); |
1188 |
|
- |
return ((zName != null) && zName.endsWith( "Impl" )) ? zName.substring( 0, zName.length() - 4 ) : zName; |
1189 |
|
- |
} |
1190 |
|
- |
|
1191 |
|
- |
public static String justClassNameIfPackage( Class<?> pClass, String pPackage ) |
1192 |
|
- |
{ |
1193 |
|
- |
return (pClass != null) ? justClassNameIfPackage( pClass.getName(), pPackage ) : null; |
1194 |
|
- |
} |
1195 |
|
- |
|
1196 |
|
- |
public static String justClassNameIfPackage( String pClassName, String pPackage ) |
1197 |
|
- |
{ |
1198 |
|
- |
if ( pClassName != null ) |
1199 |
|
- |
{ |
1200 |
|
- |
if ( (pPackage != null) && pPackage.endsWith( "." ) && (pPackage.length() < pClassName.length()) ) |
1201 |
|
- |
{ |
1202 |
|
- |
String zSimpleName = justClassName( pClassName ); |
1203 |
|
- |
if ( pClassName.equals( pPackage + zSimpleName ) ) |
1204 |
|
- |
{ |
1205 |
|
- |
return zSimpleName; |
1206 |
|
- |
} |
1207 |
|
- |
} |
1208 |
|
- |
} |
1209 |
|
- |
return pClassName; |
1210 |
|
- |
} |
1211 |
|
- |
|
1212 |
|
- |
public static String classNameOf( Object pObject ) |
1213 |
|
- |
{ |
1214 |
|
- |
return (pObject != null) ? pObject.getClass().getName() : null; |
1215 |
|
- |
} |
1216 |
|
- |
|
1217 |
954 |
|
public static void appendClassName( StringBuilder pBuffer, int pTabLevel, String pLabel, Object pValue ) |
1218 |
955 |
|
{ |
1219 |
956 |
|
append( pBuffer, pTabLevel, pLabel, (pValue == null) ? null : pValue.getClass().getName() ); |
|
@@ -1246,86 +983,6 @@ |
1246 |
983 |
|
return rv; |
1247 |
984 |
|
} |
1248 |
985 |
|
|
1249 |
|
- |
/** |
1250 |
|
- |
* @param pTo - is NOT extended |
1251 |
|
- |
* |
1252 |
|
- |
* @return pTo |
1253 |
|
- |
*/ |
1254 |
|
- |
public static Object[] copyArrayTo( Object[] pFrom, Object[] pTo ) |
1255 |
|
- |
{ |
1256 |
|
- |
if ( (pFrom != null) && (pTo != null) ) |
1257 |
|
- |
{ |
1258 |
|
- |
copySubArrayTo( Math.min( pFrom.length, pTo.length ), pFrom, 0, pTo, 0 ); |
1259 |
|
- |
} |
1260 |
|
- |
return pTo; |
1261 |
|
- |
} |
1262 |
|
- |
|
1263 |
|
- |
/** |
1264 |
|
- |
* @param pTo - is NOT extended |
1265 |
|
- |
* @param pToIndex - 0 based, < 0 indicates from end (eg -1 == Last) |
1266 |
|
- |
* |
1267 |
|
- |
* @return pTo |
1268 |
|
- |
*/ |
1269 |
|
- |
public static Object[] copyArrayTo( Object[] pFrom, Object[] pTo, int pToIndex ) |
1270 |
|
- |
{ |
1271 |
|
- |
if ( (pFrom != null) && (pTo != null) ) |
1272 |
|
- |
{ |
1273 |
|
- |
copySubArrayTo( Math.min( pFrom.length, pTo.length - pToIndex ), pFrom, 0, pTo, pToIndex ); |
1274 |
|
- |
} |
1275 |
|
- |
return pTo; |
1276 |
|
- |
} |
1277 |
|
- |
|
1278 |
|
- |
/** |
1279 |
|
- |
* @param pCount - < 1 means copy nothing |
1280 |
|
- |
* @param pTo - is NOT extended |
1281 |
|
- |
* @param pFromIndex - 0 based, < 0 indicates from end (eg -1 == Last) |
1282 |
|
- |
* @param pToIndex - 0 based, < 0 indicates from end (eg -1 == Last) |
1283 |
|
- |
* |
1284 |
|
- |
* @return pTo |
1285 |
|
- |
*/ |
1286 |
|
- |
public static Object[] copySubArrayTo( int pCount, // |
1287 |
|
- |
Object[] pFrom, int pFromIndex, // |
1288 |
|
- |
Object[] pTo, int pToIndex ) |
1289 |
|
- |
{ |
1290 |
|
- |
if ( (pCount > 0) && // |
1291 |
|
- |
Objects.isNotNullOrEmpty( pFrom ) && (pFromIndex < pFrom.length) && // |
1292 |
|
- |
Objects.isNotNullOrEmpty( pTo ) && (pToIndex < pTo.length) ) |
1293 |
|
- |
{ |
1294 |
|
- |
pCount = lesserOf( pCount, pTo, pToIndex = unNegateIndex( pTo, pToIndex ) ); |
1295 |
|
- |
pCount = lesserOf( pCount, pFrom, pFromIndex = unNegateIndex( pFrom, pFromIndex ) ); |
1296 |
|
- |
while ( pCount-- > 0 ) |
1297 |
|
- |
{ |
1298 |
|
- |
pTo[pToIndex++] = pFrom[pFromIndex++]; |
1299 |
|
- |
} |
1300 |
|
- |
} |
1301 |
|
- |
return pTo; |
1302 |
|
- |
} |
1303 |
|
- |
|
1304 |
|
- |
private static int lesserOf( int pCount, Object[] pObjects, int pIndex ) |
1305 |
|
- |
{ |
1306 |
|
- |
if ( pCount > 0 ) |
1307 |
|
- |
{ |
1308 |
|
- |
int zMoveLen = pObjects.length - pIndex; |
1309 |
|
- |
if ( zMoveLen < pCount ) |
1310 |
|
- |
{ |
1311 |
|
- |
return zMoveLen; |
1312 |
|
- |
} |
1313 |
|
- |
} |
1314 |
|
- |
return pCount; |
1315 |
|
- |
} |
1316 |
|
- |
|
1317 |
|
- |
private static int unNegateIndex( Object[] pFrom, int pFromIndex ) |
1318 |
|
- |
{ |
1319 |
|
- |
if ( pFromIndex < 0 ) |
1320 |
|
- |
{ |
1321 |
|
- |
if ( (pFromIndex = pFrom.length - pFromIndex) < 0 ) |
1322 |
|
- |
{ |
1323 |
|
- |
pFromIndex = 0; |
1324 |
|
- |
} |
1325 |
|
- |
} |
1326 |
|
- |
return pFromIndex; |
1327 |
|
- |
} |
1328 |
|
- |
|
1329 |
986 |
|
public static String[] parseOptions( String pOptionsAsString ) |
1330 |
987 |
|
throws IllegalArgumentException |
1331 |
988 |
|
{ |
|
@@ -1519,10 +1176,10 @@ |
1519 |
1176 |
|
} |
1520 |
1177 |
|
pSB.append( '\\' ); |
1521 |
1178 |
|
pSB.append( 'x' ); |
1522 |
|
- |
pSB.append( toHexDigit( c >> 24 ) ); |
1523 |
|
- |
pSB.append( toHexDigit( c >> 16 ) ); |
1524 |
|
- |
pSB.append( toHexDigit( c >> 8 ) ); |
1525 |
|
- |
pSB.append( toHexDigit( c ) ); |
|
1179 |
+ |
pSB.append( Hex.toChar( c >> 24 ) ); |
|
1180 |
+ |
pSB.append( Hex.toChar( c >> 16 ) ); |
|
1181 |
+ |
pSB.append( Hex.toChar( c >> 8 ) ); |
|
1182 |
+ |
pSB.append( Hex.toChar( c ) ); |
1526 |
1183 |
|
break; |
1527 |
1184 |
|
} |
1528 |
1185 |
|
} |
|
@@ -1578,10 +1235,10 @@ |
1578 |
1235 |
|
} |
1579 |
1236 |
|
try |
1580 |
1237 |
|
{ |
1581 |
|
- |
int zChar = (fromHexDigit( (char) c1 ) << 24) + // |
1582 |
|
- |
(fromHexDigit( (char) c2 ) << 16) + // |
1583 |
|
- |
(fromHexDigit( (char) c3 ) << 8) + // |
1584 |
|
- |
fromHexDigit( (char) c4 ); |
|
1238 |
+ |
int zChar = (Hex.fromCharChecked( (char) c1 ) << 24) + // |
|
1239 |
+ |
(Hex.fromCharChecked( (char) c2 ) << 16) + // |
|
1240 |
+ |
(Hex.fromCharChecked( (char) c3 ) << 8) + // |
|
1241 |
+ |
Hex.fromCharChecked( (char) c4 ); |
1585 |
1242 |
|
pSB.append( (char) zChar ); |
1586 |
1243 |
|
} |
1587 |
1244 |
|
catch ( IllegalArgumentException e ) |
|
@@ -1615,21 +1272,6 @@ |
1615 |
1272 |
|
return combine( pSeparator, pObjects.toArray() ); |
1616 |
1273 |
|
} |
1617 |
1274 |
|
|
1618 |
|
- |
public static String[] removeAllBlankOrCommentLines( String[] pLines ) |
1619 |
|
- |
{ |
1620 |
|
- |
List<String> lines = new LinkedList<String>(); |
1621 |
|
- |
|
1622 |
|
- |
for ( String line : Strings.deNull( pLines ) ) |
1623 |
|
- |
{ |
1624 |
|
- |
String s = line.trim(); |
1625 |
|
- |
if ( (s.length() != 0) && !(s.startsWith( "#" ) || s.startsWith( "//" )) ) |
1626 |
|
- |
{ |
1627 |
|
- |
lines.add( line ); |
1628 |
|
- |
} |
1629 |
|
- |
} |
1630 |
|
- |
return lines.toArray( new String[lines.size()] ); |
1631 |
|
- |
} |
1632 |
|
- |
|
1633 |
1275 |
|
// Objects: |
1634 |
1276 |
|
|
1635 |
1277 |
|
// Object Group: |
|
@@ -1650,75 +1292,15 @@ |
1650 |
1292 |
|
return true; |
1651 |
1293 |
|
} |
1652 |
1294 |
|
|
1653 |
|
- |
public static String merge( String[] pLines ) |
1654 |
|
- |
{ |
1655 |
|
- |
if ( (pLines == null) || (pLines.length == 0) ) |
1656 |
|
- |
{ |
1657 |
|
- |
return ""; |
1658 |
|
- |
} |
1659 |
|
- |
if ( pLines.length == 1 ) |
1660 |
|
- |
{ |
1661 |
|
- |
return pLines[0]; |
1662 |
|
- |
} |
1663 |
|
- |
int length = 0; |
1664 |
|
- |
for ( String line : pLines ) |
1665 |
|
- |
{ |
1666 |
|
- |
if ( line != null ) |
1667 |
|
- |
{ |
1668 |
|
- |
length += line.length() + 2; |
1669 |
|
- |
} |
1670 |
|
- |
} |
1671 |
|
- |
StringBuilder sb = new StringBuilder( length ); |
1672 |
|
- |
for ( String line : pLines ) |
1673 |
|
- |
{ |
1674 |
|
- |
if ( line != null ) |
1675 |
|
- |
{ |
1676 |
|
- |
sb.append( line ).append( '\r' ).append( '\n' ); |
1677 |
|
- |
} |
1678 |
|
- |
} |
1679 |
|
- |
return sb.toString(); |
1680 |
|
- |
} |
1681 |
|
- |
|
1682 |
|
- |
public static boolean isAllUppercaseOrSpaces( String pToTest ) |
1683 |
|
- |
{ |
1684 |
|
- |
if ( Strings.isNotNullOrEmpty( pToTest ) ) |
1685 |
|
- |
{ |
1686 |
|
- |
for ( int i = 0; i < pToTest.length(); i++ ) |
1687 |
|
- |
{ |
1688 |
|
- |
char c = pToTest.charAt( i ); |
1689 |
|
- |
if ( (c != ' ') && !Character.isUpperCase( c ) ) |
1690 |
|
- |
{ |
1691 |
|
- |
return false; |
1692 |
|
- |
} |
1693 |
|
- |
} |
1694 |
|
- |
} |
1695 |
|
- |
return true; |
1696 |
|
- |
} |
1697 |
|
- |
|
1698 |
|
- |
public static boolean isAllUppercase( String pToTest ) |
1699 |
|
- |
{ |
1700 |
|
- |
if ( Strings.isNotNullOrEmpty( pToTest ) ) |
1701 |
|
- |
{ |
1702 |
|
- |
for ( int i = 0; i < pToTest.length(); i++ ) |
1703 |
|
- |
{ |
1704 |
|
- |
if ( !Character.isUpperCase( pToTest.charAt( i ) ) ) |
1705 |
|
- |
{ |
1706 |
|
- |
return false; |
1707 |
|
- |
} |
1708 |
|
- |
} |
1709 |
|
- |
} |
1710 |
|
- |
return true; |
1711 |
|
- |
} |
1712 |
|
- |
|
1713 |
1295 |
|
public static boolean isAsciiIdentifier( String pToTest ) |
1714 |
1296 |
|
{ |
1715 |
1297 |
|
if ( !Strings.isNullOrEmpty( pToTest ) ) |
1716 |
1298 |
|
{ |
1717 |
|
- |
if ( isFirstCharAsciiIdentifier( pToTest.charAt( 0 ) ) ) |
|
1299 |
+ |
if ( Characters.isFirstCharAsciiIdentifier( pToTest.charAt( 0 ) ) ) |
1718 |
1300 |
|
{ |
1719 |
1301 |
|
for ( int i = 1; i < pToTest.length(); i++ ) |
1720 |
1302 |
|
{ |
1721 |
|
- |
if ( !isNonFirstCharAsciiIdentifier( pToTest.charAt( i ) ) ) |
|
1303 |
+ |
if ( !Characters.isNonFirstCharAsciiIdentifier( pToTest.charAt( i ) ) ) |
1722 |
1304 |
|
{ |
1723 |
1305 |
|
return false; |
1724 |
1306 |
|
} |
|
@@ -1729,28 +1311,13 @@ |
1729 |
1311 |
|
return false; |
1730 |
1312 |
|
} |
1731 |
1313 |
|
|
1732 |
|
- |
public static boolean isFirstCharAsciiIdentifier( char pToTest ) |
1733 |
|
- |
{ |
1734 |
|
- |
return isAsciiLetter( pToTest ) || (pToTest == '_'); |
1735 |
|
- |
} |
1736 |
|
- |
|
1737 |
|
- |
public static boolean isNonFirstCharAsciiIdentifier( char pToTest ) |
1738 |
|
- |
{ |
1739 |
|
- |
return isAsciiLetter( pToTest ) || (pToTest == '_') || Character.isDigit( pToTest ); |
1740 |
|
- |
} |
1741 |
|
- |
|
1742 |
|
- |
public static boolean isAsciiLetter( char pToTest ) |
1743 |
|
- |
{ |
1744 |
|
- |
return (('A' <= pToTest) && (pToTest <= 'Z')) || (('a' <= pToTest) && (pToTest <= 'z')); |
1745 |
|
- |
} |
1746 |
|
- |
|
1747 |
1314 |
|
public static boolean isNoSpaceAscii( String pToTest ) |
1748 |
1315 |
|
{ |
1749 |
1316 |
|
if ( !Strings.isNullOrEmpty( pToTest ) ) |
1750 |
1317 |
|
{ |
1751 |
1318 |
|
for ( int i = 0; i < pToTest.length(); i++ ) |
1752 |
1319 |
|
{ |
1753 |
|
- |
if ( !isNoSpaceAscii( pToTest.charAt( i ) ) ) |
|
1320 |
+ |
if ( !Characters.isNoSpaceAscii( pToTest.charAt( i ) ) ) |
1754 |
1321 |
|
{ |
1755 |
1322 |
|
return false; |
1756 |
1323 |
|
} |
|
@@ -1760,18 +1327,13 @@ |
1760 |
1327 |
|
return false; |
1761 |
1328 |
|
} |
1762 |
1329 |
|
|
1763 |
|
- |
public static boolean isNoSpaceAscii( char pToTest ) |
1764 |
|
- |
{ |
1765 |
|
- |
return ((' ' < pToTest) && (pToTest < 127)); |
1766 |
|
- |
} |
1767 |
|
- |
|
1768 |
1330 |
|
public static boolean isNoCtrlAscii( String pToTest ) |
1769 |
1331 |
|
{ |
1770 |
1332 |
|
if ( pToTest != null ) |
1771 |
1333 |
|
{ |
1772 |
1334 |
|
for ( int i = 0; i < pToTest.length(); i++ ) |
1773 |
1335 |
|
{ |
1774 |
|
- |
if ( !isNoCtrlAscii( pToTest.charAt( i ) ) ) |
|
1336 |
+ |
if ( !Characters.isNoCtrlAscii( pToTest.charAt( i ) ) ) |
1775 |
1337 |
|
{ |
1776 |
1338 |
|
return false; |
1777 |
1339 |
|
} |
|
@@ -1781,11 +1343,6 @@ |
1781 |
1343 |
|
return false; |
1782 |
1344 |
|
} |
1783 |
1345 |
|
|
1784 |
|
- |
public static boolean isNoCtrlAscii( char pToTest ) |
1785 |
|
- |
{ |
1786 |
|
- |
return ((' ' <= pToTest) && (pToTest < 127)); |
1787 |
|
- |
} |
1788 |
|
- |
|
1789 |
1346 |
|
public static boolean hasText( Object pValue ) |
1790 |
1347 |
|
{ |
1791 |
1348 |
|
return (pValue != null) && (pValue.toString().trim().length() != 0); |