001 package market.statistics;
002
003 import java.util.Calendar;
004
005 import market.Conversions;
006 import market.SMarket;
007
008 public class PriceHistoryEntry extends HistoryEntry {
009
010 private boolean changeInMorning;
011
012 public PriceHistoryEntry(Calendar date, int value) {
013 super(date, value);
014 this.changeInMorning = !SMarket.isOpen() && SMarket.hasTimeAdvanced();
015 }
016
017
018 /**
019 * Returns if an Entry is privsional or not. An entry is provisional (and can therefore be replaced) if
020 * <ul>
021 * <li>it has been created in the morning before the market opened. The market hasn't opened and
022 * the date hasn't advanced since then, that means, it is still the same morning since the
023 * last price change.</li>
024 * <li>it has been created in the evening after the market closed, and this evening has not yet
025 * passed by, that means, it is still the same evening since the last price change.</li>
026 * <li>it has been created in the evening after the market closed, but now is the following morning and
027 * the market hasn't opened yet.</li>
028 * </ul>
029 *
030 * @return if an Entry is provisional or not.
031 */
032 public boolean isProvisional() {
033 return (((Conversions.dayDifference(date, SMarket.getTime()) == 0) &&
034 changeInMorning && SMarket.hasTimeAdvanced()) //created this morning, still morning
035 ||
036 ((Conversions.dayDifference(SMarket.getTime(), date) == 1) &&
037 !changeInMorning && !SMarket.hasTimeAdvanced()) //created this evening, still evening
038 ||
039 (Conversions.dayDifference(date, SMarket.getTime()) == 0 && //created yesterday, market not open
040 !SMarket.isOpen() && SMarket.hasTimeAdvanced()));
041 }
042 }
043
044