Java Assert assertParameter(Class expectedClass, Object[] params, int index)

Here you can find the source of assertParameter(Class expectedClass, Object[] params, int index)

Description

Utility method to provide more descriptive unchecked exceptions for unmarshalling object from Tapestry service Parameters.

License

Contributor Agreement License

Exception

Parameter Description
IllegalArgumentException if parameter is not there is wrong class type

Declaration

public static final Object assertParameter(Class expectedClass,
        Object[] params, int index) 

Method Source Code

//package com.java2s;
/*/*  w w  w  .ja va  2s.  co m*/
 * 
 * 
 * Copyright (C) 2007 Pingtel Corp., certain elements licensed under a Contributor Agreement.  
 * Contributors retain copyright to elements licensed under a Contributor Agreement.
 * Licensed to the User under the LGPL license.
 * 
 * $
 */

public class Main {
    /**
     * Utility method to provide more descriptive unchecked exceptions for unmarshalling object
     * from Tapestry service Parameters.
     * 
     * Please note that in most cases it is better to use listeners parameters directly.
     * 
     * @throws IllegalArgumentException if parameter is not there is wrong class type
     */
    public static final Object assertParameter(Class expectedClass,
            Object[] params, int index) {
        if (params == null || params.length < index) {
            throw new IllegalArgumentException(
                    "Missing parameter at position " + index);
        }

        if (params[index] != null) {
            Class actualClass = params[index].getClass();
            if (!expectedClass.isAssignableFrom(actualClass)) {
                throw new IllegalArgumentException("Object of class type "
                        + expectedClass.getName()
                        + " was expected at position " + index
                        + " but class type was " + actualClass.getName());
            }
        }

        return params[index];
    }
}

Related

  1. assertObjectEmpty(Object value)
  2. assertObjEquals(Object expected, Object actual)
  3. assertOffsetLengthValid(int offset, int length, int arrayLength)
  4. assertOid(final String s)
  5. assertOneBitMask(long mask)
  6. assertParameterInRange(long param, long lower, long upper)
  7. assertParameterWithinBounds(String name, long lower, long upper, long parameter)
  8. assertParameterWithinBounds(String name, long lower, long upper, long parameter)
  9. assertPasswordMeetsRequirements(String password, boolean expected)