0
0
Fork 0

Implement a Sequence object in jlib

This commit is contained in:
Oliver Akins 2022-12-08 21:52:11 -06:00
parent f982baa481
commit 9f99de7c9e
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99

33
jlib/Sequence.java Normal file
View file

@ -0,0 +1,33 @@
package jlib;
import java.util.HashSet;
import java.util.LinkedList;
public class Sequence<T> {
private LinkedList<T> previous;
private Integer max;
public Sequence(Integer size) {
this.max = size;
this.previous = new LinkedList<T>();
}
public void add(T e) {
if (this.previous.size() == this.max) {
this.previous.pop();
}
this.previous.add(e);
}
public Integer size() {
return this.previous.size();
}
public Boolean isUnique() {
HashSet<T> s = new HashSet<>();
for (T e : this.previous) {
s.add(e);
}
return s.size() == this.max;
}
}