Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2010-2011. Axon Framework
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.axonframework.util;

Utility class (inspired by Springs Assert class) for doing assertions on parameters and object state. To remove the need for explicit dependencies on Spring, the functionality of that class is migrated to this class.

Author(s):
Allard Buijze
Since:
0.3
public abstract class Assert {
    private Assert() {
        // utility class
    }

    
Asserts that the value of state is true. If not, an IllegalStateException is thrown.

Parameters:
state the state validation expression
message The message that the excetion contains if state evaluates to false
    public static void state(boolean stateString message) {
        if (!state) {
            throw new IllegalStateException(message);
        }
    }

    
Asserts that the given expression is true. If not, an IllegalArgumentException is thrown.

Parameters:
expression the state validation expression
message The message that the exception contains if state evaluates to false
    public static void isTrue(boolean expressionString message) {
        if (!expression) {
            throw new IllegalArgumentException(message);
        }
    }

    
Asserts that the given expression is false. If not, an IllegalArgumentException is thrown.

Parameters:
expression the state validation expression
message The message that the exception contains if state evaluates to true
    public static void isFalse(boolean expressionString message) {
        if (expression) {
            throw new IllegalArgumentException(message);
        }
    }

    
Assert that the given value is not null. If not, an IllegalArgumentException is thrown.

Parameters:
value the value not to be null
message The message to add to the exception when the assertion fails
    public static void notNull(Object valueString message) {
        isTrue(value != nullmessage);
    }
New to GrepCode? Check out our FAQ X