mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-22 14:42:37 +01:00
Add default methods for volume, price, amount
This commit is contained in:
parent
d9d054f2bd
commit
300e19d095
1 changed files with 29 additions and 0 deletions
|
@ -17,11 +17,16 @@
|
|||
|
||||
package bisq.core.trade.model;
|
||||
|
||||
import bisq.core.monetary.Price;
|
||||
import bisq.core.monetary.Volume;
|
||||
import bisq.core.offer.Offer;
|
||||
|
||||
import bisq.common.proto.persistable.PersistablePayload;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface Tradable extends PersistablePayload {
|
||||
Offer getOffer();
|
||||
|
@ -31,4 +36,28 @@ public interface Tradable extends PersistablePayload {
|
|||
String getId();
|
||||
|
||||
String getShortId();
|
||||
|
||||
default Optional<TradeModel> asTradeModel() {
|
||||
if (this instanceof TradeModel) {
|
||||
return Optional.of(((TradeModel) this));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
default Optional<Volume> getOptionalVolume() {
|
||||
return asTradeModel().map(TradeModel::getVolume).or(() -> Optional.ofNullable(getOffer().getVolume()));
|
||||
}
|
||||
|
||||
default Optional<Price> getOptionalPrice() {
|
||||
return asTradeModel().map(TradeModel::getPrice).or(() -> Optional.ofNullable(getOffer().getPrice()));
|
||||
}
|
||||
|
||||
default Optional<Coin> getOptionalAmount() {
|
||||
return asTradeModel().map(TradeModel::getAmount);
|
||||
}
|
||||
|
||||
default Optional<Long> getOptionalAmountAsLong() {
|
||||
return asTradeModel().map(TradeModel::getAmountAsLong);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue