Shreyas arya


generate functionTue, 24 Jan 2023

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

public boolean isValidNextStatus(Order order, Status status) { switch (order.getStatus()) { case CREATED: return status == Status.PENDING || status == Status.CANCELED; case PENDING: return status == Status.IN_PROCESS || status == Status.CANCELED; case IN_PROCESS: return status == Status.SHIPPED || status == Status.CANCELED; case SHIPPED: return status == Status.DELIVERED; case DELIVERED: case CANCELED: default: return false; } }

Questions about programming?Chat with your personal AI assistant