Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -410,9 +410,9 @@
410 410 // Both CAN'T be null
411 411 if ( (pThis instanceof Object[]) && (pThat instanceof Object[]) )
412 412 {
413 - return areArraysEqual( (Object[]) pThis, (Object[]) pThat );
413 + return Objects.areArraysEqual( (Object[]) pThis, (Object[]) pThat );
414 414 }
415 - return (pThis instanceof int[]) && (pThat instanceof int[]) && areArraysEqual( (int[]) pThis, (int[]) pThat );
415 + return (pThis instanceof int[]) && (pThat instanceof int[]) && Integers.areArraysEqual( (int[]) pThis, (int[]) pThat );
416 416 }
417 417
418 418 public static int insureNonNegative( int pValue )
  @@ -420,42 +420,6 @@
420 420 return (pValue < 0) ? 0 : pValue;
421 421 }
422 422
423 - public static <K, V> Map<K, V> deNull( Map<K, V> pToCheck )
424 - {
425 - if ( pToCheck == null )
426 - {
427 - pToCheck = Collections.emptyMap();
428 - }
429 - return pToCheck;
430 - }
431 -
432 - public static <T> List<T> deNull( List<T> pToCheck )
433 - {
434 - if ( pToCheck == null )
435 - {
436 - pToCheck = Collections.emptyList();
437 - }
438 - return pToCheck;
439 - }
440 -
441 - public static <T> Set<T> deNull( Set<T> pToCheck )
442 - {
443 - if ( pToCheck == null )
444 - {
445 - pToCheck = Collections.emptySet();
446 - }
447 - return pToCheck;
448 - }
449 -
450 - public static <T> Collection<T> deNull( Collection<T> pToCheck )
451 - {
452 - if ( pToCheck == null )
453 - {
454 - pToCheck = Collections.emptyList();
455 - }
456 - return pToCheck;
457 - }
458 -
459 423 public static String deNullToString( Object value, Object defaultValue )
460 424 {
461 425 return Strings.deNull( noEmptyToString( value ), noEmptyToString( defaultValue ) );
  @@ -522,7 +486,7 @@
522 486
523 487 public static String combine( String pSeparator, Object... pObjects )
524 488 {
525 - if ( isNullOrEmpty( pObjects ) )
489 + if ( Objects.isNullOrEmpty( pObjects ) )
526 490 {
527 491 return null;
528 492 }
  @@ -540,7 +504,7 @@
540 504
541 505 public static String combine( char pSeparator, String... pStrings )
542 506 {
543 - if ( isNullOrEmpty( pStrings ) )
507 + if ( Objects.isNullOrEmpty( pStrings ) )
544 508 {
545 509 return null;
546 510 }
  @@ -602,7 +566,7 @@
602 566 {
603 567 if ( Strings.isNullOrEmptyOrSpaces( pStringToAssert ) )
604 568 {
605 - Strings.nullOrEmptyOrSpace( pErrorMessage, "String" );
569 + Strings.errorNullOrEmptyOrSpace( pErrorMessage, "String" );
606 570 }
607 571 }
608 572
  @@ -612,7 +576,7 @@
612 576 String rv = Strings.noEmpty( pStringToAssert );
613 577 if ( rv == null )
614 578 {
615 - Strings.nullOrEmpty( pErrorMessage, "String" );
579 + Strings.errorNullOrEmpty( pErrorMessage, "String" );
616 580 }
617 581 return rv;
618 582 }
  @@ -641,9 +605,9 @@
641 605 public static void assertNotNullNotEmpty( String pErrorMessage, String[] pStringArrayToAssert )
642 606 throws IllegalArgumentException
643 607 {
644 - if ( isNullOrEmpty( pStringArrayToAssert ) )
608 + if ( Objects.isNullOrEmpty( pStringArrayToAssert ) )
645 609 {
646 - Strings.nullOrEmpty( pErrorMessage, "String[]" );
610 + Strings.errorNullOrEmpty( pErrorMessage, "String[]" );
647 611 }
648 612 }
649 613
  @@ -656,7 +620,7 @@
656 620 String s = Strings.noEmpty( pStringArrayToAssert[i] );
657 621 if ( s == null )
658 622 {
659 - Strings.nullOrEmpty( pErrorMessage + "[" + i + "]", "String[]" );
623 + Strings.errorNullOrEmpty( pErrorMessage + "[" + i + "]", "String[]" );
660 624 }
661 625 rv[i] = s;
662 626 }
  @@ -677,7 +641,7 @@
677 641 String strValue = noEmptyToString( value );
678 642 if ( strValue == null )
679 643 {
680 - Strings.nullOrEmpty( what, String.valueOf( justClassNameOf( value ) ) );
644 + Strings.errorNullOrEmpty( what, String.valueOf( justClassNameOf( value ) ) );
681 645 }
682 646 return strValue;
683 647 }
  @@ -695,7 +659,7 @@
