class JobFunctions {

    public static boolean containsExactlyTaskStates(Task task, TaskState... expectedStates) {
        if (expectedStates.length == 0) {
            return false;
        }

        TaskState taskState = task.getStatus().getState();
        List<TaskStatus> statusHistory = task.getStatusHistory();
        if (expectedStates.length == 1 && statusHistory.isEmpty()) {
            return taskState == expectedStates[0];
        }

        // For non-single state values, we have to eliminate possible duplicates.
        Set<TaskState> expectedPreviousStates = CollectionsExt.asSet(expectedStates);
        Set<TaskState> taskStates = statusHistory.stream().map(ExecutableStatus::getState).collect(Collectors.toSet());
        taskStates.add(taskState);

        return expectedPreviousStates.equals(taskStates);
    }

    private  JobFunctions();

}