Ignore:
Timestamp:
2016-12-14T04:45:14+01:00 (7 years ago)
Author:
Don-vip
Message:

refactor duplicated code

File:
1 edited

Legend:

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

    r11392 r11395  
    504504    }
    505505
    506     private final class SafeReadonlyIter implements Iterator<T> {
    507         private final T[] data;
    508         private int slot;
    509 
    510         SafeReadonlyIter(T[] data) {
    511             this.data = data;
    512         }
     506    private abstract class AbstractIter implements Iterator<T> {
     507        protected int slot;
    513508
    514509        @Override
     
    519514        }
    520515
     516        protected void align() {
     517            while (slot < data.length && data[slot] == null) {
     518                slot++;
     519            }
     520        }
     521    }
     522
     523    private final class SafeReadonlyIter extends AbstractIter {
     524        private final T[] data;
     525
     526        SafeReadonlyIter(T[] data) {
     527            this.data = data;
     528        }
     529
    521530        @Override
    522531        public T next() {
     
    529538            throw new UnsupportedOperationException();
    530539        }
    531 
    532         private void align() {
    533             while (slot < data.length && data[slot] == null) {
    534                 slot++;
    535             }
    536         }
    537     }
    538 
    539     private final class Iter implements Iterator<T> {
     540    }
     541
     542    private final class Iter extends AbstractIter {
    540543        private final int mods;
    541         private int slot;
    542544        private int removeSlot = -1;
    543545
    544546        Iter() {
    545547            mods = modCount;
    546         }
    547 
    548         @Override
    549         public boolean hasNext() {
    550             if (data == null) return false;
    551             align();
    552             return slot < data.length;
    553548        }
    554549
     
    569564        }
    570565
    571         private void align() {
     566        @Override
     567        protected void align() {
    572568            if (mods != modCount)
    573569                throw new ConcurrentModificationException();
    574             while (slot < data.length && data[slot] == null) {
    575                 slot++;
    576             }
    577         }
    578     }
    579 
     570            super.align();
     571        }
     572    }
    580573}
Note: See TracChangeset for help on using the changeset viewer.