edu.cuny.cat.core
Class Shout

java.lang.Object
  extended by edu.cuny.cat.core.Shout
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Shout>
Direct Known Subclasses:
Shout.MutableShout

public class Shout
extends java.lang.Object
implements java.lang.Comparable<Shout>, java.lang.Cloneable, java.io.Serializable

A class representing a shout in an auction. A shout may be either a bid (offer to buy) or an ask (offer to sell).

Shouts are mutable within this package for performance reasons, hence care should be taken not to rely on, e.g. shouts held in collections remaining constant.

Version:
$Revision: 1.23 $
Author:
Steve Phelps
See Also:
Serialized Form

Nested Class Summary
static class Shout.MutableShout
          A Shout that is publically mutable.
 
Field Summary
protected  Shout child
          The child of this shout.
static int CREATED
           
protected  java.lang.String id
          The agent placing this offer
protected  boolean isBid
          True if this shout is a bid.
static int MATCHED
           
protected  Shout parent
          the parent of this shout.
static int PENDING
          different meaning at different locations: (TRADER): placing shout being attempted; (SERVER): an attempted shout placing or modification is under way (SPECIALIST): a transaction involving this shout is proposed to server
static int PLACED
           
protected  double price
          The price of this offer
protected  int quantity
          The number of items offered/wanted.
static int REJECTED
           
protected  Specialist specialist
           
protected  int state
           
static boolean TRACE
          a switch for debug purposes.
protected  Trader trader
           
 
Constructor Summary
Shout()
           
Shout(int quantity, double price, boolean isBid)
           
Shout(Shout existing)
           
Shout(java.lang.String shoutId, double price, boolean isBid)
           
Shout(java.lang.String shoutId, int quantity, double price, boolean isBid)
           
Shout(java.lang.String shoutId, int quantity, double price, boolean isBid, Trader trader, Specialist specialist)
           
 
Method Summary
 java.lang.Object clone()
           
 int compareTo(Shout other)
           
 void copyFrom(Shout other)
           
 boolean equals(Shout shout)
          TODO: currently only shout ID is compared, however this cannot rule out the parent shout and child shout.
 Shout getChild()
          Get the child of this shout.
 java.lang.String getId()
           
 Shout getParent()
          Get the parent of this shout.
 double getPrice()
           
 int getQuantity()
           
 Specialist getSpecialist()
           
 int getState()
           
 java.lang.String getStateDescription()
           
 Trader getTrader()
           
 boolean isAsk()
           
 boolean isBid()
           
 boolean isMatched()
           
 boolean isValid()
           
static double maxPrice(Shout s, double price)
           
static double maxPrice(Shout s1, Shout s2)
           
static double minPrice(Shout s, double price)
           
static double minPrice(Shout s1, Shout s2)
           
 boolean satisfies(Shout other)
           
 void setChild(Shout child)
           
 void setId(java.lang.String id)
           
 void setIsBid(boolean isBid)
           
 void setParent(Shout parent)
           
 void setPrice(double price)
           
 void setQuantity(int quantity)
           
 void setSpecialist(Specialist specialist)
           
 void setState(int state)
           
 void setTrader(Trader trader)
           
 Shout splat(int excess)
           
 Shout split(int excess)
          Reduce the quantity of this shout by excess and return a new child shout containing the excess quantity.
 java.lang.String toPrettyString()
           
 java.lang.String toString()
           
static int totalVolume(java.util.Iterator<Shout> itor)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRACE

public static final boolean TRACE
a switch for debug purposes. If true, output trace of shouts

See Also:
Constant Field Values

quantity

protected int quantity
The number of items offered/wanted.


price

protected double price
The price of this offer


id

protected java.lang.String id
The agent placing this offer


trader

protected Trader trader

specialist

protected Specialist specialist

isBid

protected boolean isBid
True if this shout is a bid. False if this shout is an ask.


CREATED

public static final int CREATED
See Also:
Constant Field Values

PLACED

public static final int PLACED
See Also:
Constant Field Values

REJECTED

public static final int REJECTED
See Also:
Constant Field Values

MATCHED

public static final int MATCHED
See Also:
Constant Field Values

PENDING

public static final int PENDING
different meaning at different locations: (TRADER): placing shout being attempted; (SERVER): an attempted shout placing or modification is under way (SPECIALIST): a transaction involving this shout is proposed to server

See Also:
Constant Field Values

state

protected int state

child

protected Shout child
The child of this shout. In various scenarios, it is used to store the shout attempting to modify this shout.


parent

protected Shout parent
the parent of this shout. In various scenarios, it is used to store the shout that this shout is attempting to modify.

Constructor Detail

Shout

public Shout()

Shout

public Shout(java.lang.String shoutId,
             double price,
             boolean isBid)

Shout

public Shout(int quantity,
             double price,
             boolean isBid)

Shout

public Shout(Shout existing)

Shout

public Shout(java.lang.String shoutId,
             int quantity,
             double price,
             boolean isBid,
             Trader trader,
             Specialist specialist)

Shout

public Shout(java.lang.String shoutId,
             int quantity,
             double price,
             boolean isBid)
Method Detail

getQuantity

public int getQuantity()

getPrice

public double getPrice()

getId

public java.lang.String getId()

getTrader

public Trader getTrader()

getSpecialist

public Specialist getSpecialist()

isBid

public boolean isBid()

isAsk

public boolean isAsk()

getState

public int getState()

setState

public void setState(int state)

isMatched

public boolean isMatched()

satisfies

public boolean satisfies(Shout other)

compareTo

public int compareTo(Shout other)
Specified by:
compareTo in interface java.lang.Comparable<Shout>

equals

public boolean equals(Shout shout)
TODO: currently only shout ID is compared, however this cannot rule out the parent shout and child shout.

Parameters:
shout - the shout to be compared with this shout
Returns:
true if equal; false otherwise

isValid

public boolean isValid()

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toPrettyString

public java.lang.String toPrettyString()

totalVolume

public static int totalVolume(java.util.Iterator<Shout> itor)
Parameters:
itor -
Returns:
the cumulative volume of goods in the given shouts

maxPrice

public static double maxPrice(Shout s1,
                              Shout s2)

maxPrice

public static double maxPrice(Shout s,
                              double price)

minPrice

public static double minPrice(Shout s1,
                              Shout s2)

minPrice

public static double minPrice(Shout s,
                              double price)

getChild

public Shout getChild()
Get the child of this shout. TODO: it is true in jcat that ' Shouts have children when they are split().'

Returns:
The child Shout object, or null if this Shout is childless.

setChild

public void setChild(Shout child)

getParent

public Shout getParent()
Get the parent of this shout.

Returns:
The parent Shout object, or null if this Shout is parentless.

setParent

public void setParent(Shout parent)

copyFrom

public void copyFrom(Shout other)

split

public Shout split(int excess)
Reduce the quantity of this shout by excess and return a new child shout containing the excess quantity. After a split, parent shouts keep a reference to their children.

Parameters:
excess - The excess quantity

splat

public Shout splat(int excess)

setIsBid

public void setIsBid(boolean isBid)

setId

public void setId(java.lang.String id)

setPrice

public void setPrice(double price)

setQuantity

public void setQuantity(int quantity)

setTrader

public void setTrader(Trader trader)

setSpecialist

public void setSpecialist(Specialist specialist)

getStateDescription

public java.lang.String getStateDescription()