Java Assert assertInstance(Object object, Class c)

Here you can find the source of assertInstance(Object object, Class c)

Description

assert Instance

License

Open Source License

Declaration

public static void assertInstance(Object object, Class c) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  ww  w  .j a v a  2s  .co m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    public static void assertInstance(Object object, Class c) {
        assertInstance(object, c, false);
    }

    public static void assertInstance(Object object, Class c,
            boolean allowNull) {
        if (object == null && allowNull)
            return;

        if (object == null || c == null)
            throw new NullPointerException();
        else if (!c.isInstance(object))
            throw new IllegalArgumentException();
    }
}

Related

  1. assertIndex(final int size, final int index)
  2. assertIndex(final String s, final int index)
  3. assertIndex(int index, String msg)
  4. assertInputNotEmpty(final String input, final String message)
  5. assertInstance(final Object object, final Class c)
  6. assertInstanceOf(Object obj, Class classType)
  7. assertInstanceOf(Object obj, Class expClass)
  8. assertInstanceOf(Object object, Class expectClass)
  9. assertIntegerGreaterThanZero(long number, String name)