001 package data;
002
003 /**
004 * Objectifier to compute the value of a CatalogItem.
005 *
006 * @see Stock#sumStock
007 *
008 * @author Steffen Zschaler
009 * @version 2.0 18/08/1999
010 * @since v1.0
011 */
012 public class CatalogItemValue extends Object {
013
014 /**
015 * Return the value of an CatalogItem.
016 *
017 * <p>By default returns {@link CatalogItem#getValue ci.getValue()}, but you can create subclasses that
018 * refer to any attribute you want to use as the CatalogItem's value.</p>
019 *
020 * @override Always
021 *
022 * @param ci the CatalogItem whose value is to be computed
023 *
024 * @return the value of ci.
025 *
026 * @see Stock#sumStock
027 */
028 public Value getValue(CatalogItem ci) {
029 return ci.getValue();
030 }
031
032 /**
033 * A CatalogItemValue that will return the {@link QuoteValue#getBid bid} if the
034 * {@link CatalogItem#getValue standard value} of a {@link CatalogItem} is a {@link QuoteValue}. Otherwise,
035 * it will simply return the standard value of the CatalogItem.
036 */
037 public static final CatalogItemValue EVALUATE_BID = new CatalogItemValue() {
038 public Value getValue(CatalogItem ci) {
039 Value vReturn = ci.getValue();
040
041 if (vReturn instanceof QuoteValue) {
042 vReturn = ((QuoteValue)vReturn).getBid();
043 }
044
045 return vReturn;
046 }
047 };
048
049 /**
050 * A CatalogItemValue that will return the {@link QuoteValue#getOffer offer} if the
051 * {@link CatalogItem#getValue standard value} of a {@link CatalogItem} is a {@link QuoteValue}. Otherwise,
052 * it will simply return the standard value of the CatalogItem.
053 */
054 public static final CatalogItemValue EVALUATE_OFFER = new CatalogItemValue() {
055 public Value getValue(CatalogItem ci) {
056 Value vReturn = ci.getValue();
057
058 if (vReturn instanceof QuoteValue) {
059 vReturn = ((QuoteValue)vReturn).getOffer();
060 }
061
062 return vReturn;
063 }
064 };
065
066 /**
067 * A CatalogItemValue that will return the {@link QuoteValue#getMid mid} if the
068 * {@link CatalogItem#getValue standard value} of a {@link CatalogItem} is a {@link QuoteValue}. Otherwise,
069 * it will simply return the standard value of the CatalogItem.
070 */
071 public static final CatalogItemValue EVALUATE_MID = new CatalogItemValue() {
072 public Value getValue(CatalogItem ci) {
073 Value vReturn = ci.getValue();
074
075 if (vReturn instanceof QuoteValue) {
076 vReturn = ((QuoteValue)vReturn).getMid();
077 }
078
079 return vReturn;
080 }
081 };
082
083 /**
084 * A CatalogItemValue that will return the {@link QuoteValue#getSpread spread} if the
085 * {@link CatalogItem#getValue standard value} of a {@link CatalogItem} is a {@link QuoteValue}. Otherwise,
086 * it will simply return the standard value of the CatalogItem.
087 */
088 public static final CatalogItemValue EVALUATE_SPREAD = new CatalogItemValue() {
089 public Value getValue(CatalogItem ci) {
090 Value vReturn = ci.getValue();
091
092 if (vReturn instanceof QuoteValue) {
093 vReturn = ((QuoteValue)vReturn).getSpread();
094 }
095
096 return vReturn;
097 }
098 };
099 }