|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectvoldemort.utils.Utils
public class Utils
Helper functions FTW!
| Nested Class Summary | |
|---|---|
static interface |
Utils.Posix
|
| Field Summary | |
|---|---|
static java.util.regex.Pattern |
COMMA_SEP
Pattern for splitting a string based on commas |
static java.lang.String |
NEWLINE
|
| Constructor Summary | |
|---|---|
Utils()
|
|
| Method Summary | ||
|---|---|---|
static void |
assertNotNull(java.lang.Object... objects)
Throw an IllegalArgumentException if any of the given objects are null |
|
static void |
assertNotNull(java.lang.String s,
java.lang.Object... objects)
Throw an IllegalArgumentException if any of the given objects are null |
|
static
|
compareList(java.util.List<T> listA,
java.util.List<T> listB)
Compares two lists |
|
static void |
croak(java.lang.String message)
Print an error and exit with error code 1 |
|
static void |
croak(java.lang.String message,
int errorCode)
Print an error and exit with the given error code |
|
static boolean |
deepEquals(java.lang.Object o1,
java.lang.Object o2)
Determines if two objects are equal as determined by Object.equals(Object), or "deeply equal" if both are arrays. |
|
static int |
deepHashCode(java.lang.Object o)
Gets hash code of an object, optionally returns hash code based on the "deep contents" of array if the object is an array. |
|
static
|
getAddedInTarget(java.util.Set<T> current,
java.util.Set<T> target)
Returns a set of objects that were added to the target list getAddedInTarget(current, null) - nothing was added, returns null. |
|
static java.util.GregorianCalendar |
getCalendarForNextRun(java.util.GregorianCalendar startTime,
int targetDay,
int targetHour)
Given a start time, computes the next time when the wallclock will reach a certain hour of the day, on a certain day of the week Eg: From today, when is the next Saturday, 12PM ? |
|
static int |
getDayOfTheWeekFromNow(int nDays)
Returns the day of week, 'nDays' from today |
|
static
|
getDeletedInTarget(java.util.Set<T> current,
java.util.Set<T> target)
Returns a set of objects that were deleted in the target set getDeletedInTarget(current, null) - everything was deleted, returns current. |
|
static int |
inRange(int value,
int min,
int max)
Return the value v if min <= v <= max, otherwise throw an exception |
|
static boolean |
isReadableDir(java.io.File d)
|
|
static boolean |
isReadableDir(java.lang.String dirName)
|
|
static boolean |
isReadableFile(java.io.File f)
|
|
static boolean |
isReadableFile(java.lang.String fileName)
|
|
static boolean |
isSymLink(java.io.File symlinkFile)
Check if a file is a symbolic link or not |
|
static void |
mkdirs(java.io.File newDir)
Make the directory specified in the parameters. |
|
static void |
move(java.io.File source,
java.io.File dest)
Move the source file to the dest file name. |
|
static
|
notNull(T t)
Throw an IllegalArgumentException if the argument is null, otherwise just return the argument. |
|
static
|
notNull(T t,
java.lang.String message)
Throw an IllegalArgumentException if the argument is null, otherwise just return the argument. |
|
static java.net.URI |
parseUri(java.lang.String uri)
A helper function that wraps the checked parsing exception when creating a URI |
|
static
|
reversed(java.util.List<T> l)
A reversed copy of the given list |
|
static void |
rm(java.io.File file)
Delete the given file |
|
static void |
rm(java.io.File[] files)
Delete an array of files |
|
static void |
rm(java.lang.Iterable<java.io.File> files)
Delete all the given files |
|
static void |
rm(java.lang.String file)
Delete the given file |
|
static
|
sorted(java.util.List<T> l)
Return a copy of the list sorted according to the natural order |
|
static
|
sorted(java.util.List<T> l,
java.util.Comparator<T> comparator)
Return a copy of the list sorted according to the given comparator |
|
static void |
symlink(java.lang.String filePath,
java.lang.String symLinkPath)
Create a symbolic link to an existing file. |
|
static
|
uncheckedCast(T2 t2)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String NEWLINE
public static final java.util.regex.Pattern COMMA_SEP
| Constructor Detail |
|---|
public Utils()
| Method Detail |
|---|
public static void croak(java.lang.String message)
message - The error to print
public static void croak(java.lang.String message,
int errorCode)
message - The error to printerrorCode - The error code to exit withpublic static void rm(java.io.File file)
file - The file to deletepublic static void rm(java.io.File[] files)
files - Files to deletepublic static void rm(java.lang.String file)
file - The file to deletepublic static void rm(java.lang.Iterable<java.io.File> files)
files - A collection of files to delete
public static void symlink(java.lang.String filePath,
java.lang.String symLinkPath)
filePath - Path of the file for whom to create the symbolic linksymLinkPath - Path of the symbolic link
public static void move(java.io.File source,
java.io.File dest)
source - The file to copy fromdest - The file to copy topublic static void mkdirs(java.io.File newDir)
newDir - The directory we want to makepublic static boolean isReadableFile(java.lang.String fileName)
public static boolean isReadableFile(java.io.File f)
public static boolean isReadableDir(java.lang.String dirName)
public static boolean isReadableDir(java.io.File d)
public static void assertNotNull(java.lang.Object... objects)
objects - The objects to test
public static void assertNotNull(java.lang.String s,
java.lang.Object... objects)
s - The error message to giveobjects - The objects to test
public static <T> T notNull(T t,
java.lang.String message)
T - The type of the thingt - The thing to check for nullness.message - The message to put in the exception if it is nullpublic static <T> T notNull(T t)
T - The type of the thingt - The thing to check for nullness.
public static int inRange(int value,
int min,
int max)
value - The value to checkmin - The minimum allowable valuemax - The maximum allowable value
public static int deepHashCode(java.lang.Object o)
If o is null, 0 is returned; if o is an array, the
corresponding Arrays.deepHashCode(Object[]), or
Arrays.hashCode(int[]) or the like is used to calculate the hash
code.
public static boolean deepEquals(java.lang.Object o1,
java.lang.Object o2)
Object.equals(Object), or "deeply equal" if both are arrays.
If both objects are null, true is returned; if both objects are array,
the corresponding Arrays.deepEquals(Object[], Object[]), or
Arrays.equals(int[], int[]) or the like are called to determine
equality.
Note that this method does not "deeply" compare the fields of the objects.
public static <T> java.util.Set<T> getAddedInTarget(java.util.Set<T> current,
java.util.Set<T> target)
current - Set of objects present in currenttarget - Set of partitions present in target
public static <T> java.util.Set<T> getDeletedInTarget(java.util.Set<T> current,
java.util.Set<T> target)
current - Set of objects currently presenttarget - Set of target objects
public static <T> java.util.List<T> sorted(java.util.List<T> l,
java.util.Comparator<T> comparator)
T - The type of the elements in the listl - The list to sortcomparator - The comparator to use for sorting
public static <T extends java.lang.Comparable<T>> java.util.List<T> sorted(java.util.List<T> l)
T - The type of the elements in the listl - The list to sort
public static <T> java.util.List<T> reversed(java.util.List<T> l)
T - The type of the items in the listl - The list to reverse
public static <T> boolean compareList(java.util.List<T> listA,
java.util.List<T> listB)
T - The type of items in the listlistA - List 1listB - List 2
public static java.net.URI parseUri(java.lang.String uri)
uri - The URI to parse
public static <T1,T2> T1 uncheckedCast(T2 t2)
public static boolean isSymLink(java.io.File symlinkFile)
symlinkFile -
public static java.util.GregorianCalendar getCalendarForNextRun(java.util.GregorianCalendar startTime,
int targetDay,
int targetHour)
startTime - start timetargetDay - day of the week to choosetargetHour - hour of the day to choose
public static int getDayOfTheWeekFromNow(int nDays)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||