Example usage for java.lang ClassCastException ClassCastException

List of usage examples for java.lang ClassCastException ClassCastException

Introduction

In this page you can find the example usage for java.lang ClassCastException ClassCastException.

Prototype

public ClassCastException() 

Source Link

Document

Constructs a ClassCastException with no detail message.

Usage

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksExTest08.java

/**
 * testValidateMultiField06()//from ww  w .  j  a  v  a  2s. com
 * <br><br>
 *
 * (?n)
 * <br>
 * _?FF,G
 * <br><br>
 * l?F(?) bean:"abc"<br>
 *         (?) va:not null<br>
 *         (?) field:not null<br>
 *                var:multiFieldValidator="java.lang.String"<br>
 *                Msg("message","message")<br>
 *         (?) errors:not null<br>
 *                (vf)<br>
 *         (?) validator:not null<br>
 *         (?) request:not null<br>
 *
 * <br>
 * l?F(?) MultiFieldValidator:?o<br>
 *         (?) O:IllegalArgumentException<br>
 *                    ?bZ?[W?F<br>
 *                    "var value[multiFieldValidator] is invalid."<br>
 *         (?) ?O:?Ox?FG?[<br>
 *                    ?bZ?[W?F<br>
 *                    "var value[multiFieldValidator] is invalid."<br>
 *                    O?F<br>
 *                    ClassCastException<br>
 *         (?) errors:not null<br>
 *                    (vf)<br>
 *
 * <br>
 * fieldmultiFieldValidatorMultiFieldValidatorNX
 * ?AIllegalArgumentException?mF?B
 * <br>
 *
 * @throws Exception ?\bh?O
 */
public void testValidateMultiField06() throws Exception {
    //eXgf?[^?
    // ++++ beanIuWFNg ++++
    String bean = "abc";
    // ++++ ??IuWFNg
    ValidatorAction va = new ValidatorAction();
    // ++++ ?tB?[h?
    Field field = new Field();
    Var var = new Var();
    var.setName("multiFieldValidator");
    var.setValue("java.lang.String");
    field.addVar(var);
    // ?bZ?[W?
    Msg msg = new Msg();
    msg.setKey("message");
    msg.setName("message");
    msg.setResource(false);
    field.addMsg(msg);
    // G?[?
    ActionMessages errors = new ActionMessages();
    // [HTTPNGXg
    MockHttpServletRequest request = new MockHttpServletRequest();
    // ValidatorResourcesCX^X
    ValidatorResources validatorResources = new ValidatorResources();
    // ValidatorCX^X
    Validator validator = new Validator(validatorResources);

    // eXg?s
    try {
        FieldChecksEx.validateMultiField(bean, va, field, errors, validator, request);
        fail();
    } catch (IllegalArgumentException e) {
        assertTrue(errors.isEmpty());
        assertEquals("var value[multiFieldValidator] is invalid.", e.getMessage());
        assertTrue(
                LogUTUtil.checkError("var value[multiFieldValidator] is invalid.", new ClassCastException()));
    }
}

From source file:com.projity.field.Field.java

/**
 * Compares two fields. Normally a simple String compareTo is used, but in
 * the case of array fields, I compare their indexes - we want such fields
 * to sort numerically and not alphabetically so that for example, Cost11
 * appears after Cost2 and not before./*from  w w  w  .  ja  v  a  2 s. com*/
 */
public int compareTo(Object to) {
    if (to == null)
        throw new NullPointerException();
    if (!(to instanceof Field))
        throw new ClassCastException();
    Field toField = (Field) to;
    if (configurationId == toField.configurationId) { // if array field,
        // then compare
        // indexes
        return index - toField.index;
    } else {
        return getName().compareTo(toField.getName());
    }
}