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 .