|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sam.toolkit.Text
Repository for various low-level utilities functions. This class only has static fields or methods.
Field Summary | |
static java.lang.String |
USER_GROUP
Deprecated. |
static java.lang.String |
USER_NAME
Deprecated. |
Method Summary | |
static java.util.Vector |
addArray(java.util.Vector vector,
java.lang.Object[] additionnalElements)
Appends specified elements to the end of the vector. |
static java.lang.Object |
allocateNewArray(java.lang.Class type,
int size)
Allocates a new array of specified base type. |
static java.lang.Object |
allocateNewArray(java.lang.Object array,
int size)
Allocates a new array with the same base type as the specified array. |
static char |
bytesToChar(byte[] value)
Converts one integer to corresponding character according to the local Charset
Warning: this method is highly inefficient. |
static boolean |
compare(byte[] x,
byte[] y)
Compares two byte arrays |
static boolean |
compare(byte[] x,
byte[] y,
int yBegin)
Compares two byte arrays |
static boolean |
compare(byte[] x,
int xBegin,
byte[] y,
int yBegin)
Compares two byte arrays |
static boolean |
compare(byte[] x,
int xBegin,
byte[] y,
int yBegin,
int yLength)
Compares two byte arrays |
static boolean |
compare(byte[] x,
int xBegin,
int xLength,
byte[] y,
int yBegin,
int yLength)
Compares two byte arrays |
static boolean |
contains(java.lang.Object[] array,
java.lang.Object object)
Wether specified array contains specified object. |
static int |
countCharacter(java.lang.String s,
char c)
Incredibly enough this is not part of the standard API ... |
static int |
countLines(java.lang.String text)
Counts the number of lines of a text. |
static java.lang.Object[] |
dropNulls(java.lang.Object[] array)
Drops the null elements of an array |
static java.util.Enumeration |
enumerate(java.lang.Object[] array)
Enumerates elements of an array. |
static java.lang.String |
firstWord(java.lang.String pairOfWords,
char delimiter)
Gets the first word of a two-word string |
static long |
fromHexa(java.lang.String s)
Recovers an int integral number from its hexadecimal representation |
static int[] |
fromStrings(java.lang.String[] strings)
Turns an array of integers to the array of their String representation |
static java.lang.String |
getDate()
Deprecated. |
static java.lang.String |
getDate(long date)
Deprecated. |
static java.lang.String |
getDateTime(long date)
Deprecated. |
static java.lang.String |
getDuration(long duration)
Deprecated. |
static java.lang.Object[] |
getKeys(java.util.Map map,
java.lang.Object[] runtimeType)
Gets a snapshot of the valid key set of a given Map . |
static java.lang.String[] |
getKeyStrings(java.util.Map map)
Gets a snapshot of the valid key set of a given Map . |
static java.lang.String |
getLastClassName(java.lang.Class clazz)
Gets the Java class name without its package qualification. |
static java.lang.String |
getMessage(java.lang.Throwable t)
|
static java.lang.String |
getOneDecimalString(double ratio)
Gets the representation of ratio with a one-decimal-digit precision. |
static java.lang.String |
getOneDecimalString(long value,
long divisor)
Gets the representation of value / divisor with a one-decimal-digit precision. |
static int |
getPercent(int done,
int total,
boolean direction)
Deprecated. |
static int |
getPercent(long done,
long total,
boolean direction)
Deprecated. |
static int |
getPercentage(long achieved,
long limit)
Gets the percentage corresponding to specified ratio. |
static java.lang.String |
getSizeString(long bytes)
Gets a human-readable String representation of a size. |
static java.lang.String |
getTime()
Deprecated. |
static java.lang.String |
getTime(long date)
Deprecated. |
static char |
intToChar(int value)
Converts one integer to corresponding character according to the local Charset
Warning: this method is highly inefficient. |
static java.lang.String |
left(java.lang.String text,
int length)
Shrinks or expands specified text do desired length |
static java.lang.String[] |
merge(java.lang.String[][] stringArrays)
|
static int |
parseInteger(java.lang.String value)
Parses an integer, or returns zero if incorrectly formatted |
static int |
parseInteger(java.lang.String value,
int defaultValue)
Parses an integer, or returns defaultValue if incorrectly formatted |
static java.lang.String |
replace(java.lang.String text,
java.lang.String pattern,
java.lang.String alternative)
Replaces all occurences of a pattern in a text |
static java.lang.String |
right(java.lang.String text,
int length)
Shrinks or expands specified text do desired length |
static java.lang.String |
secondWord(java.lang.String pairOfWords,
char delimiter)
Gets the second word of a two-word string |
static java.lang.String[] |
split(java.lang.String text,
java.lang.String split)
Splits a String accross specified delimiters |
static java.lang.String[] |
splitLines(java.lang.String text)
Splits a String accross carriage-return delimiters |
static java.lang.Object |
subArray(java.lang.Object array,
int begin,
int length)
Gets a sub-array of an array. |
static java.lang.String |
summarize(java.lang.String text,
int length)
Shortens a String by cutting it on the right |
static java.lang.String |
summarize(java.lang.String text,
int length,
boolean cutOnTheRight)
|
static java.lang.String |
toHexa(int n)
Converts an int integral number to its hexadecimal representation, without trailing zeros |
static java.lang.String |
toHexa(long n)
Converts a long integral number to its hexadecimal representation, without trailing zeros |
static java.lang.String |
toString(java.lang.Object[] array)
Gets the String representation of an array. |
static java.lang.String |
toString(java.lang.Object[] array,
java.lang.String delimiter)
Gets the String representation of an array. |
static java.lang.String |
toString(java.lang.Object[] array,
java.lang.String prefix,
java.lang.String delimiter,
java.lang.String postfix)
Gets the String representation of an array. |
static java.lang.String[] |
toStringArray(java.util.Vector vector)
Turns a vector supposedly containing String s only to a String[] array. |
static java.lang.String[] |
toStrings(int[] array)
Turns an array of integers to the array of their String representation |
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 USER_NAME
public static final java.lang.String USER_GROUP
Method Detail |
public static int countCharacter(java.lang.String s, char c)
public static java.lang.Object[] dropNulls(java.lang.Object[] array)
null
elements of an array
null
if passed array is itself null
Note that the runtime type of the returned array is that of passed arraypublic static java.lang.Object allocateNewArray(java.lang.Object array, int size)
null
if passed type is itself null
or if instantiation failspublic static java.lang.Object allocateNewArray(java.lang.Class type, int size)
null
if passed type is itself null
or if instantiation failspublic static java.lang.Object subArray(java.lang.Object array, int begin, int length)
array
- the source arraybegin
- the beginning of the sub-arraylength
- the sub-array length
public static java.lang.String firstWord(java.lang.String pairOfWords, char delimiter)
public static java.lang.String secondWord(java.lang.String pairOfWords, char delimiter)
public static java.lang.String[] splitLines(java.lang.String text)
String
accross carriage-return delimiters
public static java.lang.String[] split(java.lang.String text, java.lang.String split)
String
accross specified delimiters
public static java.lang.String[] merge(java.lang.String[][] stringArrays)
public static java.lang.Object[] getKeys(java.util.Map map, java.lang.Object[] runtimeType)
Map
.
map
- the mapruntimeType
- an array of same runtime array type as the one desired, e.g. new String[0]
public static java.lang.String[] getKeyStrings(java.util.Map map)
Map
.
map
- the map containing only String
instances or null
s.public static char intToChar(int value)
Charset
Warning: this method is highly inefficient.
Moreover, it is intrinsequently buggy since some charsets require char
be encoded
onto several byte
s
public static char bytesToChar(byte[] value)
Charset
Warning: this method is highly inefficient.
public static java.lang.String[] toStringArray(java.util.Vector vector)
String
s only to a String[]
array.
java.lang.ClassCastException
- if the vector does not contain only String
instancespublic static java.util.Vector addArray(java.util.Vector vector, java.lang.Object[] additionnalElements)
null
and additionnalElements
was not.public static boolean compare(byte[] x, byte[] y)
byte
arrays
x
- the first byte[]
arrayy
- the second byte[]
array
true
iff both arrays are null
or if both regions matchpublic static boolean compare(byte[] x, byte[] y, int yBegin)
byte
arrays
x
- the first byte[]
arrayy
- the second byte[]
arrayyBegin
- the beginning of the second array region
true
iff both arrays are null
or if both regions matchpublic static boolean compare(byte[] x, int xBegin, byte[] y, int yBegin)
byte
arrays
x
- the first byte[]
arrayxBegin
- the beginning of the first array regiony
- the second byte[]
arrayyBegin
- the beginning of the second array region
true
iff both arrays are null
or if both regions matchpublic static boolean compare(byte[] x, int xBegin, byte[] y, int yBegin, int yLength)
byte
arrays
x
- the first byte[]
arrayxBegin
- the beginning of the first array regiony
- the second byte[]
arrayyBegin
- the beginning of the second array regionyLength
- the length of the second array region
true
iff both arrays are null
or if both regions matchpublic static boolean compare(byte[] x, int xBegin, int xLength, byte[] y, int yBegin, int yLength)
byte
arrays
x
- the first byte[]
arrayxBegin
- the beginning of the first array regionxLength
- the length of the first array regiony
- the second byte[]
arrayyBegin
- the beginning of the second array regionyLength
- the length of the second array region
true
iff both arrays are null
or if both regions matchpublic static java.util.Enumeration enumerate(java.lang.Object[] array)
Incredibly enough this is not part of the standard API.
public static int parseInteger(java.lang.String value)
public static int parseInteger(java.lang.String value, int defaultValue)
defaultValue
if incorrectly formatted
public static java.lang.String toHexa(long n)
long
integral number to its hexadecimal representation, without trailing zeros
public static java.lang.String toHexa(int n)
int
integral number to its hexadecimal representation, without trailing zeros
public static long fromHexa(java.lang.String s)
int
integral number from its hexadecimal representation
public static java.lang.String summarize(java.lang.String text, int length)
String
by cutting it on the right
text
- the text to be shortenedlength
- the desired lengthpublic static java.lang.String summarize(java.lang.String text, int length, boolean cutOnTheRight)
public static java.lang.String left(java.lang.String text, int length)
text
- the text to be modifiedlength
- the new desired length
If text
is null
of too small, spaces are appended at the end.
If >text
is too long then leading characters ar dropped.public static java.lang.String right(java.lang.String text, int length)
text
- the text to be modifiedlength
- the new desired length
If text
is null
of too small, spaces are appended at the beginning.
If >text
is too long then leading characters ar dropped.public static int countLines(java.lang.String text)
text
- the desired text
public static java.lang.String getMessage(java.lang.Throwable t)
public static java.lang.String getLastClassName(java.lang.Class clazz)
Java
class name without its package qualification.
This is consistent with non-anonymous inner classes as long as they are named with '$'
as a separator.
public static java.lang.String toString(java.lang.Object[] array)
String
representation of an array.
It is incredible that this does not exist in the standard jre
...
public static java.lang.String toString(java.lang.Object[] array, java.lang.String delimiter)
String
representation of an array.
It is incredible that this does not exist in the standard jre
...
delimiter
- the delimiter printed between each pair of elements of the array,
e.g. ", "
public static java.lang.String toString(java.lang.Object[] array, java.lang.String prefix, java.lang.String delimiter, java.lang.String postfix)
String
representation of an array.
It is incredible that this does not exist in the standard jre
...
delimiter
- the delimiter printed between each pair of elements of the array,
e.g. ", "
prefix
- the prefix first printed, e.g. "["
postfix
- the postfix printed at last, e.g. "]"
public static java.lang.String[] toStrings(int[] array)
String
representation
null
if array
is null
public static int[] fromStrings(java.lang.String[] strings)
String
representation
null
if array
is null
, or in case of
invalid number formatpublic static boolean contains(java.lang.Object[] array, java.lang.Object object)
jre
...
public static java.lang.String replace(java.lang.String text, java.lang.String pattern, java.lang.String alternative)
text
- the text to be replaced inpattern
- the pattern to be replacedalternative
- the desired substitution to pattern
public static java.lang.String getSizeString(long bytes)
String
representation of a size.
This is basically what a du -h
would do to du
Note that the multiplicator is 1024
for "kilo" and
1048576
for "mega"
public static java.lang.String getOneDecimalString(double ratio)
ratio
with a one-decimal-digit precision.
public static java.lang.String getOneDecimalString(long value, long divisor)
value / divisor
with a one-decimal-digit precision.
public static int getPercentage(long achieved, long limit)
achieved
- the numerator supposedly non-negativelimit
- the divisor supposedly non-negative
public static int getPercent(int done, int total, boolean direction)
public static int getPercent(long done, long total, boolean direction)
public static java.lang.String getDateTime(long date)
public static java.lang.String getDate()
public static java.lang.String getDate(long date)
public static java.lang.String getTime()
public static java.lang.String getTime(long date)
public static java.lang.String getDuration(long duration)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |