// Path: library/src/main/java/com/comuto/validator/UnsupportedException.java
// public class UnsupportedException extends RuntimeException {
//     /**
//      * Constructs a new {@code RuntimeException} with the current stack trace
//      * and the specified detail message.
//      *
//      * @param constraint the constraint for this exception.
//      * @param o the object invalid value;
//      * @param propertyName the property.
//      */
//     public UnsupportedException(Constraint constraint, Object o, String propertyName) {
//         super("Constraint: "
//             + constraint.getClass().getSimpleName()
//             + " cannot handle "
//             + o.getClass().getName()
//             + "on property: "
//             + propertyName
//             + ". If you want to validate a custom Object, you can create a custom Constraint which extends this one and override validate().");
//     }
// }
// 
// Path: library/src/main/java/com/comuto/validator/Violation.java
// public class Violation {
//     private final String propertyName;
//     private final Object invalidValue;
//     private final String message;
//     private final String code;
// 
//     /**
//      * Construct the violation with final values.
//      *
//      * @param propertyName The name of the field. This is defined by the user.
//      * @param invalidValue The invalid which have violate the constraint.
//      * @param message The interpolated message.
//      * @param code The Error code of the constraint.
//      */
//     public Violation(String propertyName, Object invalidValue, String message, String code) {
//         this.propertyName = propertyName;
//         this.invalidValue = invalidValue;
//         this.message = message;
//         this.code = code;
//     }
// 
//     /**
//      * @return the interpolated error message for this constraint violation
//      */
//     public String getMessage() {
//         return message;
//     }
// 
//     /**
//      * Returns the value failing to pass the constraint.
//      * For cross-parameter constraints, an {@code Object[]} representing
//      * the method invocation arguments is returned.
//      *
//      * @return the value failing to pass the constraint
//      */
//     public Object getInvalidValue() {
//         return invalidValue;
//     }
// 
//     /**
//      * Returns the name of the property.
//      *
//      * @return the property name.
//      */
//     public String getPropertyName() {
//         return propertyName;
//     }
// 
//     /**
//      * Returns a machine-digestible error code for the violation.
//      *
//      * @return String The error code.
//      */
//     public String getCode() {
//         return code;
//     }
// }


import android.support.annotation.NonNull;
import com.comuto.validator.UnsupportedException;
import com.comuto.validator.Violation;
import java.util.HashSet;
import java.util.Set;
package com.comuto.validator.constraint;


/**
 * Validate the object value to have a correct length.
 */
public class LengthConstraint extends Constraint<Object> {
    /**
     * Constant pass to Violation when length is too small.
     */
    public static final String ERROR_CODE_TOO_SMALL = "ERROR_CODE_TOO_SMALL";
    /**
     * Constant pass to Violation when the length value is too large.
     */
    public static final String ERROR_CODE_TOO_LARGE = "ERROR_CODE_TOO_LARGE";

    protected double min = 0;
    protected double max = Double.MAX_VALUE;

    protected String minMessage = "This value is too short. It should have %s characters or more.";
    protected String maxMessage = "This value is too long. It should have %s characters or less.";

    /**
     * Constructor of the constraint
     *
     * @param object the object to validate through this constraint.
     * @param propertyName the property name of your field, this allow you to have the name of the field in violation.
     */
    public LengthConstraint(@NonNull Object object, @NonNull String propertyName) {
        super(object, propertyName);
    }

    /**
     * Validate if the value has reach the excepted values.
     *
     * @return a non-null set of violation. If there is no violations, this set will be empty.
     * @throws UnsupportedException when an constraint object to validate is not supported.
     */
    @NonNull
    @Override
    public Set<Violation> validate() throws UnsupportedException {
// Path: library/src/main/java/com/comuto/validator/UnsupportedException.java
// public class UnsupportedException extends RuntimeException {
//     /**
//      * Constructs a new {@code RuntimeException} with the current stack trace
//      * and the specified detail message.
//      *
//      * @param constraint the constraint for this exception.
//      * @param o the object invalid value;
//      * @param propertyName the property.
//      */
//     public UnsupportedException(Constraint constraint, Object o, String propertyName) {
//         super("Constraint: "
//             + constraint.getClass().getSimpleName()
//             + " cannot handle "
//             + o.getClass().getName()
//             + "on property: "
//             + propertyName
//             + ". If you want to validate a custom Object, you can create a custom Constraint which extends this one and override validate().");
//     }
// }
// 
// Path: library/src/main/java/com/comuto/validator/Violation.java
// public class Violation {
//     private final String propertyName;
//     private final Object invalidValue;
//     private final String message;
//     private final String code;
// 
//     /**
//      * Construct the violation with final values.
//      *
//      * @param propertyName The name of the field. This is defined by the user.
//      * @param invalidValue The invalid which have violate the constraint.
//      * @param message The interpolated message.
//      * @param code The Error code of the constraint.
//      */
//     public Violation(String propertyName, Object invalidValue, String message, String code) {
//         this.propertyName = propertyName;
//         this.invalidValue = invalidValue;
//         this.message = message;
//         this.code = code;
//     }
// 
//     /**
//      * @return the interpolated error message for this constraint violation
//      */
//     public String getMessage() {
//         return message;
//     }
// 
//     /**
//      * Returns the value failing to pass the constraint.
//      * For cross-parameter constraints, an {@code Object[]} representing
//      * the method invocation arguments is returned.
//      *
//      * @return the value failing to pass the constraint
//      */
//     public Object getInvalidValue() {
//         return invalidValue;
//     }
// 
//     /**
//      * Returns the name of the property.
//      *
//      * @return the property name.
//      */
//     public String getPropertyName() {
//         return propertyName;
//     }
// 
//     /**
//      * Returns a machine-digestible error code for the violation.
//      *
//      * @return String The error code.
//      */
//     public String getCode() {
//         return code;
//     }
// }


// Path: library/src/main/java/com/comuto/validator/constraint/LengthConstraint.java
import android.support.annotation.NonNull;
import com.comuto.validator.UnsupportedException;
import com.comuto.validator.Violation;
import java.util.HashSet;
import java.util.Set;

package com.comuto.validator.constraint;


/**
 * Validate the object value to have a correct length.
 */
public class LengthConstraint extends Constraint<Object> {
    /**
     * Constant pass to Violation when length is too small.
     */
    public static final String ERROR_CODE_TOO_SMALL = "ERROR_CODE_TOO_SMALL";
    /**
     * Constant pass to Violation when the length value is too large.
     */
    public static final String ERROR_CODE_TOO_LARGE = "ERROR_CODE_TOO_LARGE";

    protected double min = 0;
    protected double max = Double.MAX_VALUE;

    protected String minMessage = "This value is too short. It should have %s characters or more.";
    protected String maxMessage = "This value is too long. It should have %s characters or less.";

    /**
     * Constructor of the constraint
     *
     * @param object the object to validate through this constraint.
     * @param propertyName the property name of your field, this allow you to have the name of the field in violation.
     */
    public LengthConstraint(@NonNull Object object, @NonNull String propertyName) {
        super(object, propertyName);
    }

    /**
     * Validate if the value has reach the excepted values.
     *
     * @return a non-null set of violation. If there is no violations, this set will be empty.
     * @throws UnsupportedException when an constraint object to validate is not supported.
     */
    @NonNull
    @Override
    public Set<Violation> validate() throws UnsupportedException {
        final Set<Violation> violations = new HashSet<>();