32 |
|
map.put(seven, "F"); |
33 |
|
assertFalse(map.isEmpty()); |
34 |
|
assertEquals(7, map.size()); |
35 |
< |
return map.navigableSubMap(one, true, seven, false); |
35 |
> |
return map.subMap(one, true, seven, false); |
36 |
> |
} |
37 |
> |
|
38 |
> |
/** |
39 |
> |
* Create a map from Integers -5 to -1 to Strings "A"-"E". |
40 |
> |
*/ |
41 |
> |
private static ConcurrentNavigableMap dmap5() { |
42 |
> |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
43 |
> |
assertTrue(map.isEmpty()); |
44 |
> |
map.put(m1, "A"); |
45 |
> |
map.put(m5, "E"); |
46 |
> |
map.put(m3, "C"); |
47 |
> |
map.put(m2, "B"); |
48 |
> |
map.put(m4, "D"); |
49 |
> |
assertFalse(map.isEmpty()); |
50 |
> |
assertEquals(5, map.size()); |
51 |
> |
return map.descendingMap(); |
52 |
|
} |
53 |
|
|
54 |
|
private static ConcurrentNavigableMap map0() { |
55 |
|
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
56 |
|
assertTrue(map.isEmpty()); |
57 |
< |
return map.navigableTailMap(one, true); |
57 |
> |
return map.tailMap(one, true); |
58 |
> |
} |
59 |
> |
|
60 |
> |
private static ConcurrentNavigableMap dmap0() { |
61 |
> |
ConcurrentSkipListMap map = new ConcurrentSkipListMap(); |
62 |
> |
assertTrue(map.isEmpty()); |
63 |
> |
return map; |
64 |
|
} |
65 |
|
|
66 |
|
/** |
760 |
|
assertEquals(1, ssm.size()); |
761 |
|
assertEquals(3, sm.size()); |
762 |
|
assertEquals(4, map.size()); |
763 |
+ |
} |
764 |
+ |
|
765 |
+ |
/** |
766 |
+ |
* clear removes all pairs |
767 |
+ |
*/ |
768 |
+ |
public void testDescendingClear() { |
769 |
+ |
ConcurrentNavigableMap map = dmap5(); |
770 |
+ |
map.clear(); |
771 |
+ |
assertEquals(map.size(), 0); |
772 |
+ |
} |
773 |
+ |
|
774 |
+ |
|
775 |
+ |
/** |
776 |
+ |
* Maps with same contents are equal |
777 |
+ |
*/ |
778 |
+ |
public void testDescendingEquals() { |
779 |
+ |
ConcurrentNavigableMap map1 = dmap5(); |
780 |
+ |
ConcurrentNavigableMap map2 = dmap5(); |
781 |
+ |
assertEquals(map1, map2); |
782 |
+ |
assertEquals(map2, map1); |
783 |
+ |
map1.clear(); |
784 |
+ |
assertFalse(map1.equals(map2)); |
785 |
+ |
assertFalse(map2.equals(map1)); |
786 |
+ |
} |
787 |
+ |
|
788 |
+ |
/** |
789 |
+ |
* containsKey returns true for contained key |
790 |
+ |
*/ |
791 |
+ |
public void testDescendingContainsKey() { |
792 |
+ |
ConcurrentNavigableMap map = dmap5(); |
793 |
+ |
assertTrue(map.containsKey(m1)); |
794 |
+ |
assertFalse(map.containsKey(zero)); |
795 |
+ |
} |
796 |
+ |
|
797 |
+ |
/** |
798 |
+ |
* containsValue returns true for held values |
799 |
+ |
*/ |
800 |
+ |
public void testDescendingContainsValue() { |
801 |
+ |
ConcurrentNavigableMap map = dmap5(); |
802 |
+ |
assertTrue(map.containsValue("A")); |
803 |
+ |
assertFalse(map.containsValue("Z")); |
804 |
+ |
} |
805 |
+ |
|
806 |
+ |
/** |
807 |
+ |
* get returns the correct element at the given key, |
808 |
+ |
* or null if not present |
809 |
+ |
*/ |
810 |
+ |
public void testDescendingGet() { |
811 |
+ |
ConcurrentNavigableMap map = dmap5(); |
812 |
+ |
assertEquals("A", (String)map.get(m1)); |
813 |
+ |
ConcurrentNavigableMap empty = dmap0(); |
814 |
+ |
assertNull(empty.get(m1)); |
815 |
+ |
} |
816 |
+ |
|
817 |
+ |
/** |
818 |
+ |
* isEmpty is true of empty map and false for non-empty |
819 |
+ |
*/ |
820 |
+ |
public void testDescendingIsEmpty() { |
821 |
+ |
ConcurrentNavigableMap empty = dmap0(); |
822 |
+ |
ConcurrentNavigableMap map = dmap5(); |
823 |
+ |
assertTrue(empty.isEmpty()); |
824 |
+ |
assertFalse(map.isEmpty()); |
825 |
+ |
} |
826 |
+ |
|
827 |
+ |
/** |
828 |
+ |
* firstKey returns first key |
829 |
+ |
*/ |
830 |
+ |
public void testDescendingFirstKey() { |
831 |
+ |
ConcurrentNavigableMap map = dmap5(); |
832 |
+ |
assertEquals(m1, map.firstKey()); |
833 |
+ |
} |
834 |
+ |
|
835 |
+ |
/** |
836 |
+ |
* lastKey returns last key |
837 |
+ |
*/ |
838 |
+ |
public void testDescendingLastKey() { |
839 |
+ |
ConcurrentNavigableMap map = dmap5(); |
840 |
+ |
assertEquals(m5, map.lastKey()); |
841 |
+ |
} |
842 |
+ |
|
843 |
+ |
|
844 |
+ |
/** |
845 |
+ |
* keySet returns a Set containing all the keys |
846 |
+ |
*/ |
847 |
+ |
public void testDescendingKeySet() { |
848 |
+ |
ConcurrentNavigableMap map = dmap5(); |
849 |
+ |
Set s = map.keySet(); |
850 |
+ |
assertEquals(5, s.size()); |
851 |
+ |
assertTrue(s.contains(m1)); |
852 |
+ |
assertTrue(s.contains(m2)); |
853 |
+ |
assertTrue(s.contains(m3)); |
854 |
+ |
assertTrue(s.contains(m4)); |
855 |
+ |
assertTrue(s.contains(m5)); |
856 |
+ |
} |
857 |
+ |
|
858 |
+ |
/** |
859 |
+ |
* keySet is ordered |
860 |
+ |
*/ |
861 |
+ |
public void testDescendingKeySetOrder() { |
862 |
+ |
ConcurrentNavigableMap map = dmap5(); |
863 |
+ |
Set s = map.keySet(); |
864 |
+ |
Iterator i = s.iterator(); |
865 |
+ |
Integer last = (Integer)i.next(); |
866 |
+ |
assertEquals(last, m1); |
867 |
+ |
while (i.hasNext()) { |
868 |
+ |
Integer k = (Integer)i.next(); |
869 |
+ |
assertTrue(last.compareTo(k) > 0); |
870 |
+ |
last = k; |
871 |
+ |
} |
872 |
+ |
} |
873 |
+ |
|
874 |
+ |
/** |
875 |
+ |
* values collection contains all values |
876 |
+ |
*/ |
877 |
+ |
public void testDescendingValues() { |
878 |
+ |
ConcurrentNavigableMap map = dmap5(); |
879 |
+ |
Collection s = map.values(); |
880 |
+ |
assertEquals(5, s.size()); |
881 |
+ |
assertTrue(s.contains("A")); |
882 |
+ |
assertTrue(s.contains("B")); |
883 |
+ |
assertTrue(s.contains("C")); |
884 |
+ |
assertTrue(s.contains("D")); |
885 |
+ |
assertTrue(s.contains("E")); |
886 |
+ |
} |
887 |
+ |
|
888 |
+ |
/** |
889 |
+ |
* keySet.toArray returns contains all keys |
890 |
+ |
*/ |
891 |
+ |
public void testDescendingAscendingKeySetToArray() { |
892 |
+ |
ConcurrentNavigableMap map = dmap5(); |
893 |
+ |
Set s = map.keySet(); |
894 |
+ |
Object[] ar = s.toArray(); |
895 |
+ |
assertTrue(s.containsAll(Arrays.asList(ar))); |
896 |
+ |
assertEquals(5, ar.length); |
897 |
+ |
ar[0] = m10; |
898 |
+ |
assertFalse(s.containsAll(Arrays.asList(ar))); |
899 |
+ |
} |
900 |
+ |
|
901 |
+ |
/** |
902 |
+ |
* descendingkeySet.toArray returns contains all keys |
903 |
+ |
*/ |
904 |
+ |
public void testDescendingDescendingKeySetToArray() { |
905 |
+ |
ConcurrentNavigableMap map = dmap5(); |
906 |
+ |
Set s = map.descendingKeySet(); |
907 |
+ |
Object[] ar = s.toArray(); |
908 |
+ |
assertEquals(5, ar.length); |
909 |
+ |
assertTrue(s.containsAll(Arrays.asList(ar))); |
910 |
+ |
ar[0] = m10; |
911 |
+ |
assertFalse(s.containsAll(Arrays.asList(ar))); |
912 |
+ |
} |
913 |
+ |
|
914 |
+ |
/** |
915 |
+ |
* Values.toArray contains all values |
916 |
+ |
*/ |
917 |
+ |
public void testDescendingValuesToArray() { |
918 |
+ |
ConcurrentNavigableMap map = dmap5(); |
919 |
+ |
Collection v = map.values(); |
920 |
+ |
Object[] ar = v.toArray(); |
921 |
+ |
ArrayList s = new ArrayList(Arrays.asList(ar)); |
922 |
+ |
assertEquals(5, ar.length); |
923 |
+ |
assertTrue(s.contains("A")); |
924 |
+ |
assertTrue(s.contains("B")); |
925 |
+ |
assertTrue(s.contains("C")); |
926 |
+ |
assertTrue(s.contains("D")); |
927 |
+ |
assertTrue(s.contains("E")); |
928 |
+ |
} |
929 |
+ |
|
930 |
+ |
|
931 |
+ |
/** |
932 |
+ |
* entrySet contains all pairs |
933 |
+ |
*/ |
934 |
+ |
public void testDescendingEntrySet() { |
935 |
+ |
ConcurrentNavigableMap map = dmap5(); |
936 |
+ |
Set s = map.entrySet(); |
937 |
+ |
assertEquals(5, s.size()); |
938 |
+ |
Iterator it = s.iterator(); |
939 |
+ |
while (it.hasNext()) { |
940 |
+ |
Map.Entry e = (Map.Entry) it.next(); |
941 |
+ |
assertTrue( |
942 |
+ |
(e.getKey().equals(m1) && e.getValue().equals("A")) || |
943 |
+ |
(e.getKey().equals(m2) && e.getValue().equals("B")) || |
944 |
+ |
(e.getKey().equals(m3) && e.getValue().equals("C")) || |
945 |
+ |
(e.getKey().equals(m4) && e.getValue().equals("D")) || |
946 |
+ |
(e.getKey().equals(m5) && e.getValue().equals("E"))); |
947 |
+ |
} |
948 |
+ |
} |
949 |
+ |
|
950 |
+ |
/** |
951 |
+ |
* putAll adds all key-value pairs from the given map |
952 |
+ |
*/ |
953 |
+ |
public void testDescendingPutAll() { |
954 |
+ |
ConcurrentNavigableMap empty = dmap0(); |
955 |
+ |
ConcurrentNavigableMap map = dmap5(); |
956 |
+ |
empty.putAll(map); |
957 |
+ |
assertEquals(5, empty.size()); |
958 |
+ |
assertTrue(empty.containsKey(m1)); |
959 |
+ |
assertTrue(empty.containsKey(m2)); |
960 |
+ |
assertTrue(empty.containsKey(m3)); |
961 |
+ |
assertTrue(empty.containsKey(m4)); |
962 |
+ |
assertTrue(empty.containsKey(m5)); |
963 |
+ |
} |
964 |
+ |
|
965 |
+ |
/** |
966 |
+ |
* putIfAbsent works when the given key is not present |
967 |
+ |
*/ |
968 |
+ |
public void testDescendingPutIfAbsent() { |
969 |
+ |
ConcurrentNavigableMap map = dmap5(); |
970 |
+ |
map.putIfAbsent(six, "Z"); |
971 |
+ |
assertTrue(map.containsKey(six)); |
972 |
+ |
} |
973 |
+ |
|
974 |
+ |
/** |
975 |
+ |
* putIfAbsent does not add the pair if the key is already present |
976 |
+ |
*/ |
977 |
+ |
public void testDescendingPutIfAbsent2() { |
978 |
+ |
ConcurrentNavigableMap map = dmap5(); |
979 |
+ |
assertEquals("A", map.putIfAbsent(m1, "Z")); |
980 |
+ |
} |
981 |
+ |
|
982 |
+ |
/** |
983 |
+ |
* replace fails when the given key is not present |
984 |
+ |
*/ |
985 |
+ |
public void testDescendingReplace() { |
986 |
+ |
ConcurrentNavigableMap map = dmap5(); |
987 |
+ |
assertNull(map.replace(six, "Z")); |
988 |
+ |
assertFalse(map.containsKey(six)); |
989 |
+ |
} |
990 |
+ |
|
991 |
+ |
/** |
992 |
+ |
* replace succeeds if the key is already present |
993 |
+ |
*/ |
994 |
+ |
public void testDescendingReplace2() { |
995 |
+ |
ConcurrentNavigableMap map = dmap5(); |
996 |
+ |
assertNotNull(map.replace(m1, "Z")); |
997 |
+ |
assertEquals("Z", map.get(m1)); |
998 |
+ |
} |
999 |
+ |
|
1000 |
+ |
|
1001 |
+ |
/** |
1002 |
+ |
* replace value fails when the given key not mapped to expected value |
1003 |
+ |
*/ |
1004 |
+ |
public void testDescendingReplaceValue() { |
1005 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1006 |
+ |
assertEquals("A", map.get(m1)); |
1007 |
+ |
assertFalse(map.replace(m1, "Z", "Z")); |
1008 |
+ |
assertEquals("A", map.get(m1)); |
1009 |
+ |
} |
1010 |
+ |
|
1011 |
+ |
/** |
1012 |
+ |
* replace value succeeds when the given key mapped to expected value |
1013 |
+ |
*/ |
1014 |
+ |
public void testDescendingReplaceValue2() { |
1015 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1016 |
+ |
assertEquals("A", map.get(m1)); |
1017 |
+ |
assertTrue(map.replace(m1, "A", "Z")); |
1018 |
+ |
assertEquals("Z", map.get(m1)); |
1019 |
+ |
} |
1020 |
+ |
|
1021 |
+ |
|
1022 |
+ |
/** |
1023 |
+ |
* remove removes the correct key-value pair from the map |
1024 |
+ |
*/ |
1025 |
+ |
public void testDescendingRemove() { |
1026 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1027 |
+ |
map.remove(m5); |
1028 |
+ |
assertEquals(4, map.size()); |
1029 |
+ |
assertFalse(map.containsKey(m5)); |
1030 |
+ |
} |
1031 |
+ |
|
1032 |
+ |
/** |
1033 |
+ |
* remove(key,value) removes only if pair present |
1034 |
+ |
*/ |
1035 |
+ |
public void testDescendingRemove2() { |
1036 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1037 |
+ |
assertTrue(map.containsKey(m5)); |
1038 |
+ |
assertEquals("E", map.get(m5)); |
1039 |
+ |
map.remove(m5, "E"); |
1040 |
+ |
assertEquals(4, map.size()); |
1041 |
+ |
assertFalse(map.containsKey(m5)); |
1042 |
+ |
map.remove(m4, "A"); |
1043 |
+ |
assertEquals(4, map.size()); |
1044 |
+ |
assertTrue(map.containsKey(m4)); |
1045 |
+ |
|
1046 |
+ |
} |
1047 |
+ |
|
1048 |
+ |
/** |
1049 |
+ |
* lowerEntry returns preceding entry. |
1050 |
+ |
*/ |
1051 |
+ |
public void testDescendingLowerEntry() { |
1052 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1053 |
+ |
Map.Entry e1 = map.lowerEntry(m3); |
1054 |
+ |
assertEquals(m2, e1.getKey()); |
1055 |
+ |
|
1056 |
+ |
Map.Entry e2 = map.lowerEntry(m6); |
1057 |
+ |
assertEquals(m5, e2.getKey()); |
1058 |
+ |
|
1059 |
+ |
Map.Entry e3 = map.lowerEntry(m1); |
1060 |
+ |
assertNull(e3); |
1061 |
+ |
|
1062 |
+ |
Map.Entry e4 = map.lowerEntry(zero); |
1063 |
+ |
assertNull(e4); |
1064 |
+ |
|
1065 |
+ |
} |
1066 |
+ |
|
1067 |
+ |
/** |
1068 |
+ |
* higherEntry returns next entry. |
1069 |
+ |
*/ |
1070 |
+ |
public void testDescendingHigherEntry() { |
1071 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1072 |
+ |
Map.Entry e1 = map.higherEntry(m3); |
1073 |
+ |
assertEquals(m4, e1.getKey()); |
1074 |
+ |
|
1075 |
+ |
Map.Entry e2 = map.higherEntry(zero); |
1076 |
+ |
assertEquals(m1, e2.getKey()); |
1077 |
+ |
|
1078 |
+ |
Map.Entry e3 = map.higherEntry(m5); |
1079 |
+ |
assertNull(e3); |
1080 |
+ |
|
1081 |
+ |
Map.Entry e4 = map.higherEntry(m6); |
1082 |
+ |
assertNull(e4); |
1083 |
+ |
|
1084 |
+ |
} |
1085 |
+ |
|
1086 |
+ |
/** |
1087 |
+ |
* floorEntry returns preceding entry. |
1088 |
+ |
*/ |
1089 |
+ |
public void testDescendingFloorEntry() { |
1090 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1091 |
+ |
Map.Entry e1 = map.floorEntry(m3); |
1092 |
+ |
assertEquals(m3, e1.getKey()); |
1093 |
+ |
|
1094 |
+ |
Map.Entry e2 = map.floorEntry(m6); |
1095 |
+ |
assertEquals(m5, e2.getKey()); |
1096 |
+ |
|
1097 |
+ |
Map.Entry e3 = map.floorEntry(m1); |
1098 |
+ |
assertEquals(m1, e3.getKey()); |
1099 |
+ |
|
1100 |
+ |
Map.Entry e4 = map.floorEntry(zero); |
1101 |
+ |
assertNull(e4); |
1102 |
+ |
|
1103 |
+ |
} |
1104 |
+ |
|
1105 |
+ |
/** |
1106 |
+ |
* ceilingEntry returns next entry. |
1107 |
+ |
*/ |
1108 |
+ |
public void testDescendingCeilingEntry() { |
1109 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1110 |
+ |
Map.Entry e1 = map.ceilingEntry(m3); |
1111 |
+ |
assertEquals(m3, e1.getKey()); |
1112 |
+ |
|
1113 |
+ |
Map.Entry e2 = map.ceilingEntry(zero); |
1114 |
+ |
assertEquals(m1, e2.getKey()); |
1115 |
+ |
|
1116 |
+ |
Map.Entry e3 = map.ceilingEntry(m5); |
1117 |
+ |
assertEquals(m5, e3.getKey()); |
1118 |
+ |
|
1119 |
+ |
Map.Entry e4 = map.ceilingEntry(m6); |
1120 |
+ |
assertNull(e4); |
1121 |
+ |
|
1122 |
+ |
} |
1123 |
+ |
|
1124 |
+ |
/** |
1125 |
+ |
* pollFirstEntry returns entries in order |
1126 |
+ |
*/ |
1127 |
+ |
public void testDescendingPollFirstEntry() { |
1128 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1129 |
+ |
Map.Entry e = map.pollFirstEntry(); |
1130 |
+ |
assertEquals(m1, e.getKey()); |
1131 |
+ |
assertEquals("A", e.getValue()); |
1132 |
+ |
e = map.pollFirstEntry(); |
1133 |
+ |
assertEquals(m2, e.getKey()); |
1134 |
+ |
map.put(m1, "A"); |
1135 |
+ |
e = map.pollFirstEntry(); |
1136 |
+ |
assertEquals(m1, e.getKey()); |
1137 |
+ |
assertEquals("A", e.getValue()); |
1138 |
+ |
e = map.pollFirstEntry(); |
1139 |
+ |
assertEquals(m3, e.getKey()); |
1140 |
+ |
map.remove(m4); |
1141 |
+ |
e = map.pollFirstEntry(); |
1142 |
+ |
assertEquals(m5, e.getKey()); |
1143 |
+ |
try { |
1144 |
+ |
e.setValue("A"); |
1145 |
+ |
shouldThrow(); |
1146 |
+ |
} catch (Exception ok) { |
1147 |
+ |
} |
1148 |
+ |
e = map.pollFirstEntry(); |
1149 |
+ |
assertNull(e); |
1150 |
+ |
} |
1151 |
+ |
|
1152 |
+ |
/** |
1153 |
+ |
* pollLastEntry returns entries in order |
1154 |
+ |
*/ |
1155 |
+ |
public void testDescendingPollLastEntry() { |
1156 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1157 |
+ |
Map.Entry e = map.pollLastEntry(); |
1158 |
+ |
assertEquals(m5, e.getKey()); |
1159 |
+ |
assertEquals("E", e.getValue()); |
1160 |
+ |
e = map.pollLastEntry(); |
1161 |
+ |
assertEquals(m4, e.getKey()); |
1162 |
+ |
map.put(m5, "E"); |
1163 |
+ |
e = map.pollLastEntry(); |
1164 |
+ |
assertEquals(m5, e.getKey()); |
1165 |
+ |
assertEquals("E", e.getValue()); |
1166 |
+ |
e = map.pollLastEntry(); |
1167 |
+ |
assertEquals(m3, e.getKey()); |
1168 |
+ |
map.remove(m2); |
1169 |
+ |
e = map.pollLastEntry(); |
1170 |
+ |
assertEquals(m1, e.getKey()); |
1171 |
+ |
try { |
1172 |
+ |
e.setValue("E"); |
1173 |
+ |
shouldThrow(); |
1174 |
+ |
} catch (Exception ok) { |
1175 |
+ |
} |
1176 |
+ |
e = map.pollLastEntry(); |
1177 |
+ |
assertNull(e); |
1178 |
+ |
} |
1179 |
+ |
|
1180 |
+ |
/** |
1181 |
+ |
* size returns the correct values |
1182 |
+ |
*/ |
1183 |
+ |
public void testDescendingSize() { |
1184 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1185 |
+ |
ConcurrentNavigableMap empty = dmap0(); |
1186 |
+ |
assertEquals(0, empty.size()); |
1187 |
+ |
assertEquals(5, map.size()); |
1188 |
+ |
} |
1189 |
+ |
|
1190 |
+ |
/** |
1191 |
+ |
* toString contains toString of elements |
1192 |
+ |
*/ |
1193 |
+ |
public void testDescendingToString() { |
1194 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1195 |
+ |
String s = map.toString(); |
1196 |
+ |
for (int i = 1; i <= 5; ++i) { |
1197 |
+ |
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
1198 |
+ |
} |
1199 |
+ |
} |
1200 |
+ |
|
1201 |
+ |
// Exception testDescendings |
1202 |
+ |
|
1203 |
+ |
/** |
1204 |
+ |
* get(null) of nm1mpty map throws NPE |
1205 |
+ |
*/ |
1206 |
+ |
public void testDescendingGet_NullPointerException() { |
1207 |
+ |
try { |
1208 |
+ |
ConcurrentNavigableMap c = dmap5(); |
1209 |
+ |
c.get(null); |
1210 |
+ |
shouldThrow(); |
1211 |
+ |
} catch(NullPointerException e){} |
1212 |
+ |
} |
1213 |
+ |
|
1214 |
+ |
/** |
1215 |
+ |
* containsKey(null) of nm1mpty map throws NPE |
1216 |
+ |
*/ |
1217 |
+ |
public void testDescendingContainsKey_NullPointerException() { |
1218 |
+ |
try { |
1219 |
+ |
ConcurrentNavigableMap c = dmap5(); |
1220 |
+ |
c.containsKey(null); |
1221 |
+ |
shouldThrow(); |
1222 |
+ |
} catch(NullPointerException e){} |
1223 |
+ |
} |
1224 |
+ |
|
1225 |
+ |
/** |
1226 |
+ |
* containsValue(null) throws NPE |
1227 |
+ |
*/ |
1228 |
+ |
public void testDescendingContainsValue_NullPointerException() { |
1229 |
+ |
try { |
1230 |
+ |
ConcurrentNavigableMap c = dmap0(); |
1231 |
+ |
c.containsValue(null); |
1232 |
+ |
shouldThrow(); |
1233 |
+ |
} catch(NullPointerException e){} |
1234 |
+ |
} |
1235 |
+ |
|
1236 |
+ |
|
1237 |
+ |
/** |
1238 |
+ |
* put(null,x) throws NPE |
1239 |
+ |
*/ |
1240 |
+ |
public void testDescendingPut1_NullPointerException() { |
1241 |
+ |
try { |
1242 |
+ |
ConcurrentNavigableMap c = dmap5(); |
1243 |
+ |
c.put(null, "whatever"); |
1244 |
+ |
shouldThrow(); |
1245 |
+ |
} catch(NullPointerException e){} |
1246 |
+ |
} |
1247 |
+ |
|
1248 |
+ |
/** |
1249 |
+ |
* putIfAbsent(null, x) throws NPE |
1250 |
+ |
*/ |
1251 |
+ |
public void testDescendingPutIfAbsent1_NullPointerException() { |
1252 |
+ |
try { |
1253 |
+ |
ConcurrentNavigableMap c = dmap5(); |
1254 |
+ |
c.putIfAbsent(null, "whatever"); |
1255 |
+ |
shouldThrow(); |
1256 |
+ |
} catch(NullPointerException e){} |
1257 |
+ |
} |
1258 |
+ |
|
1259 |
+ |
/** |
1260 |
+ |
* replace(null, x) throws NPE |
1261 |
+ |
*/ |
1262 |
+ |
public void testDescendingReplace_NullPointerException() { |
1263 |
+ |
try { |
1264 |
+ |
ConcurrentNavigableMap c = dmap5(); |
1265 |
+ |
c.replace(null, "whatever"); |
1266 |
+ |
shouldThrow(); |
1267 |
+ |
} catch(NullPointerException e){} |
1268 |
+ |
} |
1269 |
+ |
|
1270 |
+ |
/** |
1271 |
+ |
* replace(null, x, y) throws NPE |
1272 |
+ |
*/ |
1273 |
+ |
public void testDescendingReplaceValue_NullPointerException() { |
1274 |
+ |
try { |
1275 |
+ |
ConcurrentNavigableMap c = dmap5(); |
1276 |
+ |
c.replace(null, m1, "whatever"); |
1277 |
+ |
shouldThrow(); |
1278 |
+ |
} catch(NullPointerException e){} |
1279 |
+ |
} |
1280 |
+ |
|
1281 |
+ |
/** |
1282 |
+ |
* remove(null) throws NPE |
1283 |
+ |
*/ |
1284 |
+ |
public void testDescendingRemove1_NullPointerException() { |
1285 |
+ |
try { |
1286 |
+ |
ConcurrentNavigableMap c = dmap5(); |
1287 |
+ |
c.remove(null); |
1288 |
+ |
shouldThrow(); |
1289 |
+ |
} catch(NullPointerException e){} |
1290 |
+ |
} |
1291 |
+ |
|
1292 |
+ |
/** |
1293 |
+ |
* remove(null, x) throws NPE |
1294 |
+ |
*/ |
1295 |
+ |
public void testDescendingRemove2_NullPointerException() { |
1296 |
+ |
try { |
1297 |
+ |
ConcurrentNavigableMap c = dmap5(); |
1298 |
+ |
c.remove(null, "whatever"); |
1299 |
+ |
shouldThrow(); |
1300 |
+ |
} catch(NullPointerException e){} |
1301 |
+ |
} |
1302 |
+ |
|
1303 |
+ |
/** |
1304 |
+ |
* A deserialized map equals original |
1305 |
+ |
*/ |
1306 |
+ |
public void testDescendingSerialization() { |
1307 |
+ |
ConcurrentNavigableMap q = dmap5(); |
1308 |
+ |
|
1309 |
+ |
try { |
1310 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
1311 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
1312 |
+ |
out.writeObject(q); |
1313 |
+ |
out.close(); |
1314 |
+ |
|
1315 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
1316 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
1317 |
+ |
ConcurrentNavigableMap r = (ConcurrentNavigableMap)in.readObject(); |
1318 |
+ |
assertEquals(q.size(), r.size()); |
1319 |
+ |
assertTrue(q.equals(r)); |
1320 |
+ |
assertTrue(r.equals(q)); |
1321 |
+ |
} catch(Exception e){ |
1322 |
+ |
e.printStackTrace(); |
1323 |
+ |
unexpectedException(); |
1324 |
+ |
} |
1325 |
+ |
} |
1326 |
+ |
|
1327 |
+ |
|
1328 |
+ |
|
1329 |
+ |
/** |
1330 |
+ |
* subMap returns map with keys in requested range |
1331 |
+ |
*/ |
1332 |
+ |
public void testDescendingSubMapContents() { |
1333 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1334 |
+ |
SortedMap sm = map.subMap(m2, m4); |
1335 |
+ |
assertEquals(m2, sm.firstKey()); |
1336 |
+ |
assertEquals(m3, sm.lastKey()); |
1337 |
+ |
assertEquals(2, sm.size()); |
1338 |
+ |
assertFalse(sm.containsKey(m1)); |
1339 |
+ |
assertTrue(sm.containsKey(m2)); |
1340 |
+ |
assertTrue(sm.containsKey(m3)); |
1341 |
+ |
assertFalse(sm.containsKey(m4)); |
1342 |
+ |
assertFalse(sm.containsKey(m5)); |
1343 |
+ |
Iterator i = sm.keySet().iterator(); |
1344 |
+ |
Object k; |
1345 |
+ |
k = (Integer)(i.next()); |
1346 |
+ |
assertEquals(m2, k); |
1347 |
+ |
k = (Integer)(i.next()); |
1348 |
+ |
assertEquals(m3, k); |
1349 |
+ |
assertFalse(i.hasNext()); |
1350 |
+ |
Iterator j = sm.keySet().iterator(); |
1351 |
+ |
j.next(); |
1352 |
+ |
j.remove(); |
1353 |
+ |
assertFalse(map.containsKey(m2)); |
1354 |
+ |
assertEquals(4, map.size()); |
1355 |
+ |
assertEquals(1, sm.size()); |
1356 |
+ |
assertEquals(m3, sm.firstKey()); |
1357 |
+ |
assertEquals(m3, sm.lastKey()); |
1358 |
+ |
assertTrue(sm.remove(m3) != null); |
1359 |
+ |
assertTrue(sm.isEmpty()); |
1360 |
+ |
assertEquals(3, map.size()); |
1361 |
+ |
} |
1362 |
+ |
|
1363 |
+ |
public void testDescendingSubMapContents2() { |
1364 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1365 |
+ |
SortedMap sm = map.subMap(m2, m3); |
1366 |
+ |
assertEquals(1, sm.size()); |
1367 |
+ |
assertEquals(m2, sm.firstKey()); |
1368 |
+ |
assertEquals(m2, sm.lastKey()); |
1369 |
+ |
assertFalse(sm.containsKey(m1)); |
1370 |
+ |
assertTrue(sm.containsKey(m2)); |
1371 |
+ |
assertFalse(sm.containsKey(m3)); |
1372 |
+ |
assertFalse(sm.containsKey(m4)); |
1373 |
+ |
assertFalse(sm.containsKey(m5)); |
1374 |
+ |
Iterator i = sm.keySet().iterator(); |
1375 |
+ |
Object k; |
1376 |
+ |
k = (Integer)(i.next()); |
1377 |
+ |
assertEquals(m2, k); |
1378 |
+ |
assertFalse(i.hasNext()); |
1379 |
+ |
Iterator j = sm.keySet().iterator(); |
1380 |
+ |
j.next(); |
1381 |
+ |
j.remove(); |
1382 |
+ |
assertFalse(map.containsKey(m2)); |
1383 |
+ |
assertEquals(4, map.size()); |
1384 |
+ |
assertEquals(0, sm.size()); |
1385 |
+ |
assertTrue(sm.isEmpty()); |
1386 |
+ |
assertTrue(sm.remove(m3) == null); |
1387 |
+ |
assertEquals(4, map.size()); |
1388 |
+ |
} |
1389 |
+ |
|
1390 |
+ |
/** |
1391 |
+ |
* headMap returns map with keys in requested range |
1392 |
+ |
*/ |
1393 |
+ |
public void testDescendingHeadMapContents() { |
1394 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1395 |
+ |
SortedMap sm = map.headMap(m4); |
1396 |
+ |
assertTrue(sm.containsKey(m1)); |
1397 |
+ |
assertTrue(sm.containsKey(m2)); |
1398 |
+ |
assertTrue(sm.containsKey(m3)); |
1399 |
+ |
assertFalse(sm.containsKey(m4)); |
1400 |
+ |
assertFalse(sm.containsKey(m5)); |
1401 |
+ |
Iterator i = sm.keySet().iterator(); |
1402 |
+ |
Object k; |
1403 |
+ |
k = (Integer)(i.next()); |
1404 |
+ |
assertEquals(m1, k); |
1405 |
+ |
k = (Integer)(i.next()); |
1406 |
+ |
assertEquals(m2, k); |
1407 |
+ |
k = (Integer)(i.next()); |
1408 |
+ |
assertEquals(m3, k); |
1409 |
+ |
assertFalse(i.hasNext()); |
1410 |
+ |
sm.clear(); |
1411 |
+ |
assertTrue(sm.isEmpty()); |
1412 |
+ |
assertEquals(2, map.size()); |
1413 |
+ |
assertEquals(m4, map.firstKey()); |
1414 |
+ |
} |
1415 |
+ |
|
1416 |
+ |
/** |
1417 |
+ |
* headMap returns map with keys in requested range |
1418 |
+ |
*/ |
1419 |
+ |
public void testDescendingTailMapContents() { |
1420 |
+ |
ConcurrentNavigableMap map = dmap5(); |
1421 |
+ |
SortedMap sm = map.tailMap(m2); |
1422 |
+ |
assertFalse(sm.containsKey(m1)); |
1423 |
+ |
assertTrue(sm.containsKey(m2)); |
1424 |
+ |
assertTrue(sm.containsKey(m3)); |
1425 |
+ |
assertTrue(sm.containsKey(m4)); |
1426 |
+ |
assertTrue(sm.containsKey(m5)); |
1427 |
+ |
Iterator i = sm.keySet().iterator(); |
1428 |
+ |
Object k; |
1429 |
+ |
k = (Integer)(i.next()); |
1430 |
+ |
assertEquals(m2, k); |
1431 |
+ |
k = (Integer)(i.next()); |
1432 |
+ |
assertEquals(m3, k); |
1433 |
+ |
k = (Integer)(i.next()); |
1434 |
+ |
assertEquals(m4, k); |
1435 |
+ |
k = (Integer)(i.next()); |
1436 |
+ |
assertEquals(m5, k); |
1437 |
+ |
assertFalse(i.hasNext()); |
1438 |
+ |
|
1439 |
+ |
Iterator ei = sm.entrySet().iterator(); |
1440 |
+ |
Map.Entry e; |
1441 |
+ |
e = (Map.Entry)(ei.next()); |
1442 |
+ |
assertEquals(m2, e.getKey()); |
1443 |
+ |
assertEquals("B", e.getValue()); |
1444 |
+ |
e = (Map.Entry)(ei.next()); |
1445 |
+ |
assertEquals(m3, e.getKey()); |
1446 |
+ |
assertEquals("C", e.getValue()); |
1447 |
+ |
e = (Map.Entry)(ei.next()); |
1448 |
+ |
assertEquals(m4, e.getKey()); |
1449 |
+ |
assertEquals("D", e.getValue()); |
1450 |
+ |
e = (Map.Entry)(ei.next()); |
1451 |
+ |
assertEquals(m5, e.getKey()); |
1452 |
+ |
assertEquals("E", e.getValue()); |
1453 |
+ |
assertFalse(i.hasNext()); |
1454 |
+ |
|
1455 |
+ |
SortedMap ssm = sm.tailMap(m4); |
1456 |
+ |
assertEquals(m4, ssm.firstKey()); |
1457 |
+ |
assertEquals(m5, ssm.lastKey()); |
1458 |
+ |
assertTrue(ssm.remove(m4) != null); |
1459 |
+ |
assertEquals(1, ssm.size()); |
1460 |
+ |
assertEquals(3, sm.size()); |
1461 |
+ |
assertEquals(4, map.size()); |
1462 |
|
} |
1463 |
|
|
1464 |
|
} |