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        /**
011             * ID for serialization.
012             */
013            private static final long serialVersionUID = -1757057771582369394L;
014            
015            private boolean changeInMorning;
016    
017        public PriceHistoryEntry(Calendar date, int value) {
018            super(date, value);
019            this.changeInMorning = !SMarket.isOpen() && SMarket.hasTimeAdvanced();
020        }
021    
022    
023        /**
024         * Returns if an Entry is privsional or not. An entry is provisional (and can therefore be replaced) if
025         * <ul>
026         *   <li>it has been created in the morning before the market opened. The market hasn't opened and
027         *          the date hasn't advanced since then, that means, it is still the same morning since the
028         *          last price change.</li>
029         *   <li>it has been created in the evening after the market closed, and this evening has not yet
030         *          passed by, that means, it is still the same evening since the last price change.</li>
031         *   <li>it has been created in the evening after the market closed, but now is the following morning and
032         *          the market hasn't opened yet.</li>
033         * </ul>
034         *
035         * @return if an Entry is provisional or not.
036         */
037        public boolean isProvisional() {
038            return (((Conversions.dayDifference(date, SMarket.getTime()) == 0) &&
039                    changeInMorning && SMarket.hasTimeAdvanced()) //created this morning, still morning
040                    ||
041                    ((Conversions.dayDifference(SMarket.getTime(), date) == 1) &&
042                    !changeInMorning && !SMarket.hasTimeAdvanced()) //created this evening, still evening
043                    ||
044                    (Conversions.dayDifference(date, SMarket.getTime()) == 0 && //created yesterday, market not open
045                    !SMarket.isOpen() && SMarket.hasTimeAdvanced()));
046        }
047    }
048    
049