mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Remove lombok Delegate from PersistableList
Add final Add setAll method Remove Iterable interface
This commit is contained in:
parent
9190f17966
commit
074ed6753b
@ -18,42 +18,69 @@
|
|||||||
package bisq.common.proto.persistable;
|
package bisq.common.proto.persistable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.experimental.Delegate;
|
|
||||||
|
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
public abstract class PersistableList<T extends PersistablePayload> implements PersistableEnvelope, Iterable<T> {
|
public abstract class PersistableList<T extends PersistablePayload> implements PersistableEnvelope {
|
||||||
@Delegate(excludes = ExcludesDelegateMethods.class)
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
private final List<T> list = createList();
|
||||||
private List<T> list;
|
|
||||||
|
protected List<T> createList() {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
public PersistableList() {
|
public PersistableList() {
|
||||||
list = new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PersistableList(List<T> list) {
|
public PersistableList(List<T> list) {
|
||||||
this.list = list;
|
setAll(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAll(Collection<T> collection) {
|
||||||
|
this.list.clear();
|
||||||
|
this.list.addAll(collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean add(T item) {
|
||||||
|
if (!list.contains(item)) {
|
||||||
|
list.add(item);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean remove(T tradable) {
|
||||||
|
return list.remove(tradable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.stream() does not compile for unknown reasons, so add that manual delegate method
|
|
||||||
public Stream<T> stream() {
|
public Stream<T> stream() {
|
||||||
return list.stream();
|
return list.stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface ExcludesDelegateMethods<T> {
|
public int size() {
|
||||||
Stream<T> stream();
|
return list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public boolean contains(T thing) {
|
||||||
public String toString() {
|
return list.contains(thing);
|
||||||
return "PersistableList{" +
|
}
|
||||||
"\n list=" + list +
|
|
||||||
"\n}";
|
public boolean isEmpty() {
|
||||||
|
return list.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEach(Consumer<? super T> action) {
|
||||||
|
list.forEach(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
list.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user