mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-03 10:46:54 +01:00
Add PersistableListAsObservable
Remove ObservableList methods from PersistableList Let DisputeList and TradableList extend PersistableListAsObservable Fix param names
This commit is contained in:
parent
f7c2464fbc
commit
f9f33aa16d
4 changed files with 58 additions and 36 deletions
|
@ -17,19 +17,14 @@
|
|||
|
||||
package bisq.common.proto.persistable;
|
||||
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public abstract class PersistableList<T extends PersistablePayload> implements PersistableEnvelope {
|
||||
|
||||
@Getter
|
||||
|
@ -46,18 +41,6 @@ public abstract class PersistableList<T extends PersistablePayload> implements P
|
|||
setAll(list);
|
||||
}
|
||||
|
||||
public void addListener(ListChangeListener<T> listener) {
|
||||
((ObservableList<T>) getList()).addListener(listener);
|
||||
}
|
||||
|
||||
public void removeListener(ListChangeListener<T> listener) {
|
||||
((ObservableList<T>) getList()).removeListener(listener);
|
||||
}
|
||||
|
||||
public ObservableList<T> getObservableList() {
|
||||
return (ObservableList<T>) getList();
|
||||
}
|
||||
|
||||
public void setAll(Collection<T> collection) {
|
||||
this.list.clear();
|
||||
this.list.addAll(collection);
|
||||
|
@ -71,8 +54,8 @@ public abstract class PersistableList<T extends PersistablePayload> implements P
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean remove(T tradable) {
|
||||
return list.remove(tradable);
|
||||
public boolean remove(T item) {
|
||||
return list.remove(item);
|
||||
}
|
||||
|
||||
public Stream<T> stream() {
|
||||
|
@ -83,8 +66,8 @@ public abstract class PersistableList<T extends PersistablePayload> implements P
|
|||
return list.size();
|
||||
}
|
||||
|
||||
public boolean contains(T thing) {
|
||||
return list.contains(thing);
|
||||
public boolean contains(T item) {
|
||||
return list.contains(item);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.common.proto.persistable;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class PersistableListAsObservable<T extends PersistablePayload> extends PersistableList<T> {
|
||||
|
||||
public PersistableListAsObservable() {
|
||||
}
|
||||
|
||||
protected PersistableListAsObservable(List<T> list) {
|
||||
super(list);
|
||||
}
|
||||
|
||||
protected List<T> createList() {
|
||||
return FXCollections.observableArrayList();
|
||||
}
|
||||
|
||||
public ObservableList<T> getObservableList() {
|
||||
return (ObservableList<T>) getList();
|
||||
}
|
||||
|
||||
public void addListener(ListChangeListener<T> listener) {
|
||||
((ObservableList<T>) getList()).addListener(listener);
|
||||
}
|
||||
|
||||
public void removeListener(ListChangeListener<T> listener) {
|
||||
((ObservableList<T>) getList()).removeListener(listener);
|
||||
}
|
||||
}
|
|
@ -17,11 +17,9 @@
|
|||
|
||||
package bisq.core.support.dispute;
|
||||
|
||||
import bisq.common.proto.persistable.PersistableList;
|
||||
import bisq.common.proto.persistable.PersistableListAsObservable;
|
||||
import bisq.common.proto.persistable.PersistablePayload;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.ToString;
|
||||
|
@ -35,10 +33,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
* Calls to the List are delegated because this class intercepts the add/remove calls so changes
|
||||
* can be saved to disc.
|
||||
*/
|
||||
public abstract class DisputeList<T extends PersistablePayload> extends PersistableList<T> {
|
||||
protected List<T> createList() {
|
||||
return FXCollections.observableArrayList();
|
||||
}
|
||||
public abstract class DisputeList<T extends PersistablePayload> extends PersistableListAsObservable<T> {
|
||||
|
||||
public DisputeList() {
|
||||
}
|
||||
|
|
|
@ -23,19 +23,17 @@ import bisq.core.proto.CoreProtoResolver;
|
|||
|
||||
import bisq.common.proto.ProtoUtil;
|
||||
import bisq.common.proto.ProtobufferRuntimeException;
|
||||
import bisq.common.proto.persistable.PersistableList;
|
||||
import bisq.common.proto.persistable.PersistableListAsObservable;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public final class TradableList<T extends Tradable> extends PersistableList<T> {
|
||||
public final class TradableList<T extends Tradable> extends PersistableListAsObservable<T> {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
|
@ -44,10 +42,6 @@ public final class TradableList<T extends Tradable> extends PersistableList<T> {
|
|||
public TradableList() {
|
||||
}
|
||||
|
||||
protected List<T> createList() {
|
||||
return FXCollections.observableArrayList();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
|
|
Loading…
Add table
Reference in a new issue