Permalink
Browse files

Changed all amount of items and prices to be long instead of sometime…

…s long and sometimes int
  • Loading branch information...
1 parent aa3a29e commit 759fce0af1be095fb780271d9dd94c9975afb0ae @jettro jettro committed Jan 12, 2012
Showing with 102 additions and 94 deletions.
  1. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/api/order/AbstractOrderCommand.java
  2. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/api/order/AbstractOrderPlacedEvent.java
  3. +1 −1 app/src/main/java/org/axonframework/samples/trader/app/api/order/BuyOrderPlacedEvent.java
  4. +1 −1 app/src/main/java/org/axonframework/samples/trader/app/api/order/CreateBuyOrderCommand.java
  5. +1 −1 app/src/main/java/org/axonframework/samples/trader/app/api/order/CreateSellOrderCommand.java
  6. +1 −1 app/src/main/java/org/axonframework/samples/trader/app/api/order/SellOrderPlacedEvent.java
  7. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/api/order/TradeExecutedEvent.java
  8. +3 −3 ...main/java/org/axonframework/samples/trader/app/api/portfolio/item/AddItemsToPortfolioCommand.java
  9. +3 −3 ...axonframework/samples/trader/app/api/portfolio/item/CancelItemReservationForPortfolioCommand.java
  10. +3 −3 ...xonframework/samples/trader/app/api/portfolio/item/ConfirmItemReservationForPortfolioCommand.java
  11. +3 −3 ...xonframework/samples/trader/app/api/portfolio/item/ItemReservationCancelledForPortfolioEvent.java
  12. +3 −3 ...xonframework/samples/trader/app/api/portfolio/item/ItemReservationConfirmedForPortfolioEvent.java
  13. +3 −3 ...main/java/org/axonframework/samples/trader/app/api/portfolio/item/ItemsAddedToPortfolioEvent.java
  14. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/api/portfolio/item/ItemsReservedEvent.java
  15. +5 −5 ...nframework/samples/trader/app/api/portfolio/item/NotEnoughItemsAvailableToReserveInPortfolio.java
  16. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/api/portfolio/item/ReserveItemsCommand.java
  17. +3 −3 ...in/java/org/axonframework/samples/trader/app/api/transaction/AbstractTransactionStartedEvent.java
  18. +1 −1 ...rc/main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionStartedEvent.java
  19. +1 −1 ...c/main/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionStartedEvent.java
  20. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/command/trading/Order.java
  21. +12 −4 app/src/main/java/org/axonframework/samples/trader/app/command/trading/OrderBook.java
  22. +17 −17 app/src/main/java/org/axonframework/samples/trader/app/command/trading/Portfolio.java
  23. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/command/trading/SellTradeManagerSaga.java
  24. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/query/orderbook/OrderEntry.java
  25. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/query/portfolio/ItemEntry.java
  26. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/query/portfolio/PortfolioEntry.java
  27. +1 −1 ...rc/main/java/org/axonframework/samples/trader/app/query/portfolio/PortfolioItemEventListener.java
  28. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/query/tradeexecuted/TradeExecutedEntry.java
  29. +5 −5 app/src/main/java/org/axonframework/samples/trader/app/query/transaction/TransactionEntry.java
  30. +2 −2 app/src/test/java/org/axonframework/samples/trader/app/query/portfolio/PortfolioEntryMatcher.java
