package stexfires.io.internal;

/**
 * @author Mathias Kalb
 * @since 0.1
 */
enum ReadableProducerState {
    OPEN,
    READ_BEFORE,
    READ_RECORDS,
    READ_AFTER,
    CLOSE;

    public static void validateStates(ReadableProducerState currentState, ReadableProducerState newState) throws IllegalStateException {
        if (currentState.ordinal() + 1 != newState.ordinal()) {
            throw new IllegalStateException("Wrong ReadableProducerState! " + currentState + " -> " + newState);
        }
    }

    public void validateNotClosed() throws IllegalStateException {
        if (this == CLOSE) {
            throw new IllegalStateException("Wrong ReadableProducerState! " + this);
        }
    }

    public ReadableProducerState validate(ReadableProducerState currentState) throws IllegalStateException {
        validateStates(currentState, this);
        return this;
    }

}

@@ -370,24 +370,65 @@
 rdinal()) %7B%0A
+            if (newState != CLOSE) %7B%0A    
             
@@ -540,197 +540,13 @@
     
-%7D%0A
     %7D
-%0A%0A    public void validateNotClosed() throws IllegalStateException %7B%0A        if (this == CLOSE) %7B%0A            throw new IllegalStateException(%22Wrong ReadableProducerState! %22 + this);
 %0A   

Optimize ReadableProducerState