695 659 {
696 660 if ( value == null )
697 661 {
698 - Strings.nullOrEmpty( what, String.valueOf( justClassNameOf( value ) ) );
662 + Strings.errorNullOrEmpty( what, String.valueOf( justClassNameOf( value ) ) );
699 663 }
700 664 if ( value instanceof String )
701 665 {
  @@ -796,77 +760,6 @@
796 760
797 761 // Groups
798 762
799 - // Primitives:
800 -
801 - // int Group:
802 -
803 - public static String zeroPadIt( int pMinDesiredLength, int pIt )
804 - {
805 - String rv = String.valueOf( pIt );
806 - while ( rv.length() < pMinDesiredLength )
807 - {
808 - rv = "0" + rv;
809 - }
810 - return rv;
811 - }
812 -
813 - public static String padIt( int pMinDesiredLength, int pIt )
814 - {
815 - return Strings.padIt( pMinDesiredLength, "" + pIt );
816 - }
817 -
818 - public static String iTpad( int pIt, int pMinDesiredLength )
819 - {
820 - return Strings.iTpad( "" + pIt, pMinDesiredLength );
821 - }
822 -
823 - public static boolean isNullOrEmpty( int[] pArrayToCheck )
824 - {
825 - return (pArrayToCheck == null || pArrayToCheck.length == 0);
826 - }
827 -
828 - public static boolean areArraysEqual( byte[] pThis, byte[] pThat )
829 - {
830 - if ( pThis == pThat ) // handles if both are null
831 - {
832 - return true;
833 - }
834 - if ( (pThis != null) && (pThat != null) && (pThis.length == pThat.length) )
835 - {
836 - for ( int i = pThis.length; --i >= 0; )
837 - {
838 - if ( pThis[i] != pThat[i] )
839 - {
840 - return false;
841 - }
842 - }
843 - return true;
844 - }
845 - return false;
846 - }
847 -
848 - public static boolean areArraysEqual( int[] pThis, int[] pThat )
849 - {
850 - if ( pThis == pThat ) // handles if both are null
851 - {
852 - return true;
853 - }
854 - if ( (pThis != null) && (pThat != null) && (pThis.length == pThat.length) )
855 - {
856 - for ( int i = pThis.length; --i >= 0; )
857 - {
858 - if ( pThis[i] != pThat[i] )
859 - {
860 - return false;
861 - }
862 - }
863 - return true;
864 - }
865 - return false;
866 - }
867 -
868 - // Objects:
869 -
870 763 // Object Group:
871 764
872 765 public static String padIt( int pMinDesiredLength, Object pIt )
  @@ -879,110 +772,6 @@
879 772 return Strings.iTpad( "" + pIt, pMinDesiredLength );
880 773 }
881 774
882 - private static void assertElementsNotNull( String pErrorMessage, Object[] pArrayToAssert )
883 - throws IllegalArgumentException
884 - {
885 - for ( int i = pArrayToAssert.length; --i >= 0; )
886 - {
887 - if ( pArrayToAssert[i] == null )
888 - {
889 - Strings.nullOrEmpty( pErrorMessage, "Object[" + i + "]" );
890 - }
891 - }
892 - }
893 -
894 - public static void assertNotNullAndElementsNotNull( String pErrorMessage, Object[] pArrayToAssert )
895 - throws IllegalArgumentException
896 - {
897 - if ( pArrayToAssert == null )
898 - {
899 - Strings.nullOrEmpty( pErrorMessage, "Object[]" );
900 - }
901 - assertElementsNotNull( pErrorMessage, pArrayToAssert );
902 - }
903 -
904 - public static void assertNotNullNotEmptyAndElementsNotNull( String pErrorMessage, Object[] pArrayToAssert )
905 - throws IllegalArgumentException
906 - {
907 - assertNotNullNotEmpty( pErrorMessage, pArrayToAssert );
908 - assertElementsNotNull( pErrorMessage, pArrayToAssert );
909 - }
910 -
911 - public static void assertNotNullNotEmpty( String pErrorMessage, Object[] pArrayToAssert )
912 - throws IllegalArgumentException
913 - {
914 - if ( isNullOrEmpty( pArrayToAssert ) )
915 - {
916 - Strings.nullOrEmpty( pErrorMessage, "Object[]" );
917 - }
918 - }
919 -
920 - public static boolean isNotNull( Object pToCheck )
921 - {
922 - return (pToCheck != null);
923 - }
924 -
925 - public static int getNonNullEntryCount( Object[] pArrayToCheck )
926 - {
927 - int rv = 0;
928 - if ( pArrayToCheck != null )
929 - {
930 - for ( int i = pArrayToCheck.length; --i >= 0; )
931 - {
932 - if ( pArrayToCheck[i] != null )
933 - {
934 - rv++;
935 - }
936 - }
937 - }
938 - return rv;
939 - }
940 -
941 - public static boolean hasEntries( Object[] pArrayToCheck )
942 - {
943 - if ( pArrayToCheck != null )
944 - {
945 - for ( int i = pArrayToCheck.length; --i >= 0; )
946 - {
947 - if ( pArrayToCheck[i] != null )
948 - {
949 - return true;
950 - }
951 - }
952 - }
953 - return false;
954 - }
955 -
956 - public static boolean isNotNullOrEmpty( Object[] pArrayToCheck )
957 - {
958 - return ((pArrayToCheck != null) && (pArrayToCheck.length != 0));
959 - }
960 -
961 - public static boolean isNullOrEmpty( Object[] pArrayToCheck )
962 - {
963 - return ((pArrayToCheck == null) || (pArrayToCheck.length == 0));
964 - }
965 -
966 - public static boolean areArraysEqual( Object[] pThis, Object[] pThat )
967 - {
968 - if ( pThis == pThat ) // handles if both are null
969 - {
970 - return true;
971 - }
972 - if ( (pThis != null) && (pThat != null) && (pThis.length == pThat.length) )
973 - {
974 - for ( int i = pThis.length; --i >= 0; )
975 - {
976 - if ( !areEqual( pThis[i], pThat[i] ) )
977 - {
978 - return false;
979 - }
980 - }
981 - return true;
982 - }
983 - return false;
984 - }
985 -
986 775 public static boolean isAnyTrue( Boolean... pToSearch )
987 776 {
988 777 if ( pToSearch != null )
  @@ -1056,7 +845,7 @@
1056 845
1057 846 public static String[] removeStringFromArray( String[] pArray, int pIndexToRemove )
1058 847 {
1059 - if ( isNullOrEmpty( pArray ) || (pIndexToRemove < 0) || (pArray.length <= pIndexToRemove) )
848 + if ( Objects.isNullOrEmpty( pArray ) || (pIndexToRemove < 0) || (pArray.length <= pIndexToRemove) )
1060 849 {
1061 850 return pArray;
1062 851 }
  @@ -1075,11 +864,11 @@
1075 864
1076 865 public static String[] appendStringArrays( String[] pArray1, String[] pArray2 )
1077 866 {
1078 - if ( isNullOrEmpty( pArray2 ) )
867 + if ( Objects.isNullOrEmpty( pArray2 ) )
1079 868 {
1080 869 return pArray1;
1081 870 }
1082 - if ( isNullOrEmpty( pArray1 ) )
871 + if ( Objects.isNullOrEmpty( pArray1 ) )
1083 872 {
1084 873 return pArray2;
1085 874 }
  @@ -1233,13 +1022,13 @@
1233 1022 {
1234 1023 return null;
1235 1024 }
1236 - String[] strings = new String[pObjects.length];
1025 + String[] zStrings = new String[pObjects.length];
1237 1026 for ( int i = 0; i < pObjects.length; i++ )
1238 1027 {
1239 1028 Object o = pObjects[i];
1240 - strings[i] = (o == null) ? null : o.toString();
1029 + zStrings[i] = (o == null) ? null : o.toString();
1241 1030 }
1242 - return strings;
1031 + return zStrings;
1243 1032 }
1244 1033
1245 1034 public static List<String> toStringList( Collection pCollection )
  @@ -1264,7 +1053,7 @@
1264 1053 public static Map<String, String> addPropertiesTo( Map<String, String> pMap, String... pProperty_NameValues )
1265 1054 throws IllegalArgumentException
1266 1055 {
1267 - if ( isNotNullOrEmpty( pProperty_NameValues ) )
1056 + if ( Objects.isNotNullOrEmpty( pProperty_NameValues ) )
1268 1057 {
1269 1058 if ( (pProperty_NameValues.length & 1) != 0 )
1270 1059 {
  @@ -1278,22 +1067,6 @@
1278 1067 return pMap;
1279 1068 }
1280 1069
1281 - public static String[] stringMapToStringArray( Map<String, String> pMap )
1282 - {
1283 - if ( pMap == null || pMap.isEmpty() )
1284 - {
1285 - return Strings.EMPTY_ARRAY;
1286 - }
1287 - String[] rv = new String[pMap.size() * 2];
1288 - int i = 0;
1289 - for ( Map.Entry<String, String> zEntry : pMap.entrySet() )
1290 - {
1291 - rv[i++] = zEntry.getKey();
1292 - rv[i++] = zEntry.getValue();
1293 - }
1294 - return rv;
1295 - }
1296 -
1297 1070 public static boolean isAll7BitAsciiAlpha( String pString, int pMinLength )
1298 1071 {
1299 1072 if ( (pString == null) || (pString.length() < pMinLength) )
  @@ -1591,8 +1364,8 @@
1591 1364 Object[] pTo, int pToIndex )
1592 1365 {
1593 1366 if ( (pCount > 0) && //
1594 - isNotNullOrEmpty( pFrom ) && (pFromIndex < pFrom.length) && //
1595 - isNotNullOrEmpty( pTo ) && (pToIndex < pTo.length) )
1367 + Objects.isNotNullOrEmpty( pFrom ) && (pFromIndex < pFrom.length) && //
1368 + Objects.isNotNullOrEmpty( pTo ) && (pToIndex < pTo.length) )
1596 1369 {
1597 1370 pCount = lesserOf( pCount, pTo, pToIndex = unNegateIndex( pTo, pToIndex ) );
1598 1371 pCount = lesserOf( pCount, pFrom, pFromIndex = unNegateIndex( pFrom, pFromIndex ) );