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.

public class StateValidator { public StateValidator(State currentState) { this.currentState = currentState; } public boolean isValid(State newState) { boolean result = false; switch(newState) { case TO_BE_APPROVED: result = (currentState == State.DRAFT); break; case APPROVED: result = (currentState == State.TO_BE_APPROVED); break; case PUBLISHED: result = (currentState == State.APPROVED); break; case ARCHIVED: result = (currentState == State.PUBLISHED); break; case DRAFT: result = (currentState == State.ARCHIVED); break; default: break; } return result; } private State currentState; }

Questions about programming?Chat with your personal AI assistant