From 9f8ea147f78616c6f4345317569abc54b571e51f Mon Sep 17 00:00:00 2001 From: rizer1980 <4340180@gmail.com> Date: Tue, 26 Nov 2024 09:31:41 +0300 Subject: [PATCH] format fix --- .../xchange/dto/marketdata/OrderBook.java | 80 ++++++++----------- .../dto/marketdata/ConcurrencyTest.java | 6 +- .../xchange/dto/marketdata/OrderBookTest.java | 37 ++++----- 3 files changed, 54 insertions(+), 69 deletions(-) diff --git a/xchange-core/src/main/java/org/knowm/xchange/dto/marketdata/OrderBook.java b/xchange-core/src/main/java/org/knowm/xchange/dto/marketdata/OrderBook.java index efdd2a8af98..2de7cfb5c91 100644 --- a/xchange-core/src/main/java/org/knowm/xchange/dto/marketdata/OrderBook.java +++ b/xchange-core/src/main/java/org/knowm/xchange/dto/marketdata/OrderBook.java @@ -19,40 +19,28 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * DTO representing the exchange order book - */ +/** DTO representing the exchange order book */ public final class OrderBook implements Serializable { private static final long serialVersionUID = -7788306758114464314L; - @JsonIgnore - public final StampedLock lock = new StampedLock(); + @JsonIgnore public final StampedLock lock = new StampedLock(); - /** - * the asks - */ - @Getter - private final List asks; + /** the asks */ + @Getter private final List asks; - /** - * the bids - */ - @Getter - private final List bids; + /** the bids */ + @Getter private final List bids; - /** - * the timestamp of the orderbook according to the exchange's server, null if not provided - */ - @Getter - private Date timeStamp; + /** the timestamp of the orderbook according to the exchange's server, null if not provided */ + @Getter private Date timeStamp; /** * Constructor * * @param timeStamp - the timestamp of the orderbook according to the exchange's server, null if - * not provided - * @param asks The ASK orders - * @param bids The BID orders + * not provided + * @param asks The ASK orders + * @param bids The BID orders */ @JsonCreator public OrderBook( @@ -67,10 +55,10 @@ public OrderBook( * Constructor * * @param timeStamp - the timestamp of the orderbook according to the exchange's server, null if - * not provided - * @param asks The ASK orders - * @param bids The BID orders - * @param sort True if the asks and bids need to be sorted + * not provided + * @param asks The ASK orders + * @param bids The BID orders + * @param sort True if the asks and bids need to be sorted */ public OrderBook(Date timeStamp, List asks, List bids, boolean sort) { @@ -90,9 +78,9 @@ public OrderBook(Date timeStamp, List asks, List bids, b * Constructor * * @param timeStamp - the timestamp of the orderbook according to the exchange's server, null if - * not provided - * @param asks The ASK orders - * @param bids The BID orders + * not provided + * @param asks The ASK orders + * @param bids The BID orders */ public OrderBook(Date timeStamp, Stream asks, Stream bids) { @@ -103,10 +91,10 @@ public OrderBook(Date timeStamp, Stream asks, Stream bid * Constructor * * @param timeStamp - the timestamp of the orderbook according to the exchange's server, null if - * not provided - * @param asks The ASK orders - * @param bids The BID orders - * @param sort True if the asks and bids need to be sorted + * not provided + * @param asks The ASK orders + * @param bids The BID orders + * @param sort True if the asks and bids need to be sorted */ public OrderBook(Date timeStamp, Stream asks, Stream bids, boolean sort) { @@ -224,31 +212,29 @@ public void update(OrderBookUpdate orderBookUpdate) { } } - private final Logger LOG = LoggerFactory.getLogger(OrderBook.class); - /** * @return true, if wee need to run binarySearch again */ private boolean recheckIdx(List limitOrders, LimitOrder limitOrder, int idx) { - switch (idx) { - case 0: { + switch (idx) { + case 0: + { if (!limitOrders.isEmpty()) { - //if not equals, need to recheck + // if not equals, need to recheck return limitOrders.get(0).compareTo(limitOrder) != 0; - } else - return true; + } else return true; } - case -1: { + case -1: + { if (limitOrders.isEmpty()) { return false; - } else - return limitOrders.get(0).compareTo(limitOrder) <= 0; + } else return limitOrders.get(0).compareTo(limitOrder) <= 0; } - default: - return true; - } + default: + return true; + } } // Replace timeStamp if the provided date is non-null and in the future diff --git a/xchange-core/src/test/java/org/knowm/xchange/dto/marketdata/ConcurrencyTest.java b/xchange-core/src/test/java/org/knowm/xchange/dto/marketdata/ConcurrencyTest.java index f8312e42b74..3473d2f3208 100644 --- a/xchange-core/src/test/java/org/knowm/xchange/dto/marketdata/ConcurrencyTest.java +++ b/xchange-core/src/test/java/org/knowm/xchange/dto/marketdata/ConcurrencyTest.java @@ -19,10 +19,8 @@ public class ConcurrencyTest { static Instrument inst = new CurrencyPair("BTC/USDT"); public static void main(String[] args) throws InterruptedException, ExecutionException { - OrderBook orderBook1 = - new OrderBook(new Date(), initOrderBookAsks(), new ArrayList<>(), true); - OrderBook orderBook2 = - new OrderBook(new Date(), initOrderBookAsks(), new ArrayList<>(), true); + OrderBook orderBook1 = new OrderBook(new Date(), initOrderBookAsks(), new ArrayList<>(), true); + OrderBook orderBook2 = new OrderBook(new Date(), initOrderBookAsks(), new ArrayList<>(), true); OrderBookOld orderBookOld = new OrderBookOld(new Date(), initOrderBookAsks(), new ArrayList<>(), true); ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(50); diff --git a/xchange-core/src/test/java/org/knowm/xchange/dto/marketdata/OrderBookTest.java b/xchange-core/src/test/java/org/knowm/xchange/dto/marketdata/OrderBookTest.java index bb0c7da2bd1..20906f72d48 100644 --- a/xchange-core/src/test/java/org/knowm/xchange/dto/marketdata/OrderBookTest.java +++ b/xchange-core/src/test/java/org/knowm/xchange/dto/marketdata/OrderBookTest.java @@ -9,7 +9,6 @@ import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Date; import java.util.List; import org.junit.Before; @@ -196,22 +195,24 @@ public void testRecheckIdx() LimitOrder higherBidOrder = new LimitOrder( OrderType.BID, BigDecimal.ONE, CurrencyPair.BTC_USD, "", null, new BigDecimal("10.5")); - //idx!= -1,0 - assertThat(method.invoke(orderBook, new ArrayList(),sameBidOrder, 1)).isEqualTo(true); - //idx=0, empty List - assertThat(method.invoke(orderBook, new ArrayList(),sameBidOrder, 0)).isEqualTo(true); - //idx=0, order equals - assertThat(method.invoke(orderBook, orderBook.getBids(),sameBidOrder, 0)).isEqualTo(false); - //idx=0, smallerBidOrder - assertThat(method.invoke(orderBook, orderBook.getBids(),smallerBidOrder, 0)).isEqualTo(true); - //idx=-1, empty List - assertThat(method.invoke(orderBook, new ArrayList(),sameBidOrder, -1)).isEqualTo(false); - //idx=-1, order equals - assertThat(method.invoke(orderBook, orderBook.getBids(),sameBidOrder, -1)).isEqualTo(true); - //idx=-1, smaller order - assertThat(method.invoke(orderBook, orderBook.getBids(),smallerBidOrder, -1)).isEqualTo(true); - //idx=-1, higher order - assertThat(method.invoke(orderBook, orderBook.getBids(),higherBidOrder, -1)).isEqualTo(false); + // idx!= -1,0 + assertThat(method.invoke(orderBook, new ArrayList(), sameBidOrder, 1)) + .isEqualTo(true); + // idx=0, empty List + assertThat(method.invoke(orderBook, new ArrayList(), sameBidOrder, 0)) + .isEqualTo(true); + // idx=0, order equals + assertThat(method.invoke(orderBook, orderBook.getBids(), sameBidOrder, 0)).isEqualTo(false); + // idx=0, smallerBidOrder + assertThat(method.invoke(orderBook, orderBook.getBids(), smallerBidOrder, 0)).isEqualTo(true); + // idx=-1, empty List + assertThat(method.invoke(orderBook, new ArrayList(), sameBidOrder, -1)) + .isEqualTo(false); + // idx=-1, order equals + assertThat(method.invoke(orderBook, orderBook.getBids(), sameBidOrder, -1)).isEqualTo(true); + // idx=-1, smaller order + assertThat(method.invoke(orderBook, orderBook.getBids(), smallerBidOrder, -1)).isEqualTo(true); + // idx=-1, higher order + assertThat(method.invoke(orderBook, orderBook.getBids(), higherBidOrder, -1)).isEqualTo(false); } - }