org.apache.commons.mail
Class EmailUtils

java.lang.Object
  extended byorg.apache.commons.mail.EmailUtils

final class EmailUtils
extends java.lang.Object

Utility methods used by commons-email.

These methods are copied from other commons components (commons-lang) to avoid creating a dependency for such a small component.

This is a package scoped class, and should not be used directly by users.

Since:
1.0
Version:
$Id: EmailUtils.java 279313 2005-09-07 12:41:58Z henning $
Author:
jakarta-commons

Field Summary
private static java.util.Random RANDOM
           Random object used by random method.
 
Constructor Summary
private EmailUtils()
          Constructs a new EmailException with no detail message.
 
Method Summary
(package private) static boolean isEmpty(java.lang.String str)
           Checks if a String is empty ("") or null.
(package private) static boolean isNotEmpty(java.lang.String str)
           Checks if a String is not empty ("") and not null.
(package private) static void notNull(java.lang.Object object, java.lang.String message)
           Validate an argument, throwing IllegalArgumentException if the argument is null.
private static java.lang.String random(int count, int start, int end, boolean letters, boolean numbers, char[] chars, java.util.Random random)
           Creates a random string based on a variety of options, using supplied source of randomness.
(package private) static java.lang.String randomAlphabetic(int count)
           Creates a random string whose length is the number of characters specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RANDOM

private static final java.util.Random RANDOM

Random object used by random method. This has to be not local to the random method so as to not return the same value in the same millisecond.

Constructor Detail

EmailUtils

private EmailUtils()
Constructs a new EmailException with no detail message.

Method Detail

isEmpty

static boolean isEmpty(java.lang.String str)

Checks if a String is empty ("") or null.

Parameters:
str - the String to check, may be null
Returns:
true if the String is empty or null
Since:
Commons Lang v2.1, svn 240418

isNotEmpty

static boolean isNotEmpty(java.lang.String str)

Checks if a String is not empty ("") and not null.

Parameters:
str - the String to check, may be null
Returns:
true if the String is not empty and not null
Since:
Commons Lang v2.1, svn 240418

notNull

static void notNull(java.lang.Object object,
                    java.lang.String message)

Validate an argument, throwing IllegalArgumentException if the argument is null.

Parameters:
object - the object to check is not null
message - the exception message you would like to see if the object is null
Throws:
java.lang.IllegalArgumentException - if the object is null
Since:
Commons Lang v2.1, svn 201930

randomAlphabetic

static java.lang.String randomAlphabetic(int count)

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alphabetic characters.

Parameters:
count - the length of random string to create
Returns:
the random string
Since:
Commons Lang v2.1, svn 201930

random

private static java.lang.String random(int count,
                                       int start,
                                       int end,
                                       boolean letters,
                                       boolean numbers,
                                       char[] chars,
                                       java.util.Random random)

Creates a random string based on a variety of options, using supplied source of randomness.

If start and end are both 0, start and end are set to ' ' and 'z', the ASCII printable characters, will be used, unless letters and numbers are both false, in which case, start and end are set to 0 and Integer.MAX_VALUE.

If set is not null, characters between start and end are chosen.

This method accepts a user-supplied Random instance to use as a source of randomness. By seeding a single Random instance with a fixed seed and using it for each call, the same random sequence of strings can be generated repeatedly and predictably.

Parameters:
count - the length of random string to create
start - the position in set of chars to start at
end - the position in set of chars to end before
letters - only allow letters?
numbers - only allow numbers?
chars - the set of chars to choose randoms from. If null, then it will use the set of all chars.
random - a source of randomness.
Returns:
the random string
Throws:
java.lang.IllegalArgumentException - if count < 0.
Since:
Commons Lang v2.1, svn 201930