Introductie type ArrayCycle en consequent maken van add en remove methodes: nu zonder type in de naam.
This commit is contained in:
31
java/src/pm/util/ArrayCycle.java
Normal file
31
java/src/pm/util/ArrayCycle.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package pm.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ArrayCycle<T> extends ArrayList<T> {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
protected int index = 0;
|
||||
|
||||
public T current() {
|
||||
return this.get(index);
|
||||
}
|
||||
|
||||
public T previous() {
|
||||
if (--index < 0) {
|
||||
index = Math.max(0, size() - 1);
|
||||
}
|
||||
return get(index);
|
||||
}
|
||||
|
||||
public T next() {
|
||||
if (++index >= size()) {
|
||||
index = 0;
|
||||
}
|
||||
return get(index);
|
||||
}
|
||||
|
||||
public T reset() {
|
||||
return get(index = 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user