站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

Parameters (Utilities API) - NetBeans API Javadoc (Current Development Version)

org.openide.util 7.9.0 1

org.openide.util
Class Parameters

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

public class Parameters
extends 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

Method Summary
static void javaIdentifier(CharSequence name, CharSequence value)
          Asserts the parameter value is not null and it is a Java identifier.
static void javaIdentifierOrNull(CharSequence name, CharSequence value)
          Asserts the parameter value is either null or a Java identifier.
static void notEmpty(CharSequence name, CharSequence value)
          Asserts the parameter value is neither null nor an empty character sequence.
static void notNull(CharSequence name, Object value)
          Asserts the parameter value is not null.
static void notWhitespace(CharSequence name, 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(CharSequence name,
                           Object value)
Asserts the parameter value is not null.

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

notEmpty

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

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

notWhitespace

public static void notWhitespace(CharSequence name,
                                 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:
NullPointerException - if the parameter value is null.
IllegalArgumentException - if the parameter value does not contain at least one non-whitespace character.

javaIdentifier

public static void javaIdentifier(CharSequence name,
                                  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:
NullPointerException - if the parameter value is null.
IllegalArgumentException - if the parameter value is not a Java identifier.

javaIdentifierOrNull

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

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

org.openide.util 7.9.0 1

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.