net.sf.freecol.common.util
Class Utils

java.lang.Object
  extended by net.sf.freecol.common.util.Utils

public class Utils
extends java.lang.Object

Collection of small static helper methods.


Constructor Summary
Utils()
           
 
Method Summary
static boolean equals(java.lang.Object one, java.lang.Object two)
          Will check if both objects are equal but also checks for null.
static
<T> T
getRandomMember(java.util.logging.Logger logger, java.lang.String logMe, java.util.List<T> list, java.util.Random random)
          Gets a random member of a list.
static java.lang.String getUserDirectory()
          Generalize this method instead of calling it directly elsewhere.
static java.lang.String join(java.lang.String delimiter, java.util.List<java.lang.String> strings)
          Joins the given strings.
static java.lang.String join(java.lang.String delimiter, java.lang.String... strings)
          Joins the given strings.
static double randomDouble(java.util.logging.Logger logger, java.lang.String logMe, java.util.Random random)
          Convenience to aid logging uses of Randoms.
static int randomInt(java.util.logging.Logger logger, java.lang.String logMe, java.util.Random random, int n)
          Convenience to aid logging uses of Randoms.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

join

public static java.lang.String join(java.lang.String delimiter,
                                    java.lang.String... strings)
Joins the given strings.

Parameters:
delimiter - The delimiter to place between the individual strings.
strings - The strings to be joined.
Returns:
Each of the strings in the given array delimited by the given string.

join

public static java.lang.String join(java.lang.String delimiter,
                                    java.util.List<java.lang.String> strings)
Joins the given strings.

Parameters:
delimiter - The delimiter to place between the individual strings.
strings - The strings to be joined.
Returns:
Each of the strings in the given array delimited by the given string.

equals

public static boolean equals(java.lang.Object one,
                             java.lang.Object two)
Will check if both objects are equal but also checks for null.

Parameters:
one - First object to compare
two - Second object to compare
Returns:
(one == null && two != null) || (one != null && one.equals(two))

getUserDirectory

public static java.lang.String getUserDirectory()
Generalize this method instead of calling it directly elsewhere.

Returns:
String

randomInt

public static int randomInt(java.util.logging.Logger logger,
                            java.lang.String logMe,
                            java.util.Random random,
                            int n)
Convenience to aid logging uses of Randoms.

Parameters:
logger - The Logger to log to.
logMe - A string to log with the result.
random - A pseudo-Random number source.
n - The exclusive maximum integer to return.
Returns:
A pseudo-random integer r, 0 <= r < n.

randomDouble

public static double randomDouble(java.util.logging.Logger logger,
                                  java.lang.String logMe,
                                  java.util.Random random)
Convenience to aid logging uses of Randoms.

Parameters:
logger - The Logger to log to.
logMe - A string to log with the result.
random - A pseudo-Random number source.
Returns:
A pseudo-random double r, 0 <= r < 1.0.

getRandomMember

public static <T> T getRandomMember(java.util.logging.Logger logger,
                                    java.lang.String logMe,
                                    java.util.List<T> list,
                                    java.util.Random random)
Gets a random member of a list.

Parameters:
logger - The Logger to log to.
logMe - A string to log with the result.
list - The list.
random - A random number source.
Returns:
A random member from the list.