Last change
on this file since 16260 was 16108, checked in by Don-vip, 4 years ago |
fix #18909 - UniqueIdGenerator.generateUniqueId() should be public (patch by taylor.smock)
|
-
Property svn:eol-style
set to
native
|
File size:
1.2 KB
|
Line | |
---|
1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.concurrent.atomic.AtomicLong;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Generator of unique identifiers.
|
---|
8 | * @since 15820
|
---|
9 | */
|
---|
10 | public final class UniqueIdGenerator {
|
---|
11 |
|
---|
12 | private final AtomicLong idCounter = new AtomicLong(0);
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Generates a new primitive unique id.
|
---|
16 | * @return new primitive unique (negative) id
|
---|
17 | * @since 16108 (made public)
|
---|
18 | */
|
---|
19 | public long generateUniqueId() {
|
---|
20 | return idCounter.decrementAndGet();
|
---|
21 | }
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Returns the current primitive unique id.
|
---|
25 | * @return the current primitive unique (negative) id (last generated)
|
---|
26 | */
|
---|
27 | public long currentUniqueId() {
|
---|
28 | return idCounter.get();
|
---|
29 | }
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Advances the current primitive unique id to skip a range of values.
|
---|
33 | * @param newId new unique id
|
---|
34 | * @throws IllegalArgumentException if newId is greater than current unique id
|
---|
35 | */
|
---|
36 | public void advanceUniqueId(long newId) {
|
---|
37 | if (newId > currentUniqueId()) {
|
---|
38 | throw new IllegalArgumentException("Cannot modify the id counter backwards");
|
---|
39 | }
|
---|
40 | idCounter.set(newId);
|
---|
41 | }
|
---|
42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.