Some reformatting.

This commit is contained in:
7u83 2016-12-25 21:31:55 +01:00
parent c0676d5b03
commit bdc4f794f5
4 changed files with 60 additions and 53 deletions

View File

@ -2,12 +2,10 @@ package StockExchange;
public class BuyOrder extends Order implements Comparable<Order> { public class BuyOrder extends Order implements Comparable<Order> {
@Override
public int compareTo(Order o) { public int compareTo(Order o) {
if (o.limit < limit) if (o.limit < limit) {
{
//System.out.println("return 1"); //System.out.println("return 1");
return -1; return -1;
} }

View File

@ -28,7 +28,7 @@ public class Exchange extends Thread {
} }
// Here we store the list of quote receivers // Here we store the list of quote receivers
TreeSet<QuoteReceiver> qrlist = new TreeSet<QuoteReceiver>(); TreeSet<QuoteReceiver> qrlist = new TreeSet();
public void AddQuoteReceiver(QuoteReceiver qr) { public void AddQuoteReceiver(QuoteReceiver qr) {
qrlist.add(qr); qrlist.add(qr);
@ -52,7 +52,7 @@ public class Exchange extends Thread {
long lastsize; long lastsize;
// Order orderlist[]; // Order orderlist[];
TreeSet<BuyOrder> bid = new TreeSet<BuyOrder>(); TreeSet<BuyOrder> bid = new TreeSet();
TreeSet<SellOrder> ask = new TreeSet<SellOrder>(); TreeSet<SellOrder> ask = new TreeSet<SellOrder>();
private final Semaphore available = new Semaphore(1, true); private final Semaphore available = new Semaphore(1, true);

View File

@ -1,7 +1,10 @@
package StockExchange; package StockExchange;
public abstract class Order implements Comparable<Order> { public abstract class Order implements Comparable<Order> {
/**
* when
*/
public long timestamp = 0; public long timestamp = 0;
public long size; public long size;
public double limit; public double limit;
@ -11,7 +14,6 @@ public abstract class Order implements Comparable<Order>{
public long id = 0; public long id = 0;
public Account account = null; public Account account = null;
enum OrderStatus { enum OrderStatus {
open, executed, canceled open, executed, canceled
} }
@ -19,8 +21,9 @@ public abstract class Order implements Comparable<Order>{
OrderStatus status = OrderStatus.open; OrderStatus status = OrderStatus.open;
public long getAge() { public long getAge() {
if (timestamp==0) if (timestamp == 0) {
return 0; return 0;
}
return System.currentTimeMillis() - timestamp; return System.currentTimeMillis() - timestamp;
} }

View File

@ -5,6 +5,8 @@
*/ */
package sesim; package sesim;
import StockExchange.*;
/** /**
* *
* @author tube * @author tube
@ -15,6 +17,10 @@ public class SeSim {
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Exchange se = new StockExchange.Exchange();
se.start();
// TODO code application logic here // TODO code application logic here
} }