org.openide.util
Class Parameters

java.lang.Object
  extended by org.openide.util.Parameters

public class Parameters
extends java.lang.Object

Utilities for checking the values of method parameters. Methods in this class generally take the name of the parameter to check and its value and throw exceptions with messages according to the method name or just return. For example, if you have a myMethod() method taking a myParam parameter whose value must be a Java identifier, you usually check that by doing:

 public void myMethod(String myParam) {
     if (!Utilities.isJavaIdentifier(myParam)) {
         throw new IllegalArgumentException("The myParam parameter is not a valid Java identifier");
     }
 }
 
Using this class you can do the same in a simpler way:
 public void myMethod(String myParam) {
     Parameters.javaIdentifier("myParam", myParam);
 }
 

Since:
org.openide.util 7.6
Author:
Andrei Badea

Method Summary
static void javaIdentifier(java.lang.CharSequence name, java.lang.CharSequence value)
          Asserts the parameter value is not null and it is a Java identifier.
static void javaIdentifierOrNull(java.lang.CharSequence name, java.lang.CharSequence value)
          Asserts the parameter value is either null or a Java identifier.
static void notEmpty(java.lang.CharSequence name, java.lang.CharSequence value)
          Asserts the parameter value is neither null nor an empty character sequence.
static void notNull(java.lang.CharSequence name, java.lang.Object value)
          Asserts the parameter value is not null.
static void notWhitespace(java.lang.CharSequence name, java.lang.CharSequence value)
          Asserts the parameter value is not null and it contains at least one non-whitespace character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

notNull

public static void notNull(java.lang.CharSequence name,
                           java.lang.Object value)
Asserts the parameter value is not null.

Parameters:
name - the parameter name.
value - the parameter value.
Throws:
java.lang.NullPointerException - if the parameter value is null.

notEmpty

public static void notEmpty(java.lang.CharSequence name,
                            java.lang.CharSequence value)
Asserts the parameter value is neither null nor an empty character sequence.

Parameters:
name - the parameter name.
value - the parameter value.
Throws:
java.lang.NullPointerException - if the parameter value is null.
java.lang.IllegalArgumentException - if the parameter value is an empty character sequence.

notWhitespace

public static void notWhitespace(java.lang.CharSequence name,
                                 java.lang.CharSequence value)
Asserts the parameter value is not null and it contains at least one non-whitespace character. Whitespace is defined as by String.trim().

Parameters:
name - the parameter name.
value - the parameter value.
Throws:
java.lang.NullPointerException - if the parameter value is null.
java.lang.IllegalArgumentException - if the parameter value does not contain at least one non-whitespace character.

javaIdentifier

public static void javaIdentifier(java.lang.CharSequence name,
                                  java.lang.CharSequence value)
Asserts the parameter value is not null and it is a Java identifier.

Parameters:
name - the parameter name.
value - the parameter value.
Throws:
java.lang.NullPointerException - if the parameter value is null.
java.lang.IllegalArgumentException - if the parameter value is not a Java identifier.

javaIdentifierOrNull

public static void javaIdentifierOrNull(java.lang.CharSequence name,
                                        java.lang.CharSequence value)
Asserts the parameter value is either null or a Java identifier.

Parameters:
name - the parameter name.
value - the parameter value.
Throws:
java.lang.IllegalArgumentException - if the parameter value is neither null nor a Java identifier.