Shreyas arya

Generation

generate functionMon, 23 Jan 2023

We need to create validators for each status. The validator will check if transition from current state is allowed or not.

enum State { STARTED, IN_PROGRESS, RESOLVED, CLOSED } enum Validator { START_TO_INPROGRESS { public void validate(State from, State to) { if(from != STARTED) { throw new IllegalStateException("Not allowed state transition from: " + from + " to: " + to); } } }, INPROGRESS_TO_RESOLVED { public void validate(State from, State to) { if(from != IN_PROGRESS || to != RESOLVED) { throw new IllegalStateException("Not allowed state transition from: " + from + " to: " + to); } } }, RESOLVED_TO_CLOSED { public void validate(State from, State to) { if(from != RESOLVED || to != CLOSED) { throw new IllegalStateException("Not allowed state transition from: " + from + " to: " +

Questions about programming?Chat with your personal AI assistant