Skip to content

Commit

Permalink
Removed and replaced classic setters and getters with lombok annotati…
Browse files Browse the repository at this point in the history
…ons.

Added the builder patter for the Order class.
Config file to prevent code coverage tools to complain about lombok generated code.
  • Loading branch information
tiago18c committed Jun 10, 2021
1 parent 74ed160 commit fc1389f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 224 deletions.
1 change: 1 addition & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.addLombokGeneratedAnnotation = true
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@
<artifactId>Java-WebSocket</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
114 changes: 4 additions & 110 deletions src/main/java/org/p2p/solanaj/serum/Order.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.p2p.solanaj.serum;

import lombok.*;
import org.p2p.solanaj.core.PublicKey;

import java.security.SecureRandom;

/**
* Class that represents a Serum order.
*/
@Builder
@Getter
@Setter(AccessLevel.PACKAGE)
public class Order {

private long price;
Expand All @@ -23,116 +27,6 @@ public class Order {
private SelfTradeBehaviorLayout selfTradeBehaviorLayout;
private boolean buy;

public Order(float floatPrice, float floatQuantity) {
this.floatPrice = floatPrice;
this.floatQuantity = floatQuantity;
this.clientOrderId = new SecureRandom().nextLong();
}

// constructor used by new orders
public Order(float floatPrice, float floatQuantity, long clientOrderId) {
this.floatPrice = floatPrice;
this.floatQuantity = floatQuantity;
this.clientOrderId = clientOrderId;
}

public Order(long price, long quantity, long clientOrderId, float floatPrice, float floatQuantity, PublicKey owner) {
this.price = price;
this.quantity = quantity;
this.clientOrderId = clientOrderId;
this.floatPrice = floatPrice;
this.floatQuantity = floatQuantity;
this.owner = owner;
}

public long getPrice() {
return price;
}

public void setPrice(long price) {
this.price = price;
}

public long getQuantity() {
return quantity;
}

public void setQuantity(long quantity) {
this.quantity = quantity;
}

public long getClientOrderId() {
return clientOrderId;
}

public void setClientOrderId(long clientOrderId) {
this.clientOrderId = clientOrderId;
}

public float getFloatPrice() {
return floatPrice;
}

public void setFloatPrice(float floatPrice) {
this.floatPrice = floatPrice;
}

public float getFloatQuantity() {
return floatQuantity;
}

public void setFloatQuantity(float floatQuantity) {
this.floatQuantity = floatQuantity;
}

public PublicKey getOwner() {
return owner;
}

public void setOwner(PublicKey owner) {
this.owner = owner;
}

public long getMaxQuoteQuantity() {
return maxQuoteQuantity;
}

public void setMaxQuoteQuantity(long maxQuoteQuantity) {
this.maxQuoteQuantity = maxQuoteQuantity;
}

public long getClientId() {
return clientId;
}

public void setClientId(long clientId) {
this.clientId = clientId;
}

public OrderTypeLayout getOrderTypeLayout() {
return orderTypeLayout;
}

public void setOrderTypeLayout(OrderTypeLayout orderTypeLayout) {
this.orderTypeLayout = orderTypeLayout;
}

public SelfTradeBehaviorLayout getSelfTradeBehaviorLayout() {
return selfTradeBehaviorLayout;
}

public void setSelfTradeBehaviorLayout(SelfTradeBehaviorLayout selfTradeBehaviorLayout) {
this.selfTradeBehaviorLayout = selfTradeBehaviorLayout;
}

public boolean isBuy() {
return buy;
}

public void setBuy(boolean buy) {
this.buy = buy;
}

@Override
public String toString() {
return "Order{" +
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/org/p2p/solanaj/serum/OrderBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ public ArrayList<Order> getOrders() {
slab.getSlabNodes().forEach(slabNode -> {
if (slabNode instanceof SlabLeafNode) {
SlabLeafNode slabLeafNode = (SlabLeafNode) slabNode;
orders.add(
new Order(
slabLeafNode.getPrice(),
slabLeafNode.getQuantity(),
slabLeafNode.getClientOrderId(),
SerumUtils.priceLotsToNumber(slabLeafNode.getPrice(), baseDecimals, quoteDecimals, baseLotSize, quoteLotSize),
(float) ((slabLeafNode.getQuantity() * baseLotSize) / SerumUtils.getBaseSplTokenMultiplier(baseDecimals)),
slabLeafNode.getOwner()
)
orders.add(Order.builder()
.price(slabLeafNode.getPrice())
.quantity(slabLeafNode.getQuantity())
.clientOrderId(slabLeafNode.getClientOrderId())
.floatPrice(SerumUtils.priceLotsToNumber(slabLeafNode.getPrice(), baseDecimals, quoteDecimals, baseLotSize, quoteLotSize))
.floatQuantity((float) ((slabLeafNode.getQuantity() * baseLotSize) / SerumUtils.getBaseSplTokenMultiplier(baseDecimals)))
.owner(slabLeafNode.getOwner())
.build()
);
}
});
Expand Down
Loading

0 comments on commit fc1389f

Please sign in to comment.