001/* 002 * JKNIV, utils - Helper utilities for jdk code. 003 * 004 * Copyright (C) 2017, the original author or authors. 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software Foundation, Inc., 018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 019 */ 020package net.sf.jkniv.asserts; 021 022public class IsNull extends AbstractAssert 023{ 024 IsNull() 025 { 026 super("[Assertion failed] - the object argument must be null"); 027 } 028 029 /** 030 * @param message the exception message to use if the assertion fails 031 */ 032 IsNull(String message) 033 { 034 super(message); 035 } 036 037 /** 038 * Assert that an object is {@code null} . 039 * <pre class="code">Assert.isNull(value, "The value must be null");</pre> 040 * @param objects the object to check 041 * @throws IllegalArgumentException if the object is not {@code null} 042 */ 043 public void verify(Object... objects) 044 { 045 if (verifyObjects(objects)) 046 throwDefaultException(); 047 } 048 049 public void verify(RuntimeException e, Object... objects) 050 { 051 if (verifyObjects(objects)) 052 throw e; 053 } 054 055 public void verifyArray(Object[] object) 056 { 057 if (verifyObject(object)) 058 throwDefaultException(); 059 } 060 061 public void verifyArray(RuntimeException e, Object[] object) 062 { 063 if (verifyObject(object)) 064 throw e; 065 } 066 067 private boolean verifyObjects(Object... objects) 068 { 069 boolean ret = false; 070 if (objects != null && objects.length > 0) 071 { 072 for (Object o : objects) 073 { 074 if (verifyObject(o)) 075 { 076 ret = true; 077 break; 078 } 079 } 080 } 081 return ret; 082 } 083 084 private boolean verifyObject(Object object) 085 { 086 boolean ret = false; 087 if (object != null) 088 ret = true; 089 090 return ret; 091 } 092}