1 18 19 package org.apache.jorphan.timer; 20 21 25 public abstract class AbstractTimer implements ITimer, ITimerConstants 26 { 27 28 private int m_state; 29 30 31 private double m_data; 32 33 34 37 public void start() 38 { 39 if (m_state != STATE_READY) 40 { 41 throw new IllegalStateException ( 42 this 43 + ": start() must be called from READY state, " 44 + "current state is " 45 + STATE_NAMES[m_state]); 46 } 47 48 m_state = STATE_STARTED; 49 m_data = getCurrentTime(); 50 } 51 52 55 public void stop() 56 { 57 final double data = getCurrentTime(); 59 60 if (m_state != STATE_STARTED) 61 { 62 throw new IllegalStateException ( 63 this 64 + ": stop() must be called from STARTED state, " 65 + "current state is " 66 + STATE_NAMES[m_state]); 67 } 68 69 m_data = data - m_data; 70 m_state = STATE_STOPPED; 71 } 72 73 76 public double getDuration() 77 { 78 if (m_state != STATE_STOPPED) 79 { 80 throw new IllegalStateException ( 81 this 82 + ": getDuration() must be called from STOPPED state, " 83 + "current state is " 84 + STATE_NAMES[m_state]); 85 } 86 return m_data; 87 } 88 89 92 public void reset() 93 { 94 m_state = STATE_READY; 95 } 96 97 protected abstract double getCurrentTime(); 98 } 99 | Popular Tags |