Changeset 6717 in josm


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

where applicable, replace System.arraycopy by Arrays.copyOf

Location:
trunk/src/org/openstreetmap/josm
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r6639 r6717  
    2626import org.openstreetmap.josm.tools.CheckParameterUtil;
    2727import org.openstreetmap.josm.tools.Predicate;
     28import org.openstreetmap.josm.tools.Utils;
    2829import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
    2930
     
    924925    /**
    925926     * Add new referrer. If referrer is already included then no action is taken
    926      * @param referrer
     927     * @param referrer The referrer to add
    927928     */
    928929    protected void addReferrer(OsmPrimitive referrer) {
    929         // Based on methods from josm-ng
    930930        if (referrers == null) {
    931931            referrers = referrer;
     
    939939                    return;
    940940            }
    941             OsmPrimitive[] orig = (OsmPrimitive[])referrers;
    942             OsmPrimitive[] bigger = new OsmPrimitive[orig.length+1];
    943             System.arraycopy(orig, 0, bigger, 0, orig.length);
    944             bigger[orig.length] = referrer;
    945             referrers = bigger;
     941            referrers = Utils.addInArrayCopy((OsmPrimitive[])referrers, referrer);
    946942        }
    947943    }
     
    949945    /**
    950946     * Remove referrer. No action is taken if referrer is not registered
    951      * @param referrer
     947     * @param referrer The referrer to remove
    952948     */
    953949    protected void removeReferrer(OsmPrimitive referrer) {
    954         // Based on methods from josm-ng
    955950        if (referrers instanceof OsmPrimitive) {
    956951            if (referrers == referrer) {
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r6639 r6717  
    8282        boolean locked = writeLock();
    8383        try {
    84             RelationMember[] newMembers = new RelationMember[members.length + 1];
    85             System.arraycopy(members, 0, newMembers, 0, members.length);
    86             newMembers[members.length] = member;
    87             members = newMembers;
     84            members = Utils.addInArrayCopy(members, member);
    8885            member.getMember().addReferrer(this);
    8986            member.getMember().clearCachedStyle();
     
    480477    }
    481478
    482     private void checkMembers() {
     479    private void checkMembers() throws DataIntegrityProblemException {
    483480        DataSet dataSet = getDataSet();
    484481        if (dataSet != null) {
     
    497494    }
    498495
    499     private void fireMembersChanged() {
     496    private void fireMembersChanged() throws DataIntegrityProblemException {
    500497        checkMembers();
    501498        if (getDataSet() != null) {
  • trunk/src/org/openstreetmap/josm/data/osm/Storage.java

    r6380 r6717  
    33
    44import java.util.AbstractSet;
     5import java.util.Arrays;
    56import java.util.Collection;
    67import java.util.ConcurrentModificationException;
     
    147148    private void copyArray() {
    148149        if (arrayCopyNecessary) {
    149             @SuppressWarnings("unchecked") T[] newData = (T[]) new Object[data.length];
    150             System.arraycopy(data, 0, newData, 0, data.length);
    151             data = newData;
     150            data = Arrays.copyOf(data, data.length);
    152151            arrayCopyNecessary = false;
    153152        }
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r6639 r6717  
    1717import org.openstreetmap.josm.tools.CopyList;
    1818import org.openstreetmap.josm.tools.Pair;
     19import org.openstreetmap.josm.tools.Utils;
    1920
    2021/**
     
    425426            clearCachedStyle();
    426427            n.addReferrer(this);
    427             Node[] newNodes = new Node[nodes.length + 1];
    428             System.arraycopy(nodes, 0, newNodes, 0, nodes.length);
    429             newNodes[nodes.length] = n;
    430             nodes = newNodes;
     428            nodes = Utils.addInArrayCopy(nodes, n);
    431429            n.clearCachedStyle();
    432430            fireNodesChanged();
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r6708 r6717  
    1717import java.text.DateFormat;
    1818import java.util.ArrayList;
     19import java.util.Arrays;
    1920import java.util.Collection;
    2021import java.util.Date;
     
    814815    final private void ensureTrackVisibilityLength() {
    815816        final int l = data.tracks.size();
    816         if(l == trackVisibility.length)
     817        if (l == trackVisibility.length)
    817818            return;
    818         final boolean[] back = trackVisibility.clone();
    819         final int m = Math.min(l, back.length);
    820         trackVisibility = new boolean[l];
    821         System.arraycopy(back, 0, trackVisibility, 0, m);
    822         for(int i=m; i < l; i++) {
     819        final int m = Math.min(l, trackVisibility.length);
     820        trackVisibility = Arrays.copyOf(trackVisibility, l);
     821        for (int i = m; i < l; i++) {
    823822            trackVisibility[i] = true;
    824823        }
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java

    r6228 r6717  
    1313import java.awt.event.MouseEvent;
    1414import java.awt.event.MouseListener;
     15import java.util.Arrays;
    1516import java.util.Map;
    1617
     
    221222        // cancel for unknown buttons and copy back original settings
    222223        if (v != 1 && v != 2) {
    223             System.arraycopy(trackVisibilityBackup, 0, layer.trackVisibility, 0, layer.trackVisibility.length);
     224            layer.trackVisibility = Arrays.copyOf(trackVisibilityBackup, layer.trackVisibility.length);
    224225            Main.map.repaint();
    225226            return;
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/PuwgProjectionChoice.java

    r6228 r6717  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.util.Arrays;
    67import java.util.Collection;
    78import java.util.Collections;
     
    4445    @Override
    4546    public String[] allCodes() {
    46         String[] zones = new String[CODES.length];
    47         System.arraycopy(CODES, 0, zones, 0, CODES.length);
    48         return zones;
     47        return Arrays.copyOf(CODES, CODES.length);
    4948    }
    5049
  • 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.