Ignore:
Timestamp:
2014-01-17T21:33:44+01:00 (10 years ago)
Author:
Don-vip
Message:

where applicable, replace System.arraycopy by Arrays.copyOf

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/CopyList.java

    r6380 r6717  
    33
    44import java.util.AbstractList;
     5import java.util.Arrays;
    56import java.util.ConcurrentModificationException;
    67import java.util.Iterator;
     
    129130    }
    130131
    131     @SuppressWarnings("unchecked")
    132132    private void ensureCapacity(int target) {
    133133        modCount++;
    134134        if (target > array.length) {
    135             E[] old = array;
    136 
    137135            int newCapacity = Math.max(target, (array.length * 3)/2 + 1);
    138             array = (E[]) new Object[newCapacity];
    139             System.arraycopy(old, 0, array, 0, size);
     136            array = Arrays.copyOf(array, newCapacity);
    140137            pristine = false;
    141138        }
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6661 r6717  
    952952        return result;
    953953    }
     954   
     955    /**
     956     * Adds the given item at the end of a new copy of given array.
     957     * @param array The source array
     958     * @param item The item to add
     959     * @return An extended copy of {@code array} containing {@code item} as additional last element
     960     * @since 6717
     961     */
     962    public static <T> T[] addInArrayCopy(T[] array, T item) {
     963        T[] biggerCopy = Arrays.copyOf(array, array.length + 1);
     964        biggerCopy[array.length] = item;
     965        return biggerCopy;
     966    }
    954967}
Note: See TracChangeset for help on using the changeset viewer.