protected void throwInvalidState(final String methodName, final State... validStates) {
        String validStatesString = StringUtils.join(" or ", asList(validStates));
        String message = format("%s can only be called when State is %s, not when State is %s.",
                                methodName, validStatesString, state);
        throw new BsonInvalidOperationException(message);
    }
protected void throwInvalidState(final String methodName, final State... validStates) {
        String validStatesString = StringUtils.join(" or ", asList(validStates));
        String message = format("%s can only be called when State is %s, not when State is %s.",
                                methodName, validStatesString, state);
        throw new BsonInvalidOperationException(message);
    }
protected void throwInvalidState ( final String methodName , final State ... validStates ) { String validStatesString = StringUtils . join ( " or " , asList ( validStates ) ) ; String message = format ( "%s can only be called when State is %s, not when State is %s." , methodName , validStatesString , state ) ; throw new BsonInvalidOperationException ( message ) ; }
Throws an InvalidOperationException when the method called is not valid for the current state.

@param methodName  The name of the method.
@param validStates The valid states.
@throws BsonInvalidOperationException when the method called is not valid for the current state.
Throws an InvalidOperationException when the method called is not valid for the current state .