@@ -26,10 +26,10 @@
private AggregateIdentifier portfolioId;
private AggregateIdentifier orderBookId;
private long tradeCount;
- private int itemPrice;
+ private long itemPrice;
private AggregateIdentifier orderId;
- protected AbstractOrderCommand(AggregateIdentifier portfolioId, AggregateIdentifier orderBookId, long tradeCount, int itemPrice) {
+ protected AbstractOrderCommand(AggregateIdentifier portfolioId, AggregateIdentifier orderBookId, long tradeCount, long itemPrice) {
this.portfolioId = portfolioId;
this.orderBookId = orderBookId;
this.tradeCount = tradeCount;
@@ -49,7 +49,7 @@ public long getTradeCount() {
return tradeCount;
}
- public int getItemPrice() {
+ public long getItemPrice() {
return itemPrice;
}
@@ -25,10 +25,10 @@
private final AggregateIdentifier orderId;
private final long tradeCount;
- private final int itemPrice;
+ private final long itemPrice;
private final AggregateIdentifier portfolioId;
- protected AbstractOrderPlacedEvent(AggregateIdentifier orderId, long tradeCount, int itemPrice, AggregateIdentifier portfolioId) {
+ protected AbstractOrderPlacedEvent(AggregateIdentifier orderId, long tradeCount, long itemPrice, AggregateIdentifier portfolioId) {
this.orderId = orderId;
this.tradeCount = tradeCount;
this.itemPrice = itemPrice;
@@ -47,7 +47,7 @@ public long getTradeCount() {
return tradeCount;
}
- public int getItemPrice() {
+ public long getItemPrice() {
return itemPrice;
}
@@ -22,7 +22,7 @@
*/
public class BuyOrderPlacedEvent extends AbstractOrderPlacedEvent {
- public BuyOrderPlacedEvent(AggregateIdentifier orderId, long tradeCount, int itemPrice, AggregateIdentifier portfolioId) {
+ public BuyOrderPlacedEvent(AggregateIdentifier orderId, long tradeCount, long itemPrice, AggregateIdentifier portfolioId) {
super(orderId, tradeCount, itemPrice, portfolioId);
}
@@ -22,7 +22,7 @@
*/
public class CreateBuyOrderCommand extends AbstractOrderCommand {
- public CreateBuyOrderCommand(AggregateIdentifier portfolioId, AggregateIdentifier orderBookId, long tradeCount, int itemPrice) {
+ public CreateBuyOrderCommand(AggregateIdentifier portfolioId, AggregateIdentifier orderBookId, long tradeCount, long itemPrice) {
super(portfolioId, orderBookId, tradeCount, itemPrice);
}
}
@@ -22,7 +22,7 @@
*/
public class CreateSellOrderCommand extends AbstractOrderCommand {
- public CreateSellOrderCommand(AggregateIdentifier portfolioId, AggregateIdentifier orderBookId, long tradeCount, int itemPrice) {
+ public CreateSellOrderCommand(AggregateIdentifier portfolioId, AggregateIdentifier orderBookId, long tradeCount, long itemPrice) {
super(portfolioId, orderBookId, tradeCount, itemPrice);
}
}
@@ -22,7 +22,7 @@
*/
public class SellOrderPlacedEvent extends AbstractOrderPlacedEvent {
- public SellOrderPlacedEvent(AggregateIdentifier orderId, long tradeCount, int itemPrice, AggregateIdentifier portfolioId) {
+ public SellOrderPlacedEvent(AggregateIdentifier orderId, long tradeCount, long itemPrice, AggregateIdentifier portfolioId) {
super(orderId, tradeCount, itemPrice, portfolioId);
}
}
@@ -24,11 +24,11 @@
public class TradeExecutedEvent extends DomainEvent {
private final long tradeCount;
- private final int tradePrice;
+ private final long tradePrice;
private final AggregateIdentifier buyOrderId;
private final AggregateIdentifier sellOrderId;
- public TradeExecutedEvent(long tradeCount, int tradePrice, AggregateIdentifier buyOrderId, AggregateIdentifier sellOrderId) {
+ public TradeExecutedEvent(long tradeCount, long tradePrice, AggregateIdentifier buyOrderId, AggregateIdentifier sellOrderId) {
this.tradeCount = tradeCount;
this.tradePrice = tradePrice;
this.buyOrderId = buyOrderId;
@@ -43,7 +43,7 @@ public long getTradeCount() {
return tradeCount;
}
- public int getTradePrice() {
+ public long getTradePrice() {
return tradePrice;
}
@@ -25,7 +25,7 @@
public class AddItemsToPortfolioCommand {
private AggregateIdentifier portfolioIdentifier;
private AggregateIdentifier orderBookIdentifier;
- private int amountOfItemsToAdd;
+ private long amountOfItemsToAdd;
/**
* Create a new command.
@@ -34,13 +34,13 @@
* @param orderBookIdentifier Identifier of the OrderBook to add items for
* @param amountOfItemsToAdd AMount of items to add
*/
- public AddItemsToPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier orderBookIdentifier, int amountOfItemsToAdd) {
+ public AddItemsToPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier orderBookIdentifier, long amountOfItemsToAdd) {
this.portfolioIdentifier = portfolioIdentifier;
this.orderBookIdentifier = orderBookIdentifier;
this.amountOfItemsToAdd = amountOfItemsToAdd;
}
- public int getAmountOfItemsToAdd() {
+ public long getAmountOfItemsToAdd() {
return amountOfItemsToAdd;
}
@@ -26,16 +26,16 @@
public class CancelItemReservationForPortfolioCommand {
private AggregateIdentifier portfolioIdentifier;
private AggregateIdentifier orderBookIdentifier;
- private int amountOfCancelledItems;
+ private long amountOfCancelledItems;
- public CancelItemReservationForPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier orderBookIdentifier, int amountOfCancelledItems) {
+ public CancelItemReservationForPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier orderBookIdentifier, long amountOfCancelledItems) {
this.portfolioIdentifier = portfolioIdentifier;
this.orderBookIdentifier = orderBookIdentifier;
this.amountOfCancelledItems = amountOfCancelledItems;
}
- public int getAmountOfItemsToCancel() {
+ public long getAmountOfItemsToCancel() {
return amountOfCancelledItems;
}
@@ -26,15 +26,15 @@
public class ConfirmItemReservationForPortfolioCommand {
private AggregateIdentifier portfolioIdentifier;
private AggregateIdentifier orderBookIdentifier;
- private int amountOfItemsToConfirm;
+ private long amountOfItemsToConfirm;
- public ConfirmItemReservationForPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier orderBookIdentifier, int amountOfItemsToConfirm) {
+ public ConfirmItemReservationForPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier orderBookIdentifier, long amountOfItemsToConfirm) {
this.portfolioIdentifier = portfolioIdentifier;
this.orderBookIdentifier = orderBookIdentifier;
this.amountOfItemsToConfirm = amountOfItemsToConfirm;
}
- public int getAmountOfItemsToConfirm() {
+ public long getAmountOfItemsToConfirm() {
return amountOfItemsToConfirm;
}
@@ -23,14 +23,14 @@
*/
public class ItemReservationCancelledForPortfolioEvent extends DomainEvent {
private AggregateIdentifier orderBookIdentifier;
- private int amountOfCancelledItems;
+ private long amountOfCancelledItems;
- public ItemReservationCancelledForPortfolioEvent(AggregateIdentifier orderBookIdentifier, int amountOfCancelledItems) {
+ public ItemReservationCancelledForPortfolioEvent(AggregateIdentifier orderBookIdentifier, long amountOfCancelledItems) {
this.orderBookIdentifier = orderBookIdentifier;
this.amountOfCancelledItems = amountOfCancelledItems;
}
- public int getAmountOfCancelledItems() {
+ public long getAmountOfCancelledItems() {
return amountOfCancelledItems;
}
@@ -23,14 +23,14 @@
*/
public class ItemReservationConfirmedForPortfolioEvent extends DomainEvent {
private AggregateIdentifier orderBookIdentifier;
- private int amountOfConfirmedItems;
+ private long amountOfConfirmedItems;
- public ItemReservationConfirmedForPortfolioEvent(AggregateIdentifier orderBookIdentifier, int amountOfConfirmedItems) {
+ public ItemReservationConfirmedForPortfolioEvent(AggregateIdentifier orderBookIdentifier, long amountOfConfirmedItems) {
this.orderBookIdentifier = orderBookIdentifier;
this.amountOfConfirmedItems = amountOfConfirmedItems;
}
- public int getAmountOfConfirmedItems() {
+ public long getAmountOfConfirmedItems() {
return amountOfConfirmedItems;
}
@@ -25,14 +25,14 @@
*/
public class ItemsAddedToPortfolioEvent extends DomainEvent {
private AggregateIdentifier orderBookIdentifier;
- private int amountOfItemsAdded;
+ private long amountOfItemsAdded;
- public ItemsAddedToPortfolioEvent(AggregateIdentifier orderBookIdentifier, int amountOfItemsAdded) {
+ public ItemsAddedToPortfolioEvent(AggregateIdentifier orderBookIdentifier, long amountOfItemsAdded) {
this.orderBookIdentifier = orderBookIdentifier;
this.amountOfItemsAdded = amountOfItemsAdded;
}
- public int getAmountOfItemsAdded() {
+ public long getAmountOfItemsAdded() {
return amountOfItemsAdded;
}
@@ -23,14 +23,14 @@
*/
public class ItemsReservedEvent extends DomainEvent {
private AggregateIdentifier orderBookIdentifier;
- private int amountOfItemsReserved;
+ private long amountOfItemsReserved;
- public ItemsReservedEvent(AggregateIdentifier orderBookIdentifier, int amountOfItemsReserved) {
+ public ItemsReservedEvent(AggregateIdentifier orderBookIdentifier, long amountOfItemsReserved) {
this.orderBookIdentifier = orderBookIdentifier;
this.amountOfItemsReserved = amountOfItemsReserved;
}
- public int getAmountOfItemsReserved() {
+ public long getAmountOfItemsReserved() {
return amountOfItemsReserved;
}
@@ -24,20 +24,20 @@
public class NotEnoughItemsAvailableToReserveInPortfolio extends DomainEvent {
private AggregateIdentifier orderBookIdentifier;
- private int availableAmountOfItems;
- private int amountOfItemsToReserve;
+ private long availableAmountOfItems;
+ private long amountOfItemsToReserve;
- public NotEnoughItemsAvailableToReserveInPortfolio(AggregateIdentifier orderBookIdentifier, int availableAmountOfItems, int amountOfItemsToReserve) {
+ public NotEnoughItemsAvailableToReserveInPortfolio(AggregateIdentifier orderBookIdentifier, long availableAmountOfItems, long amountOfItemsToReserve) {
this.orderBookIdentifier = orderBookIdentifier;
this.availableAmountOfItems = availableAmountOfItems;
this.amountOfItemsToReserve = amountOfItemsToReserve;
}
- public int getAmountOfItemsToReserve() {
+ public long getAmountOfItemsToReserve() {
return amountOfItemsToReserve;
}
- public int getAvailableAmountOfItems() {
+ public long getAvailableAmountOfItems() {
return availableAmountOfItems;
}
@@ -22,18 +22,18 @@
*/
public class ReserveItemsCommand {
private AggregateIdentifier portfolioIdentifier;
- private int amountOfItemsToReserve;
+ private long amountOfItemsToReserve;
private AggregateIdentifier orderBookIdentifier;
public ReserveItemsCommand(AggregateIdentifier portfolioIdentifier,
AggregateIdentifier orderBookIdentifier,
- int amountOfItemsToReserve) {
+ long amountOfItemsToReserve) {
this.portfolioIdentifier = portfolioIdentifier;
this.amountOfItemsToReserve = amountOfItemsToReserve;
this.orderBookIdentifier = orderBookIdentifier;
}
- public int getAmountOfItemsToReserve() {
+ public long getAmountOfItemsToReserve() {
return amountOfItemsToReserve;
}
@@ -24,12 +24,12 @@
public abstract class AbstractTransactionStartedEvent extends DomainEvent {
private AggregateIdentifier orderbookIdentifier;
private AggregateIdentifier portfolioIdentifier;
- private int totalItems;
+ private long totalItems;
private long pricePerItem;
public AbstractTransactionStartedEvent(AggregateIdentifier orderbookIdentifier,
AggregateIdentifier portfolioIdentifier,
- int totalItems,
+ long totalItems,
long pricePerItem) {
this.orderbookIdentifier = orderbookIdentifier;
this.portfolioIdentifier = portfolioIdentifier;
@@ -53,7 +53,7 @@ public long getPricePerItem() {
return pricePerItem;
}
- public int getTotalItems() {
+ public long getTotalItems() {
return totalItems;
}
@@ -26,6 +26,6 @@ public BuyTransactionStartedEvent(AggregateIdentifier orderbookIdentifier,
AggregateIdentifier portfolioIdentifier,
long totalItems,
long pricePerItem) {
- super(orderbookIdentifier, portfolioIdentifier, (int) totalItems, pricePerItem);
+ super(orderbookIdentifier, portfolioIdentifier, totalItems, pricePerItem);
}
}
@@ -22,6 +22,6 @@
*/
public class SellTransactionStartedEvent extends AbstractTransactionStartedEvent {
public SellTransactionStartedEvent(AggregateIdentifier orderbookIdentifier, AggregateIdentifier portfolioIdentifier, long totalItems, long pricePerItem) {
- super(orderbookIdentifier, portfolioIdentifier, (int) totalItems, pricePerItem);
+ super(orderbookIdentifier, portfolioIdentifier, totalItems, pricePerItem);
}
}
@@ -22,21 +22,21 @@
*/
class Order {
- private final int itemPrice;
+ private final long itemPrice;
private final long tradeCount;
private final AggregateIdentifier userId;
private long itemsRemaining;
private AggregateIdentifier orderId;
- public Order(AggregateIdentifier orderId, int itemPrice, long tradeCount, AggregateIdentifier userId) {
+ public Order(AggregateIdentifier orderId, long itemPrice, long tradeCount, AggregateIdentifier userId) {
this.orderId = orderId;
this.itemPrice = itemPrice;
this.tradeCount = tradeCount;
this.itemsRemaining = tradeCount;
this.userId = userId;
}
- public int getItemPrice() {
+ public long getItemPrice() {
return itemPrice;
}
@@ -46,12 +46,12 @@ public OrderBook(AggregateIdentifier identifier) {
}
- public void addBuyOrder(AggregateIdentifier orderId, long tradeCount, int itemPrice, AggregateIdentifier userId) {
+ public void addBuyOrder(AggregateIdentifier orderId, long tradeCount, long itemPrice, AggregateIdentifier userId) {
apply(new BuyOrderPlacedEvent(orderId, tradeCount, itemPrice, userId));
executeTrades();
}
- public void addSellOrder(AggregateIdentifier orderId, long tradeCount, int itemPrice, AggregateIdentifier userId) {
+ public void addSellOrder(AggregateIdentifier orderId, long tradeCount, long itemPrice, AggregateIdentifier userId) {
apply(new SellOrderPlacedEvent(orderId, tradeCount, itemPrice, userId));
executeTrades();
}
@@ -63,7 +63,7 @@ private void executeTrades() {
Order lowestSeller = sellOrders.first();
if (highestBuyer.getItemPrice() >= lowestSeller.getItemPrice()) {
long matchedTradeCount = Math.min(highestBuyer.getItemsRemaining(), lowestSeller.getItemsRemaining());
- int matchedTradePrice = ((highestBuyer.getItemPrice() + lowestSeller.getItemPrice()) / 2);
+ long matchedTradePrice = ((highestBuyer.getItemPrice() + lowestSeller.getItemPrice()) / 2);
apply(new TradeExecutedEvent(matchedTradeCount,
matchedTradePrice,
highestBuyer.getOrderId(),
@@ -106,7 +106,15 @@ protected void onOrderBookCreated(OrderBookCreatedEvent event) {
private static class OrderComparator implements Comparator<Order> {
public int compare(Order o1, Order o2) {
- return o1.getItemPrice() - o2.getItemPrice();
+ if (o1.getItemPrice() == o2.getItemPrice()) {
+ return 0;
+ }
+
+ if (o1.getItemPrice() > o2.getItemPrice()) {
+ return 1;
+ } else {
+ return -1;
+ }
}
}
}
Oops, something went wrong.

0 comments on commit 759fce0

Please sign in to comment.