net.obsearch.asserts
Class OBAsserts

java.lang.Object
  extended by net.obsearch.asserts.OBAsserts

public final class OBAsserts
extends Object

This class contains utility functions that help to check for conditions and create exceptions if those conditions are not met. The functions can be statically imported for convenience

Since:
0.7
Author:
Arnoldo Jose Muller Molina

Method Summary
static void chkAssert(boolean condition, String msg)
          Creates an OBException with the given msg if the given condition is false.
static void chkAssertStorage(boolean condition, String msg)
           
static void chkEven(long x)
          Make sure x is even.
static void chkFileExists(File file)
          Checks that the given file exists, otherwise throws an IOException
static void chkFileExists(String file)
           
static void chkFileNotExists(File file)
           
static void chkFileNotExists(String file)
           
static void chkNotNull(Object x, String msg)
           
static void chkParam(boolean condition, String msg)
          Creates an IllegalArgumentException with the given msg if the given condition is false.
static void chkPositive(long x)
          Checks if the given number is greater or equal than 0.
static void chkRange(int toCheck, int min, int max)
          Checks that the given value "toCheck" is within range [min, max].
static void chkRange(long toCheck, long min, long max)
          Checks that the given value "toCheck" is within range [min, max].
static void chkRange(short toCheck, short min, short max)
          Checks that the given value "toCheck" is within range [min, max].
static void fail(String msg)
          Fail with the given message.
static void notNull(Object x)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

chkAssert

public static void chkAssert(boolean condition,
                             String msg)
                      throws OBException
Creates an OBException with the given msg if the given condition is false.

Parameters:
condition - Condition to be tested
msg - Msg to output in the exception if condition == false
Throws:
OBException - If an error occurrs it will be wrapped in an OBException

chkNotNull

public static void chkNotNull(Object x,
                              String msg)
                       throws OBException
Throws:
OBException

chkAssertStorage

public static void chkAssertStorage(boolean condition,
                                    String msg)
                             throws OBStorageException
Throws:
OBStorageException

chkParam

public static void chkParam(boolean condition,
                            String msg)
Creates an IllegalArgumentException with the given msg if the given condition is false.

Parameters:
condition - Condition to be tested
msg - Msg to output in the exception if condition == false

notNull

public static void notNull(Object x)
                    throws OBException
Throws:
OBException

chkFileExists

public static void chkFileExists(File file)
                          throws OBStorageException
Checks that the given file exists, otherwise throws an IOException

Parameters:
file - File that will be confirmed for existence
Throws:
IOException - if the given file does not exist
OBStorageException

chkFileExists

public static void chkFileExists(String file)
                          throws OBStorageException
Throws:
OBStorageException

chkFileNotExists

public static void chkFileNotExists(String file)
                             throws OBStorageException
Throws:
OBStorageException

chkFileNotExists

public static void chkFileNotExists(File file)
                             throws OBStorageException
Throws:
OBStorageException

fail

public static void fail(String msg)
                 throws OBException
Fail with the given message.

Parameters:
msg - The message to be thrown.
Throws:
OBException

chkRange

public static void chkRange(int toCheck,
                            int min,
                            int max)
Checks that the given value "toCheck" is within range [min, max]. If not, a IndexOutOfBoundsException is thrown.

Parameters:
toCheck - Value to be checked
min - minimum bound
max - maximum bound
Throws:
IndexOutOfBoundsException

chkRange

public static void chkRange(long toCheck,
                            long min,
                            long max)
Checks that the given value "toCheck" is within range [min, max]. If not, a IndexOutOfBoundsException is thrown.

Parameters:
toCheck - Value to be checked
min - minimum bound
max - maximum bound

chkPositive

public static void chkPositive(long x)
Checks if the given number is greater or equal than 0.

Parameters:
x -

chkEven

public static void chkEven(long x)
Make sure x is even.

Parameters:
x - number to verify

chkRange

public static void chkRange(short toCheck,
                            short min,
                            short max)
Checks that the given value "toCheck" is within range [min, max]. If not, a IndexOutOfBoundsException is thrown.

Parameters:
toCheck - Value to be checked
min - minimum bound
max - maximum bound


Copyright © 2007-2011 Arnoldo Jose Muller Molina. All Rights Reserved.