Overview

 
Package  Use  Tree  Deprecated  Index  Help 
Eclipse Platform
Release 3.0
 PREV CLASS   NEXT CLASS FRAMES    NO FRAMES  
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD


 

org.eclipse.jface.util
Class Assert

java.lang.Object
  extended byorg.eclipse.jface.util.Assert


public final class Assert
extends Object

Assert is useful for for embedding runtime sanity checks in code. The static predicate methods all test a condition and throw some type of unchecked exception if the condition does not hold.

Assertion failure exceptions, like most runtime exceptions, are thrown when something is misbehaving. Assertion failures are invariably unspecified behavior; consequently, clients should never rely on these being thrown (or not thrown). If you find yourself in the position where you need to catch an assertion failure, you have most certainly written your program incorrectly.

Note that an assert statement is slated to be added to the Java language in JDK 1.4, rending this class obsolete.


Method Summary
static boolean isLegal(boolean expression)
          Asserts that an argument is legal.
static boolean isLegal(boolean expression, String message)
          Asserts that an argument is legal.
static void isNotNull(Object object)
          Asserts that the given object is not null.
static void isNotNull(Object object, String message)
          Asserts that the given object is not null.
static boolean isTrue(boolean expression)
          Asserts that the given boolean is true.
static boolean isTrue(boolean expression, String message)
          Asserts that the given boolean is true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

 

 

isLegal

public static boolean isLegal(boolean expression)

Asserts that an argument is legal. If the given boolean is not true, an IllegalArgumentException is thrown.

Parameters:
expression - the outcome of the check
Returns:
true if the check passes (does not return if the check fails)
Throws:
IllegalArgumentException - if the legality test failed


 

 

isLegal

public static boolean isLegal(boolean expression,
                              String message)

Asserts that an argument is legal. If the given boolean is not true, an IllegalArgumentException is thrown. The given message is included in that exception, to aid debugging.

Parameters:
expression - the outcome of the check
message - the message to include in the exception
Returns:
true if the check passes (does not return if the check fails)
Throws:
IllegalArgumentException - if the legality test failed


 

 

isNotNull

public static void isNotNull(Object object)

Asserts that the given object is not null. If this is not the case, some kind of unchecked exception is thrown.

As a general rule, parameters passed to API methods must not be null unless explicitly allowed in the method's specification. Similarly, results returned from API methods are never null unless explicitly allowed in the method's specification. Implementations are encouraged to make regular use of Assert.isNotNull to ensure that null parameters are detected as early as possible.

Parameters:
object - the value to test
Throws:
Throwable - an unspecified unchecked exception if the object is null


 

 

isNotNull

public static void isNotNull(Object object,
                             String message)

Asserts that the given object is not null. If this is not the case, some kind of unchecked exception is thrown. The given message is included in that exception, to aid debugging.

As a general rule, parameters passed to API methods must not be null unless explicitly allowed in the method's specification. Similarly, results returned from API methods are never null unless explicitly allowed in the method's specification. Implementations are encouraged to make regular use of Assert.isNotNull to ensure that null parameters are detected as early as possible.

Parameters:
object - the value to test
message - the message to include in the exception
Throws:
Throwable - an unspecified unchecked exception if the object is null


 

 

isTrue

public static boolean isTrue(boolean expression)

Asserts that the given boolean is true. If this is not the case, some kind of unchecked exception is thrown.

Parameters:
expression - the outcome of the check
Returns:
true if the check passes (does not return if the check fails)


 

 

isTrue

public static boolean isTrue(boolean expression,
                             String message)

Asserts that the given boolean is true. If this is not the case, some kind of unchecked exception is thrown. The given message is included in that exception, to aid debugging.

Parameters:
expression - the outcome of the check
message - the message to include in the exception
Returns:
true if the check passes (does not return if the check fails)


 

Overview

 
Package  Use  Tree  Deprecated  Index  Help 
Eclipse Platform
Release 3.0
 PREV CLASS   NEXT CLASS FRAMES    NO FRAMES  
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD


Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2004. All rights reserved.