1 package org.matsim.api.core.v01;
8 public class IdSet<T>
implements Set<Id<T>> {
14 public IdSet(Class<T> idClass) {
18 public IdSet(Class<T> idClass,
int size) {
20 this.data =
new BitSet(size);
30 return this.size == 0;
35 if (key instanceof
Id) {
42 return this.data.get(
id.index());
46 return this.data.get(index);
51 return new IdSetIterator<>(
this);
60 index = this.data.nextSetBit(index);
64 array[count] =
Id.
get(index, this.idClass);
68 return (
Id<T>[]) array;
76 }
else if (array.length <
this.size) {
77 array = Arrays.copyOf(a, this.size);
78 }
else if (array.length >
this.size) {
79 Arrays.fill(a, this.size, a.length, null);
85 index = this.data.nextSetBit(index);
89 array[count] =
Id.
get(index, this.idClass);
97 public boolean remove(Object key) {
98 if (key instanceof
Id) {
99 return remove((
Id<T>) key);
105 return this.
remove(key.index());
108 private boolean remove(
int idx) {
109 if (this.data.get(idx)) {
110 this.data.clear(idx);
120 if (o instanceof
Id) {
121 if (!this.data.get(((Id) o).index())) {
133 boolean changed =
false;
135 int index = k.index();
136 if (!this.data.get(index)) {
137 this.data.set(index);
146 boolean changed =
false;
149 index = m.
data.nextSetBit(index);
151 if (!this.data.get(index)) {
152 this.data.set(index);
166 boolean changed =
false;
169 index = this.data.nextSetBit(index);
172 if (!c.contains(
id)) {
173 this.data.clear(index);
187 boolean changed =
false;
189 if (o instanceof
Id) {
190 int index = ((Id) o).index();
191 if (this.data.get(index)) {
192 this.data.clear(index);
206 private boolean add(
int index) {
207 boolean hadValue = this.data.get(index);
208 this.data.set(index);
225 if (!(o instanceof Set))
227 if (o instanceof
IdSet) {
231 Collection<?> c = (Collection<?>) o;
232 if (c.size() !=
size())
236 }
catch (ClassCastException | NullPointerException unused) {
247 for (
int i = 0; i < this.data.length(); i++) {
248 h += this.data.get(i) ? i : 0;
264 return this.
set.data.nextSetBit(this.currentIndex + 1) >= 0;
269 int index = this.
set.data.nextSetBit(this.currentIndex + 1);
271 this.currentIndex = index;
272 return Id.
get(index, this.
set.idClass);
274 throw new NoSuchElementException();
278 public void remove() {
279 this.
set.data.clear(this.currentIndex);
static< T > Id< T > get(int index, final Class< T > type)
static< T > int getNumberOfIds(final Class< T > type)
Iterator< Id< T > > iterator()
boolean contains(Object key)
boolean addAll(IdSet< T > m)
boolean contains(Id< T > id)
boolean containsAll(Collection<?> c)
boolean removeAll(Collection<?> c)
IdSet(Class< T > idClass)
IdSet(Class< T > idClass, int size)
boolean addAll(Collection<? extends Id< T >> c)
boolean add(Id< T > value)
boolean retainAll(Collection<?> c)
boolean contains(int index)