Changeset 12536 in josm


Ignore:
Timestamp:
2017-07-30T00:17:17+02:00 (3 weeks ago)
Author:
Don-vip
Message:

see #14833 - new API to manipulate primitives id counter

File:
1 edited

Legend:

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

    r12190 r12536  
    4747    }
    4848
    49     private static final AtomicLong idCounter = new AtomicLong(0);
    50 
     49    private static final AtomicLong ID_COUNTER = new AtomicLong(0);
     50
     51    /**
     52     * Generates a new primitive unique id.
     53     * @return new primitive unique (negative) id
     54     */
    5155    static long generateUniqueId() {
    52         return idCounter.decrementAndGet();
     56        return ID_COUNTER.decrementAndGet();
     57    }
     58
     59    /**
     60     * Returns the current primitive unique id.
     61     * @return the current primitive unique (negative) id (last generated)
     62     * @since 12536
     63     */
     64    public static long currentUniqueId() {
     65        return ID_COUNTER.get();
     66    }
     67
     68    /**
     69     * Advances the current primitive unique id to skip a range of values.
     70     * @param newId new unique id
     71     * @throws IllegalArgumentException if newId is greater than current unique id
     72     * @since 12536
     73     */
     74    public static void advanceUniqueId(long newId) {
     75        if (newId > currentUniqueId()) {
     76            throw new IllegalArgumentException("Cannot modify the id counter backwards");
     77        }
     78        ID_COUNTER.set(newId);
    5379    }
    5480
Note: See TracChangeset for help on using the changeset viewer.