public Lifecycle transitionTo(STATE next) { Lifecycle nextLifecycle = null; switch (next) { case SUSPENDED: // only RUNNING instances can be SUSPENDED if (STATE.RUNNING.equals(current)) { nextLifecycle = new Lifecycle(instance, next); instance.suspended = true; break; } else { throw new IllegalTransitionException(current, next); } case ENDED: // both RUNNING and SUSPENDED instances can be ENDED if (STATE.RUNNING.equals(current) || STATE.SUSPENDED.equals(current)) { nextLifecycle = new Lifecycle(instance, next); instance.suspended = false; instance.endDate = new Date(); break; } else { throw new IllegalTransitionException(current, next); } case RUNNING: // only SUSPENDED instances can become RUNNING if (STATE.SUSPENDED.equals(current)) { nextLifecycle = new Lifecycle(instance, next); instance.suspended = false; break; } else { throw new IllegalTransitionException(current, next); } default: throw new IllegalTransitionException(current, next); } return nextLifecycle; }