Example usage for org.apache.commons.validator.routines LongValidator getInstance

List of usage examples for org.apache.commons.validator.routines LongValidator getInstance

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines LongValidator getInstance.

Prototype

public static LongValidator getInstance() 

Source Link

Document

Return a singleton instance of this validator.

Usage

From source file:org.apache.metron.common.field.validation.primitive.IntegerValidation.java

@Override
public Predicate<Object> getPredicate() {
    return x -> LongValidator.getInstance().isValid(x == null ? null : x.toString());
}

From source file:org.mule.modules.validation.ValidationModule.java

/**
 * If the specified <code>value</code> is not a valid {@link Long} throw an exception.
 * <p/>/*from  ww w . j  a v a2  s .  c o  m*/
 * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-long}
 *
 * @param value                    Value to validate
 * @param locale                   The locale to use for the format
 * @param pattern                  The pattern used to format the value
 * @param minValue                 The minimum value
 * @param maxValue                 The maximum value
 * @param customExceptionClassName Class name of the exception to throw
 * @throws Exception if not valid
 */
@Processor
public void validateLong(String value, @Optional @Default("US") Locale locale, @Optional String pattern,
        @Optional Long minValue, @Optional Long maxValue,
        @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName)
        throws Exception {
    LongValidator validator = LongValidator.getInstance();

    Long newValue = null;
    if (pattern != null) {
        newValue = validator.validate(value, pattern, locale.getJavaLocale());
    } else {
        newValue = validator.validate(value, locale.getJavaLocale());
    }

    if (newValue == null) {
        throw buildException(customExceptionClassName);
    }
    if (minValue != null) {
        if (!validator.minValue(newValue, minValue)) {
            throw buildException(customExceptionClassName);
        }
    }
    if (maxValue != null) {
        if (!validator.maxValue(newValue, maxValue)) {
            throw buildException(customExceptionClassName);
        }
    }
}

From source file:vista.cliente.DiagClientePersona.java

private boolean validarPersona() {
    boolean flag = false;
    if (!tfNombre.getText().isEmpty() && !tfApellido.getText().isEmpty()) {
        if (!tfCuil.getText().equals("") && Comunes.validarTextFieldCuit(tfCuil)) {

            if (cboTipoDoc.getSelectedIndex() > 0 && LongValidator.getInstance().isValid(tfDocumento.getText())
                    && !tfDocumento.getText().contains(".")) {
                flag = true;/*from   w w w .  jav  a 2s.  c  o  m*/
            } else if (!tfDocumento.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Nmero de documento incorrecto", "Error",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                flag = true;
            }

        } else if (tfCuil.getText().equals("")) {
            flag = true;
        } else {
            JOptionPane.showMessageDialog(null, "Debe ingresar correctamente el CUIL", "Error",
                    JOptionPane.ERROR_MESSAGE);

        }
    } else {
        JOptionPane.showMessageDialog(null, "El cliente debe tener Nombre y Apellido", "Error",
                JOptionPane.ERROR_MESSAGE);
    }
    if (tfDocumento.getText().isEmpty()) {
        flag = false;
        JOptionPane.showMessageDialog(null, "Debe ingresar nro de documento", "Error",
                JOptionPane.ERROR_MESSAGE);
    }
    return flag;
}

From source file:vista.empleados.DiagEmpleadoPersona.java

private boolean validarPersona() {
    if (cboTipoEmpleado.getSelectedIndex() == 0) {
        JOptionPane.showMessageDialog(null, "Debe seleccionar el Tipo de Empleado", "Error",
                JOptionPane.ERROR_MESSAGE);
        return false;
    }//  w w  w .j  a  v a  2  s.  c o m
    if (tfNombre.getText().isEmpty()) {
        JOptionPane.showMessageDialog(null, "Debe escribir un nombre", "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    if (tfApellido.getText().isEmpty()) {
        JOptionPane.showMessageDialog(null, "Debe escribir un apellido", "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    if (!tfCuil.getText().equals("") && !Comunes.validarTextFieldCuit(tfCuil)) {
        JOptionPane.showMessageDialog(null, "Debe escribir cuil correctamente", "Error",
                JOptionPane.ERROR_MESSAGE);
        return false;
    }
    if (cboTipoDoc.getSelectedIndex() == 0) {
        JOptionPane.showMessageDialog(null, "Debe seleccionar tipo de documento", "Error",
                JOptionPane.ERROR_MESSAGE);
        return false;
    }

    if (tfDocumento.getText().isEmpty()) {
        JOptionPane.showMessageDialog(null, "Debe ingresar el numero de Documento", "Error",
                JOptionPane.ERROR_MESSAGE);
        return false;
    }

    if (!LongValidator.getInstance().isValid(tfDocumento.getText())) {
        JOptionPane.showMessageDialog(null, "Nmero de documento incorrecto", "Error",
                JOptionPane.ERROR_MESSAGE);
        return false;
    }
    if (EmpleadoFacade.getInstance().existeDNI(tfDocumento.getText().trim())
            && tipoOperacion.equals("AltaPersona")) {
        JOptionPane.showMessageDialog(null, "DNI ya existe", "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }

    return true;
}