Java Assert assertAttributeNameIsLegal(final String attributeName)

Here you can find the source of assertAttributeNameIsLegal(final String attributeName)

Description

Check whether the given String represents a legal attribute name according to the SAM spec, and throw an exception if it doesn't.

License

Open Source License

Parameter

Parameter Description
attributeName name to check

Exception

Parameter Description
IllegalArgumentException if the attribute name is illegal according to the SAM spec.

Declaration

public static void assertAttributeNameIsLegal(final String attributeName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   ww w . j  a v  a 2s.  co  m*/
     * Check whether the given String represents a legal attribute name according to the SAM spec,
     * and throw an exception if it doesn't.
     *
     * Legal attribute names are two characters long, start with a letter, and end with a letter or digit.
     *
     * @param attributeName name to check
     * @throws IllegalArgumentException if the attribute name is illegal according to the SAM spec.
     */
    public static void assertAttributeNameIsLegal(final String attributeName) {
        if (attributeName == null || attributeName.length() != 2
                || !Character.isLetter(attributeName.charAt(0))
                || !Character.isLetterOrDigit(attributeName.charAt(1))) {

            throw new IllegalArgumentException(
                    "Read attribute "
                            + attributeName
                            + " invalid: attribute names must be non-null two-character Strings matching the pattern /[A-Za-z][A-Za-z0-9]/");
        }
    }
}

Related

  1. assertArgumentNotMinusInteger(String name, int value)
  2. assertArrayIndex(int arrayLength, int offset, int length)
  3. assertArrayIndexScale(final String name, int actualIndexScale, int expectedIndexScale)
  4. assertArrayType(Object array)
  5. assertAssertionsEnabled()
  6. assertBounds(final long reqOff, final long reqLen, final long allocSize)
  7. assertByThrowing(boolean condition, String errorMessage)
  8. assertCharactersNotInString(final String illegalChars, final char... chars)
  9. assertCheckStrAndQuery(String str, String query)