litesoft
@ 947
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 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 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 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 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 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 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.core.util; import java.util.*; import org.litesoft.commonfoundation.base.*; public class NoEqualsList<E, C extends Comparable<C>> extends NoEqualsCollection<E, C> implements List<E> { private final List<Wrapper<E, C>> mCollection = new ArrayList<Wrapper<E, C>>(); protected NoEqualsList( NoEqualsHelper<E, C> pHelper ) { super( pHelper ); } public NoEqualsList( NoEqualsHelper<E, C> pHelper, Collection<? extends E> pInitialEntries ) { this( pHelper ); if ( pInitialEntries != null ) { E[] zEntries = pInitialEntries.toArray( mHelper.createArray( pInitialEntries.size() ) ); // Snag a copy of the Entries for ( E zEntry : zEntries ) { if ( zEntry != null ) { mCollection.add( wrap( zEntry ) ); } } } } public NoEqualsList( NoEqualsHelper<E, C> pHelper, E... pInitialEntries ) { this( pHelper, (pInitialEntries != null) ? Arrays.asList( pInitialEntries ) : null ); } @Override protected final Collection<Wrapper<E, C>> LLgetCollection() { return mCollection; } /** * @param pWrap !null */ private boolean LLadd( int pIndex, Wrapper<E, C> pWrap ) { mCollection.add( pIndex, pWrap ); return true; } /** * Inserts all of the elements in the specified collection into this * list at the specified position (optional operation). Shifts the * element currently at that position (if any) and any subsequent * elements to the right (increases their indices). The new elements * will appear in this list in the order that they are returned by the * specified collection's iterator. The behavior of this operation is * undefined if the specified collection is modified while the * operation is in progress. (Note that this will occur if the specified * collection is this list, and it's nonempty.) * * @param index index at which to insert the first element from the * specified collection * @param c collection containing elements to be added to this list * * @return <tt>true</tt> if this list changed as a result of the call * * @throws UnsupportedOperationException if the <tt>addAll</tt> operation * is not supported by this list * @throws ClassCastException if the class of an element of the specified * collection prevents it from being added to this list * @throws NullPointerException if the specified collection contains one * or more null elements and this list does not permit null * elements, or if the specified collection is null * @throws IllegalArgumentException if some property of an element of the * specified collection prevents it from being added to this list * @throws IndexOutOfBoundsException if the index is out of range * (<tt>index < 0 || index > size()</tt>) */ @Override public boolean addAll( int index, Collection<? extends E> c ) { E[] zEntries = c.toArray( mHelper.createArray( 0 ) ); synchronized ( this ) { boolean anyAdded = false; for ( E zEntry : zEntries ) { anyAdded = LLadd( index++, wrapNotNull( zEntry ) ); } return LLmodified( anyAdded ); } } /** * Returns the element at the specified position in this list. * * @param index index of the element to return * * @return the element at the specified position in this list * * @throws IndexOutOfBoundsException if the index is out of range * (<tt>index < 0 || index >= size()</tt>) */ @Override public synchronized E get( int index ) { return unwrap( mCollection.get( index ) ); } /** * Replaces the element at the specified position in this list with the * specified element (optional operation). * * @param index index of the element to replace * @param element element to be stored at the specified position * * @return the element previously at the specified position * * @throws UnsupportedOperationException if the <tt>set</tt> operation * is not supported by this list * @throws ClassCastException if the class of the specified element * prevents it from being added to this list * @throws NullPointerException if the specified element is null and * this list does not permit null elements * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this list * @throws IndexOutOfBoundsException if the index is out of range * (<tt>index < 0 || index >= size()</tt>) */ @Override public synchronized E set( int index, E element ) { Wrapper<E, C> zExisting = mCollection.set( index, wrapNotNull( element ) ); LLincModificationVersion(); return unwrap( zExisting ); } /** * Inserts the specified element at the specified position in this list * (optional operation). Shifts the element currently at that position * (if any) and any subsequent elements to the right (adds one to their * indices). * * @param index index at which the specified element is to be inserted * @param element element to be inserted * * @throws UnsupportedOperationException if the <tt>add</tt> operation * is not supported by this list * @throws ClassCastException if the class of the specified element * prevents it from being added to this list * @throws NullPointerException if the specified element is null and * this list does not permit null elements * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this list * @throws IndexOutOfBoundsException if the index is out of range * (<tt>index < 0 || index > size()</tt>) */ @Override public synchronized void add( int index, E element ) { LLadd( index, wrapNotNull( element ) ); LLincModificationVersion(); } /** * Removes the element at the specified position in this list (optional * operation). Shifts any subsequent elements to the left (subtracts one * from their indices). Returns the element that was removed from the * list. * * @param index the index of the element to be removed * * @return the element previously at the specified position * * @throws UnsupportedOperationException if the <tt>remove</tt> operation * is not supported by this list * @throws IndexOutOfBoundsException if the index is out of range * (<tt>index < 0 || index >= size()</tt>) */ @Override public synchronized E remove( int index ) { Wrapper<E, C> zExisting = mCollection.remove( index ); LLincModificationVersion(); return unwrap( zExisting ); } /** * Returns the index of the first occurrence of the specified element * in this list, or -1 if this list does not contain the element. * More formally, returns the lowest index <tt>i</tt> such that * <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>, * or -1 if there is no such index. * * @param o element to search for * * @return the index of the first occurrence of the specified element in * this list, or -1 if this list does not contain the element * * @throws ClassCastException if the type of the specified element * is incompatible with this list (optional) * @throws NullPointerException if the specified element is null and this * list does not permit null elements (optional) */ @Override public synchronized int indexOf( Object o ) { return mCollection.indexOf( wrap( castNotNull( o ) ) ); } /** * Returns the index of the last occurrence of the specified element * in this list, or -1 if this list does not contain the element. * More formally, returns the highest index <tt>i</tt> such that * <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>, * or -1 if there is no such index. * * @param o element to search for * * @return the index of the last occurrence of the specified element in * this list, or -1 if this list does not contain the element * * @throws ClassCastException if the type of the specified element * is incompatible with this list (optional) * @throws NullPointerException if the specified element is null and this * list does not permit null elements (optional) */ @Override public synchronized int lastIndexOf( Object o ) { return mCollection.lastIndexOf( wrap( castNotNull( o ) ) ); } /** * Compares the specified object with this list for equality. * <p/> * Returns <tt>true</tt> if and only if the specified object is also a list, both * lists have the same size, and all corresponding pairs of elements in * the two lists are <i>equal</i>. (Two elements <tt>e1</tt> and * <tt>e2</tt> are <i>equal</i> if <tt>(e1==null ? e2==null : * e1.equals(e2))</tt>.) In other words, two lists are defined to be * equal if they contain the same elements in the same order. This * definition ensures that the equals method works properly across * different implementations of the <tt>List</tt> interface. * * @param o the object to be compared for equality with this list * * @return <tt>true</tt> if the specified object is equal to this list */ public final boolean equals( Object o ) { return (o == this) || ((o instanceof List) && LLequalsNotNull( (List<?>) o )); } public final boolean equals( List<?> them ) { return (them == this) || ((them != null) && LLequalsNotNull( them )); } private boolean LLequalsNotNull( List<?> them ) { Object[] theirObjects = them.toArray(); synchronized ( this ) { if ( LLsize() != theirObjects.length ) { return false; } if ( theirObjects.length != 0 ) { Wrapper<E, C>[] zWrappers = getWrappedEntries(); for ( int i = 0; i < zWrappers.length; i++ ) { Wrapper<E, C> zWrapper = zWrappers[i]; Object zTheirObject = theirObjects[i]; if ( !mHelper.isInstance( zTheirObject ) || !LLobjectEqualsWrapperContents( castNullOK( zTheirObject ), zWrapper ) ) { return false; } } } } return true; } private boolean LLobjectEqualsWrapperContents( E pNotNullThem, Wrapper<E, C> pWrapper ) { return (pNotNullThem == pWrapper.getObject()) || // areEqual( mHelper.getProxyValue( pNotNullThem ), pWrapper.getProxyValue() ); } /** * Returns a list iterator over the elements in this list (in proper * sequence). * * @return a list iterator over the elements in this list (in proper * sequence) */ @Override public ListIterator<E> listIterator() { return listIterator( 0 ); } /** * Returns a list iterator of the elements in this list (in proper * sequence), starting at the specified position in this list. * The specified index indicates the first element that would be * returned by an initial call to {@link ListIterator#next next}. * An initial call to {@link ListIterator#previous previous} would * return the element with the specified index minus one. * * @param index index of first element to be returned from the * list iterator (by a call to the <tt>next</tt> method) * * @return a list iterator of the elements in this list (in proper * sequence), starting at the specified position in this list * * @throws IndexOutOfBoundsException if the index is out of range * (<tt>index < 0 || index > size()</tt>) */ @Override public ListIterator<E> listIterator( int index ) { ModVersionedEntries<E, C> zModVersionedEntries = getModVersionedEntries(); int zSize = zModVersionedEntries.getWrappers().length; if ( (index < 0) || (index > zSize) ) { throw new IndexOutOfBoundsException( "Index: " + index ); } return new OurListIterator( 0, zSize, 0, zModVersionedEntries ); } private class OurListIterator extends OurIterator implements ListIterator<E> { private final int mFromIndex; private OurListIterator( int pFromIndex, int pSize, int pNextIndex, ModVersionedEntries<E, C> pModVersionedEntries ) { super( pFromIndex, pSize, pNextIndex, pModVersionedEntries ); mFromIndex = pFromIndex; } /** * Returns <tt>true</tt> if this list iterator has more elements when * traversing the list in the reverse direction. (In other words, returns * <tt>true</tt> if <tt>previous</tt> would return an element rather than * throwing an exception.) * * @return <tt>true</tt> if the list iterator has more elements when * traversing the list in the reverse direction. */ public boolean hasPrevious() { return mNextIndex > mFromIndex; } /** * Returns the previous element in the list. This method may be called * repeatedly to iterate through the list backwards, or intermixed with * calls to <tt>next</tt> to go back and forth. (Note that alternating * calls to <tt>next</tt> and <tt>previous</tt> will return the same * element repeatedly.) * * @return the previous element in the list. * * @throws NoSuchElementException if the iteration has no previous * element. */ public E previous() { checkForComodification(); if ( !hasPrevious() ) { throw new NoSuchElementException(); } return mEntries[--mNextIndex]; } /** * Returns the index of the element that would be returned by a subsequent * call to <tt>next</tt>. (Returns list size if the list iterator is at the * end of the list.) * * @return the index of the element that would be returned by a subsequent * call to <tt>next</tt>, or list size if list iterator is at end * of list. */ public int nextIndex() { return mNextIndex; } /** * Returns the index of the element that would be returned by a subsequent * call to <tt>previous</tt>. (Returns -1 if the list iterator is at the * beginning of the list.) * * @return the index of the element that would be returned by a subsequent * call to <tt>previous</tt>, or -1 if list iterator is at * beginning of list. */ public int previousIndex() { return mNextIndex - 1; } // Modification Operations /** * Replaces the last element returned by <tt>next</tt> or * <tt>previous</tt> with the specified element (optional operation). * This call can be made only if neither <tt>ListIterator.remove</tt> nor * <tt>ListIterator.add</tt> have been called after the last call to * <tt>next</tt> or <tt>previous</tt>. * * @param e the element with which to replace the last element returned by * <tt>next</tt> or <tt>previous</tt>. * * @throws UnsupportedOperationException if the <tt>set</tt> operation * is not supported by this list iterator. * @throws ClassCastException if the class of the specified element * prevents it from being added to this list. * @throws IllegalArgumentException if some aspect of the specified * element prevents it from being added to this list. * @throws IllegalStateException if neither <tt>next</tt> nor * <tt>previous</tt> have been called, or <tt>remove</tt> or * <tt>add</tt> have been called after the last call to * <tt>next</tt> or <tt>previous</tt>. */ public void set( E e ) { throw new UnsupportedOperationException(); } /** * Inserts the specified element into the list (optional operation). The * element is inserted immediately before the next element that would be * returned by <tt>next</tt>, if any, and after the next element that * would be returned by <tt>previous</tt>, if any. (If the list contains * no elements, the new element becomes the sole element on the list.) * The new element is inserted before the implicit cursor: a subsequent * call to <tt>next</tt> would be unaffected, and a subsequent call to * <tt>previous</tt> would return the new element. (This call increases * by one the value that would be returned by a call to <tt>nextIndex</tt> * or <tt>previousIndex</tt>.) * * @param e the element to insert. * * @throws UnsupportedOperationException if the <tt>add</tt> method is * not supported by this list iterator. * @throws ClassCastException if the class of the specified element * prevents it from being added to this list. * @throws IllegalArgumentException if some aspect of this element * prevents it from being added to this list. */ public void add( E e ) { throw new UnsupportedOperationException(); } } /** * Returns a view of the portion of this list between the specified * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive. (If * <tt>fromIndex</tt> and <tt>toIndex</tt> are equal, the returned list is * empty.) The returned list is backed by this list, so non-structural * changes in the returned list are reflected in this list, and vice-versa. * The returned list supports all of the optional list operations supported * by this list.<p> * <p/> * This method eliminates the need for explicit range operations (of * the sort that commonly exist for arrays). Any operation that expects * a list can be used as a range operation by passing a subList view * instead of a whole list. For example, the following idiom * removes a range of elements from a list: * <pre> * list.subList(from, to).clear(); * </pre> * Similar idioms may be constructed for <tt>indexOf</tt> and * <tt>lastIndexOf</tt>, and all of the algorithms in the * <tt>Collections</tt> class can be applied to a subList.<p> * <p/> * The semantics of the list returned by this method become undefined if * the backing list (i.e., this list) is <i>structurally modified</i> in * any way other than via the returned list. (Structural modifications are * those that change the size of this list, or otherwise perturb it in such * a fashion that iterations in progress may yield incorrect results.) * * @param fromIndex low endpoint (inclusive) of the subList * @param toIndex high endpoint (exclusive) of the subList * * @return a view of the specified range within this list * * @throws IndexOutOfBoundsException for an illegal endpoint index value * (<tt>fromIndex < 0 || toIndex > size || * fromIndex > toIndex</tt>) */ @Override public synchronized List<E> subList( int fromIndex, int toIndex ) { return new SubList( this, 0, size(), fromIndex, toIndex ); } private class SubList implements List<E> { private void checkForComodification() { LLcheckForComodification( mModificationVersion ); } private volatile int mModificationVersion; private void updateModificationVersion() { mModificationVersion = LLgetModificationVersion(); } private final List<E> mParent; private final int mAbsoluteOffset; private final int mParentOffset; private int mSize; SubList( List<E> pParent, int pParentAbsoluteOffset, int pParentSize, int pFromIndex, int pToIndex ) { if ( pFromIndex < 0 ) { throw new IndexOutOfBoundsException( "fromIndex = " + pFromIndex ); } if ( pToIndex > pParentSize ) { throw new IndexOutOfBoundsException( "toIndex = " + pToIndex ); } if ( pFromIndex > pToIndex ) { throw new IllegalArgumentException( "fromIndex(" + pFromIndex + ") > toIndex(" + pToIndex + ")" ); } mParent = pParent; mAbsoluteOffset = pParentAbsoluteOffset + (mParentOffset = pFromIndex); mSize = pToIndex - pFromIndex; updateModificationVersion(); } @Override public int size() { synchronized ( getSynchronizedObject() ) { checkForComodification(); return mSize; } } @Override public boolean isEmpty() { return size() == 0; } @Override public boolean contains( Object o ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); return mHelper.isInstance( o ) && SLLLcontains( castNullOK( o ) ); } } @Override public Iterator<E> iterator() { synchronized ( getSynchronizedObject() ) { checkForComodification(); return new OurIterator( mAbsoluteOffset, mSize, 0, getModVersionedEntries() ); } } @Override public Object[] toArray() { synchronized ( getSynchronizedObject() ) { checkForComodification(); return extractForOffsetAndSize( getWrappedEntries(), mHelper.createArray( mSize ) ); } } @Override public <T> T[] toArray( T[] a ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); return extractForOffsetAndSize( getWrappedEntries(), a ); } } @Override public boolean add( E e ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); mParent.add( mParentOffset + mSize++, e ); updateModificationVersion(); return true; } } @Override public boolean remove( Object o ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); if ( mHelper.isInstance( o ) && SLLLremove( castNullOK( o ) ) ) // Preserve Left to Right { updateModificationVersion(); return true; } return false; } } @Override public boolean containsAll( Collection<?> c ) { Object[] zThem = c.toArray(); if ( zThem.length != 0 ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); for ( Object o : zThem ) { if ( !mHelper.isInstance( o ) || !SLLLcontains( castNullOK( o ) ) ) // Preserve Left to Right { return false; } } } } return true; } @Override public boolean addAll( Collection<? extends E> c ) { E[] zThem = c.toArray( mHelper.createArray( 0 ) ); synchronized ( getSynchronizedObject() ) { checkForComodification(); return SLLLaddAll( mSize, zThem ); } } @Override public boolean addAll( int index, Collection<? extends E> c ) { E[] zThem = c.toArray( mHelper.createArray( 0 ) ); synchronized ( getSynchronizedObject() ) { checkForComodification(); return SLLLaddAll( validateIndexForInsertOrSubSet( index ), zThem ); } } /** * Removes from this list all of its elements that are contained in the * specified collection (optional operation). * * @param c collection containing elements to be removed from this list * * @return <tt>true</tt> if this list changed as a result of the call * * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation * is not supported by this list * @throws ClassCastException if the class of an element of this list * is incompatible with the specified collection (optional) * @throws NullPointerException if this list contains a null element and the * specified collection does not permit null elements (optional), * or if the specified collection is null * @see #remove(Object) * @see #contains(Object) */ @Override public boolean removeAll( Collection<?> c ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); boolean modified = false; for ( Object zToRemove : c.toArray() ) { if ( mHelper.isInstance( zToRemove ) ) { modified |= SLLLremove( castNullOK( zToRemove ) ); } } if ( modified ) { updateModificationVersion(); } return modified; } } /** * Retains only the elements in this list that are contained in the * specified collection (optional operation). In other words, removes * from this list all the elements that are not contained in the specified * collection. * * @param c collection containing elements to be retained in this list * * @return <tt>true</tt> if this list changed as a result of the call * * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation * is not supported by this list * @throws ClassCastException if the class of an element of this list * is incompatible with the specified collection (optional) * @throws NullPointerException if this list contains a null element and the * specified collection does not permit null elements (optional), * or if the specified collection is null * @see #remove(Object) * @see #contains(Object) */ @Override public boolean retainAll( Collection<?> c ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); boolean modified = false; for ( Wrapper<E, C> zWrapper : getWrappedEntries() ) { E zE = zWrapper.getObject(); if ( !c.contains( zE ) ) { modified |= SLLLremove( zE ); } } if ( modified ) { updateModificationVersion(); } return modified; } } @SuppressWarnings("ConstantConditions") @Override public void clear() { synchronized ( getSynchronizedObject() ) { checkForComodification(); if ( mSize != 0 ) { do { SLLLremove( mSize - 1 ); } while ( mSize != 0 ); updateModificationVersion(); } } } @Override public E get( int index ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); return mParent.get( mParentOffset + validateReferenceIndex( index ) ); } } @Override public E set( int index, E element ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); E zExisting = mParent.set( mParentOffset + validateReferenceIndex( index ), element ); updateModificationVersion(); return zExisting; } } @Override public void add( int index, E element ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); mParent.add( mParentOffset + validateIndexForInsertOrSubSet( index ), element ); mSize++; updateModificationVersion(); } } @Override public E remove( int index ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); E zExisting = SLLLremove( index ); updateModificationVersion(); return zExisting; } } @Override public int indexOf( Object o ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); return mHelper.isInstance( o ) ? SLLLindexOf( castNullOK( o ) ) : -1; } } @Override public int lastIndexOf( Object o ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); return mHelper.isInstance( o ) ? SLLLlastIndexOf( castNullOK( o ) ) : -1; } } @Override public ListIterator<E> listIterator() { return listIterator( 0 ); } @Override public ListIterator<E> listIterator( int index ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); return new OurListIterator( mAbsoluteOffset, mSize, validateIndexForInsertOrSubSet( index ), getModVersionedEntries() ); } } @Override public List<E> subList( int fromIndex, int toIndex ) { synchronized ( getSynchronizedObject() ) { checkForComodification(); return new SubList( this, mAbsoluteOffset, mSize, fromIndex, toIndex ); } } private <T> T[] extractForOffsetAndSize( Wrapper<E, C>[] pEntries, T[] pTargetArray ) { if ( pTargetArray == null || pTargetArray.length < mSize ) { pTargetArray = Cast.it( mHelper.createArray( mSize ) ); } int zOffset = mAbsoluteOffset; for ( int i = 0; i < mSize; i++ ) { pTargetArray[i] = Cast.it( unwrap( pEntries[zOffset++] ) ); } return pTargetArray; } private int validateIndexForInsertOrSubSet( int index ) { return validateIndex( index, (0 <= index) && (index <= mSize) ); } private int validateReferenceIndex( int index ) { return validateIndex( index, (0 <= index) && (index < mSize) ); } private int validateIndex( int index, boolean ok ) { if ( ok ) { throw new IndexOutOfBoundsException( "Index: " + index + ", Size: " + mSize ); } return index; } private boolean SLLLaddAll( int at, E[] pThem ) { if ( pThem.length == 0 ) { return false; } for ( E e : pThem ) { mParent.add( mParentOffset + at++, e ); mSize++; } updateModificationVersion(); return true; } private boolean SLLLcontains( E pE ) { return (-1 != SLLLindexOf( pE )); } /** * If Removed, adjust Size, but DON'T update version. * * @return true if removed */ private boolean SLLLremove( E pE ) { int at = SLLLindexOf( pE ); if ( at == -1 ) { return false; } SLLLremove( at ); return true; } /** * If Removed, adjust Size, but DON'T update version. */ private E SLLLremove( int index ) { E zExisting = mParent.remove( mParentOffset + validateReferenceIndex( index ) ); mSize--; return zExisting; } /** * @return Offset of Entry 'pE' (not Null), or -1 if not found */ private int SLLLindexOf( E pE ) { Wrapper<E, C>[] zWrappers = getWrappedEntries(); for ( int i = 0; i < mSize; i++ ) { if ( isMemberEqual( zWrappers, i, pE ) ) { return i; } } return -1; } /** * @return Last Offset of Entry 'pE' (not Null), or -1 if not found */ private int SLLLlastIndexOf( E pE ) { Wrapper<E, C>[] zWrappers = getWrappedEntries(); for ( int i = mSize; 0 <= --i; ) { if ( isMemberEqual( zWrappers, i, pE ) ) { return i; } } return -1; } private boolean isMemberEqual( Wrapper<E, C>[] pWrappers, int index, E pE ) { return areEqual( pWrappers[mAbsoluteOffset + index].getProxyValue(), mHelper.getProxyValue( pE ) ); } } } |
Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/util/NoEqualsList.java
Revision | Author | Commited | Message |
---|---|---|---|
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
822 Diff | GeorgeS | Sun 19 Aug, 2012 01:03:51 +0000 | |
726 Diff | GeorgeS | Thu 14 Jun, 2012 13:33:38 +0000 | |
610 Diff | GeorgeS | Mon 12 Mar, 2012 00:54:00 +0000 | |
587 Diff | GeorgeS | Fri 02 Dec, 2011 11:55:12 +0000 | Accordion... |
50 Diff | GeorgeS | Tue 13 Apr, 2010 11:51:38 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |