private synchronized void check(MarketState ms) throws InvalidMarketStateTransition {
        if (state == MarketState.CLOSED) {
            if (ms == MarketState.OPEN) {
                throw new InvalidMarketStateTransition("InvalidMarketStateTransition: Market cannot go directly from CLOSED to OPEN.");
            } else if (ms == MarketState.CLOSED) {
                throw new InvalidMarketStateTransition("InvalidMarketStateTransition: Market is already CLOSED.");
            }
        } else if (state == MarketState.OPEN) {
            if (ms == MarketState.PREOPEN) {
                throw new InvalidMarketStateTransition("InvalidMarketStateTransition: Market cannot go from OPEN to PREOPEN.");
            } else if (ms == MarketState.OPEN) {
                throw new InvalidMarketStateTransition("InvalidMarketStateTransition: Market is already OPEN.");
            }
        } else if (state == MarketState.PREOPEN) {
            if (ms == MarketState.CLOSED) {
                throw new InvalidMarketStateTransition("InvalidMarketStateTransition: Market cannot go from PREOPEN to CLOSED.");
            } else if (ms == MarketState.PREOPEN) {
                throw new InvalidMarketStateTransition("InvalidMarketStateTransition: Market is already PREOPEN.");
            }
        } else {
            //return the market state Transition is correct.
        }
    }