001: /* SimpleHiLoModel.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Thu Aug 14 21:19:30 2006, Created by henrichen
010: }}IS_NOTE
011:
012: Copyright (C) 2006 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.zul;
020:
021: import org.zkoss.lang.Objects;
022: import org.zkoss.zul.event.ChartDataEvent;
023: import org.zkoss.zul.event.ChartDataListener;
024:
025: import java.util.Map;
026: import java.util.Date;
027: import java.util.List;
028: import java.util.LinkedHashMap;
029: import java.util.Iterator;
030: import java.util.ArrayList;
031: import java.util.Collection;
032:
033: /**
034: * A HiLo data model implementation of {@link HiLoModel}.
035: * A HiLo model is an model generally used in stock market to hold
036: * (date, open, high, low, close, volume) tuple data objects .
037: *
038: * @author henrichen
039: * @see HiLoModel
040: * @see Chart
041: */
042: public class SimpleHiLoModel extends AbstractChartModel implements
043: HiLoModel {
044: private Comparable _series; //the only series
045: private List _hlTuples = new ArrayList(31);
046:
047: //-- HiLoModel --//
048: public Comparable getSeries() {
049: return _series;
050: }
051:
052: public void setSeries(Comparable series) {
053: _series = series;
054: }
055:
056: public int getDataCount() {
057: return _hlTuples.size();
058: }
059:
060: public Date getDate(int index) {
061: return ((HiLoTuple) _hlTuples.get(index)).getDate();
062: }
063:
064: public Number getOpen(int index) {
065: return ((HiLoTuple) _hlTuples.get(index)).getOpen();
066: }
067:
068: public Number getHigh(int index) {
069: return ((HiLoTuple) _hlTuples.get(index)).getHigh();
070: }
071:
072: public Number getLow(int index) {
073: return ((HiLoTuple) _hlTuples.get(index)).getLow();
074: }
075:
076: public Number getClose(int index) {
077: return ((HiLoTuple) _hlTuples.get(index)).getClose();
078: }
079:
080: public Number getVolume(int index) {
081: return ((HiLoTuple) _hlTuples.get(index)).getVolume();
082: }
083:
084: public void addValue(Date date, Number open, Number high,
085: Number low, Number close, Number volume) {
086: _hlTuples.add(new HiLoTuple(date, open, high, low, close,
087: volume));
088: fireEvent(ChartDataEvent.CHANGED, null, null);
089: }
090:
091: public void removeValue(int index) {
092: _hlTuples.remove(index);
093: fireEvent(ChartDataEvent.REMOVED, null, null);
094: }
095:
096: public void clear() {
097: _hlTuples.clear();
098: fireEvent(ChartDataEvent.REMOVED, null, null);
099: }
100:
101: //-- internal class --//
102: private static class HiLoTuple {
103: private Date _date;
104: private Number _open;
105: private Number _high;
106: private Number _low;
107: private Number _close;
108: private Number _volume;
109:
110: private HiLoTuple(Date date, Number open, Number high,
111: Number low, Number close, Number volume) {
112: _date = date;
113: _open = open;
114: _high = high;
115: _low = low;
116: _close = close;
117: _volume = volume;
118: }
119:
120: private Date getDate() {
121: return _date;
122: }
123:
124: private Number getOpen() {
125: return _open;
126: }
127:
128: private Number getHigh() {
129: return _high;
130: }
131:
132: private Number getLow() {
133: return _low;
134: }
135:
136: private Number getClose() {
137: return _close;
138: }
139:
140: private Number getVolume() {
141: return _volume;
142: }
143: }
144: }
|