// Path: lib/src/main/java/com/github/niqdev/openwebnet/OpenSession.java
// public class OpenSession {
// 
//     private final OpenMessage request;
//     private final List<OpenMessage> response = new ArrayList<>();
// 
//     private OpenSession(OpenMessage request) {
//         checkNotNull(request, "request can't be null");
//         this.request = request;
//     }
// 
//     /**
//      * Helper method to create a new session.
//      *
//      * @param request message
//      * @return session
//      */
//     public static OpenSession newSession(OpenMessage request) {
//         return new OpenSession(request);
//     }
// 
//     /**
//      * Update the response messages.
//      *
//      * @param response messages
//      * @return session
//      */
//     public OpenSession addAllResponse(List<OpenMessage> response) {
//         checkNotNull(response, "response can't be null");
//         this.response.addAll(response);
//         return this;
//     }
// 
//     /**
//      * Update the response messages.
//      *
//      * @param response messages
//      * @return session
//      */
//     public OpenSession addResponse(OpenMessage response) {
//         checkNotNull(response, "response can't be null");
//         this.response.add(response);
//         return this;
//     }
// 
//     /**
//      * Returns the initial request message.
//      *
//      * @return request
//      */
//     public OpenMessage getRequest() {
//         return request;
//     }
// 
//     /**
//      * Returns the response messages.
//      *
//      * @return response
//      */
//     public List<OpenMessage> getResponse() {
//         return response;
//     }
// 
//     @Override
//     public String toString() {
//         return MoreObjects.toStringHelper(this)
//             .add("request", request.getValue())
//             .add("response", response)
//             .toString();
//     }
// }


import com.github.niqdev.openwebnet.OpenSession;
import rx.functions.Action0;
import rx.functions.Func1;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;
    }

    protected static void checkRange(Integer from, Integer to, Integer value) {
        checkNotNull(value, "invalid null value");
        checkArgument(isInRange(from, to, value), format("value must be between %d and %d", from, to));
    }

    protected static boolean isInRange(Integer from, Integer to, Integer value) {
        checkNotNull(value, "invalid null value");
        return value >= from && value <= to;
    }

    /*
     * See also org.apache.commons.lang.StringUtils.isNumeric
     */
    protected static int checkIsInteger(String value) {
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("invalid integer format");
        }
    }

    protected static void isValidPrefixType(OpenMessage request, String format, int who) {
        checkNotNull(request, "request is null");
        checkNotNull(request.getValue(), "request value is null");
        boolean isValidWho = request.getValue().startsWith(format(format, who));
        checkArgument(isValidWho, "invalid request of type " + who);
    }

// Path: lib/src/main/java/com/github/niqdev/openwebnet/OpenSession.java
// public class OpenSession {
// 
//     private final OpenMessage request;
//     private final List<OpenMessage> response = new ArrayList<>();
// 
//     private OpenSession(OpenMessage request) {
//         checkNotNull(request, "request can't be null");
//         this.request = request;
//     }
// 
//     /**
//      * Helper method to create a new session.
//      *
//      * @param request message
//      * @return session
//      */
//     public static OpenSession newSession(OpenMessage request) {
//         return new OpenSession(request);
//     }
// 
//     /**
//      * Update the response messages.
//      *
//      * @param response messages
//      * @return session
//      */
//     public OpenSession addAllResponse(List<OpenMessage> response) {
//         checkNotNull(response, "response can't be null");
//         this.response.addAll(response);
//         return this;
//     }
// 
//     /**
//      * Update the response messages.
//      *
//      * @param response messages
//      * @return session
//      */
//     public OpenSession addResponse(OpenMessage response) {
//         checkNotNull(response, "response can't be null");
//         this.response.add(response);
//         return this;
//     }
// 
//     /**
//      * Returns the initial request message.
//      *
//      * @return request
//      */
//     public OpenMessage getRequest() {
//         return request;
//     }
// 
//     /**
//      * Returns the response messages.
//      *
//      * @return response
//      */
//     public List<OpenMessage> getResponse() {
//         return response;
//     }
// 
//     @Override
//     public String toString() {
//         return MoreObjects.toStringHelper(this)
//             .add("request", request.getValue())
//             .add("response", response)
//             .toString();
//     }
// }


// Path: lib/src/main/java/com/github/niqdev/openwebnet/message/BaseOpenMessage.java
import com.github.niqdev.openwebnet.OpenSession;
import rx.functions.Action0;
import rx.functions.Func1;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;

    }

    protected static void checkRange(Integer from, Integer to, Integer value) {
        checkNotNull(value, "invalid null value");
        checkArgument(isInRange(from, to, value), format("value must be between %d and %d", from, to));
    }

    protected static boolean isInRange(Integer from, Integer to, Integer value) {
        checkNotNull(value, "invalid null value");
        return value >= from && value <= to;
    }

    /*
     * See also org.apache.commons.lang.StringUtils.isNumeric
     */
    protected static int checkIsInteger(String value) {
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("invalid integer format");
        }
    }

    protected static void isValidPrefixType(OpenMessage request, String format, int who) {
        checkNotNull(request, "request is null");
        checkNotNull(request.getValue(), "request value is null");
        boolean isValidWho = request.getValue().startsWith(format(format, who));
        checkArgument(isValidWho, "invalid request of type " + who);
    }

    protected static Func1<OpenSession, OpenSession> handleResponse(Action0 onSuccess, Action0 onFail, int who) {