1 7 8 10 package java.nio; 11 12 13 14 15 16 239 240 public abstract class IntBuffer 241 extends Buffer 242 implements Comparable <IntBuffer > 243 { 244 245 final int[] hb; final int offset; 251 boolean isReadOnly; 253 IntBuffer(int mark, int pos, int lim, int cap, int[] hb, int offset) 258 { 259 super(mark, pos, lim, cap); 260 this.hb = hb; 261 this.offset = offset; 262 } 263 264 IntBuffer(int mark, int pos, int lim, int cap) { this(mark, pos, lim, cap, null, 0); 268 } 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 309 public static IntBuffer allocate(int capacity) { 310 if (capacity < 0) 311 throw new IllegalArgumentException (); 312 return new HeapIntBuffer (capacity, capacity); 313 } 314 315 346 public static IntBuffer wrap(int[] array, 347 int offset, int length) 348 { 349 try { 350 return new HeapIntBuffer (array, offset, length); 351 } catch (IllegalArgumentException x) { 352 throw new IndexOutOfBoundsException (); 353 } 354 } 355 356 372 public static IntBuffer wrap(int[] array) { 373 return wrap(array, 0, array.length); 374 } 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 485 public abstract IntBuffer slice(); 486 487 502 public abstract IntBuffer duplicate(); 503 504 522 public abstract IntBuffer asReadOnlyBuffer(); 523 524 525 527 536 public abstract int get(); 537 538 555 public abstract IntBuffer put(int i); 556 557 570 public abstract int get(int index); 571 572 593 public abstract IntBuffer put(int index, int i); 594 595 596 598 647 public IntBuffer get(int[] dst, int offset, int length) { 648 checkBounds(offset, length, dst.length); 649 if (length > remaining()) 650 throw new BufferUnderflowException (); 651 int end = offset + length; 652 for (int i = offset; i < end; i++) 653 dst[i] = get(); 654 return this; 655 } 656 657 673 public IntBuffer get(int[] dst) { 674 return get(dst, 0, dst.length); 675 } 676 677 678 680 721 public IntBuffer put(IntBuffer src) { 722 if (src == this) 723 throw new IllegalArgumentException (); 724 int n = src.remaining(); 725 if (n > remaining()) 726 throw new BufferOverflowException (); 727 for (int i = 0; i < n; i++) 728 put(src.get()); 729 return this; 730 } 731 732 782 public IntBuffer put(int[] src, int offset, int length) { 783 checkBounds(offset, length, src.length); 784 if (length > remaining()) 785 throw new BufferOverflowException (); 786 int end = offset + length; 787 for (int i = offset; i < end; i++) 788 this.put(src[i]); 789 return this; 790 } 791 792 811 public final IntBuffer put(int[] src) { 812 return put(src, 0, src.length); 813 } 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 903 914 public final boolean hasArray() { 915 return (hb != null) && !isReadOnly; 916 } 917 918 937 public final int[] array() { 938 if (hb == null) 939 throw new UnsupportedOperationException (); 940 if (isReadOnly) 941 throw new ReadOnlyBufferException (); 942 return hb; 943 } 944 945 965 public final int arrayOffset() { 966 if (hb == null) 967 throw new UnsupportedOperationException (); 968 if (isReadOnly) 969 throw new ReadOnlyBufferException (); 970 return offset; 971 } 972 973 1014 public abstract IntBuffer compact(); 1015 1016 1021 public abstract boolean isDirect(); 1022 1023 1024 1025 1030 public String toString() { 1031 StringBuffer sb = new StringBuffer (); 1032 sb.append(getClass().getName()); 1033 sb.append("[pos="); 1034 sb.append(position()); 1035 sb.append(" lim="); 1036 sb.append(limit()); 1037 sb.append(" cap="); 1038 sb.append(capacity()); 1039 sb.append("]"); 1040 return sb.toString(); 1041 } 1042 1043 1044 1045 1046 1047 1048 1061 public int hashCode() { 1062 int h = 1; 1063 int p = position(); 1064 for (int i = limit() - 1; i >= p; i--) 1065 h = 31 * h + (int)get(i); 1066 return h; 1067 } 1068 1069 1094 public boolean equals(Object ob) { 1095 if (!(ob instanceof IntBuffer )) 1096 return false; 1097 IntBuffer that = (IntBuffer )ob; 1098 if (this.remaining() != that.remaining()) 1099 return false; 1100 int p = this.position(); 1101 for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) { 1102 int v1 = this.get(i); 1103 int v2 = that.get(j); 1104 if (v1 != v2) { 1105 if ((v1 != v1) && (v2 != v2)) continue; 1107 return false; 1108 } 1109 } 1110 return true; 1111 } 1112 1113 1125 public int compareTo(IntBuffer that) { 1126 int n = this.position() + Math.min(this.remaining(), that.remaining()); 1127 for (int i = this.position(), j = that.position(); i < n; i++, j++) { 1128 int v1 = this.get(i); 1129 int v2 = that.get(j); 1130 if (v1 == v2) 1131 continue; 1132 if ((v1 != v1) && (v2 != v2)) continue; 1134 if (v1 < v2) 1135 return -1; 1136 return +1; 1137 } 1138 return this.remaining() - that.remaining(); 1139 } 1140 1141 1142 1143 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1340 1341 1342 1354 public abstract ByteOrder order(); 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408} 1409 | Popular Tags |