public class Util extends Object implements EuclidConstants
| Modifier and Type | Class and Description |
|---|---|
static class |
Util.Message
messages
|
| Modifier and Type | Field and Description |
|---|---|
static String |
DATE_REGEX1
date of form 21-jan-1965.
|
static String |
DATE_REGEX2
date of form 1965-01-25.
|
static String[] |
GREEK_ENTITIES
greek entities
|
static Map<String,Character> |
GREEK2CHARACTER_MAP |
static String[] |
ISOLATIN_ENTITIES
isolatin entities
|
static int |
ISOLATIN_HI |
static int |
ISOLATIN_LO |
static String[] |
LOWER_ROMAN_NUMERAL |
static String |
LOWER_ROMAN_REGEX
regex matching roman numbers up to m ("[ivxlcdm]+").
|
static String[] |
months
month data .
|
static String[] |
UPPER_GREEK_ENTITIES
UPPER_GREEK entities
|
static String |
UPPER_ROMAN_REGEX
regex matching roman numbers up to M ("[IVXLCDM]+").
|
C_AMP, C_APOS, C_ATSIGN, C_BACKSLASH, C_BACKSPACE, C_CARET, C_COLON, C_COMMA, C_DEL, C_DOLLAR, C_EQUALS, C_FORMFEED, C_HASH, C_LANGLE, C_LBRAK, C_LCURLY, C_LSQUARE, C_MINUS, C_NBSP, C_NEWLINE, C_NL, C_PERCENT, C_PERIOD, C_PIPE, C_PLUS, C_POUND, C_QUERY, C_QUOT, C_RANGLE, C_RBRAK, C_RCURLY, C_RETURN, C_RSQUARE, C_SEMICOLON, C_SHRIEK, C_SLASH, C_SPACE, C_STAR, C_TAB, C_TILDE, C_UNDER, EPS, F_S, NONWHITEPUNC, NONWHITEPUNC0, NONWHITEPUNC0REGEX, ONE_THIRD, PUNC, S_AMP, S_APOS, S_ATSIGN, S_BACKSLASH, S_CARET, S_COLON, S_COMMA, S_DOLLAR, S_EMPTY, S_EQUALS, S_FORMFEED, S_HASH, S_LANGLE, S_LBRAK, S_LCURLY, S_LSQUARE, S_MINUS, S_NEWLINE, S_NL, S_PERCENT, S_PERIOD, S_PIPE, S_PLUS, S_POUND, S_QUERY, S_QUOT, S_RANGLE, S_RBRAK, S_RCURLY, S_RETURN, S_RSQUARE, S_SEMICOLON, S_SHRIEK, S_SLASH, S_SPACE, S_STAR, S_TAB, S_TILDE, S_UNDER, S_WHITEREGEX, TWO_THIRDS, U_S, WHITESPACE| Constructor and Description |
|---|
Util() |
| Modifier and Type | Method and Description |
|---|---|
static String[] |
addElementToStringArray(String[] array,
String s)
convenience method to extend array of Strings.
|
static void |
BUG(Exception e)
traps a bug.
|
static void |
BUG(String msg)
traps a bug.
|
static void |
BUG(String msg,
Exception e)
traps a bug.
|
static void |
BUG(String msg,
Throwable t)
traps a bug.
|
static void |
BUG(Throwable t)
traps a bug.
|
static String |
buildPath(String... parts)
gets build path from its components.
|
static String |
calculateMD5(String s)
borrowed from somewhere.
|
static String |
capitalise(String s)
capitalise a String (whatever the starting case)
|
static void |
check(double[] array,
int size)
checks array is not null and is of given size.
|
static void |
check(int n,
int low,
int high)
checks that an in is in the range low to high.
|
static boolean |
checkPMR()
checks that this is local to PMR.
|
static String |
concatenate(boolean[] bb,
String separator)
concatenates array of booleans.
|
static String |
concatenate(double[][] ss,
String separator)
concatenates array of array of doubles.
|
static String |
concatenate(double[] ss,
String separator)
concatenates array of doubles.
|
static String |
concatenate(int[] ss,
String separator)
concatenates array of ints.
|
static String |
concatenate(String[] ss,
String separator)
concatenates array of Strings.
|
static boolean |
containsString(String[] strings,
String s)
does an array of Strings contain a String.
|
static char[] |
convertLatin1ToUTF8(char a)
convert single IsoLatin1 character to 2 UTF8 characters .
|
static char |
convertUTF8ToLatin1(char a,
char b)
convert 2 UTF8 characters to single IsoLatin1 character.
|
static void |
copyFile(File inFile,
File outFile)
copy one file to another (I suspect there is a better way
|
static String |
createCommaSeparatedStrings(List<String> v)
create comma-separated Strings fields include a comma or a " they are
wrapped with quotes (").
|
static void |
createFile(File dir,
String filename)
creates directories and files if they don't exist.
|
static List<String> |
createList(String[] ss)
translate array of Strings to a List.
|
static File |
createNewFile(String fileName)
create new file, including making directory if required This seems to be
a mess - f.createNewFile() doesn't seem to work A directory should have a
trailing file.separator
|
static boolean |
deleteFile(File file,
boolean deleteDirectory)
delete a file If directory==true then file will be recursively deleted
|
static String |
deQuote(String s)
remove balanced quotes from ends of (trimmed) string, else no action
|
static String |
dump(URL url)
reads a stream from url and outputs it as integer values of the
characters and as strings.
|
static void |
error(String s)
Error message - nothing fancy at present.
|
static double |
format(double d,
int ndec)
format trailing decimals
|
static String |
getCanonicalDate(String s)
parse string as date.
|
static String |
getCanonicalPath(File file)
avoids the checked exception
|
static List<String> |
getCommaSeparatedStrings(String s)
parse comma-separated Strings Note fields can be EC.S_EMPTY (as in ,,,) and
fields can be quoted "...".
|
static double |
getDouble(String s) |
static FileOutputStream |
getFileOutputStream(String fileName)
get an OutputStream from a file or URL.
|
static InputStream |
getInputStreamFromResource(String filename)
convenience method to get input stream from resource.
|
static int |
getIntFromHex(String hex)
Translates a Hex number to its int equivalent.
|
static int |
getPrime(int i)
get i'th prime.
|
static String |
getPWDName()
get current directory
|
static String |
getRelativeFilename(File file1,
File file2,
String newSeparator)
path to create file2 from file1
|
static String |
getRelativePath(String targetPath,
String basePath,
String pathSeparator)
Get the relative path from one file to another, specifying the directory separator.
|
static URL |
getResource(String filename)
creates resource from filename.
|
static File |
getResourceFile(String... path)
gets file from build path components.
|
static InputStream |
getResourceUsingContextClassLoader(String name,
Class<?> clazz) |
static byte[] |
getRESTQuery(String serviceUrl,
String urlString,
String mediaType) |
static List<String> |
getRESTQueryAsLines(String s,
String u,
String mediaType) |
static String |
getSuffix(String filename)
gets suffix from filename
|
static File |
getTEMP_DIRECTORY()
get temporary directory - mainly for testing methods with outputs.
|
static File |
getTestOutputDirectory(Class<?> classx)
get class-specific temporary directory - mainly for testing methods with
ouputs.
|
static int |
indexOf(String string,
String[] strings,
boolean ignoreCase)
get the index of a String in an array
|
static int |
indexOfBalancedBracket(char lbrack,
String s)
return index of balanced bracket.
|
static Hashtable<Object,Object> |
invert(Hashtable<Object,Object> table)
invert a Hashtable by interchanging keys and values.
|
static boolean |
isEqual(double[] a,
double[] b,
double eps)
compare two arrays of doubles.
|
static boolean |
isEqual(int[] a,
int[] b,
int eps)
compare two arrays of ints.
|
static boolean |
isFloat(String s)
parse string as float.
|
static boolean |
isFloatArray(String s,
String delimiterRegex)
parse string as realArray.
|
static boolean |
isInt(String s)
parse string as integer.
|
static boolean |
isIntArray(String s,
String delimiterRegex)
parse string as integerArray.
|
static String |
leftTrim(String s)
remove leading blanks
|
static void |
message(String s)
message - nothing fancy at present
|
static String |
normaliseWhitespace(String s)
normalise whitespace in a String (all whitespace is transformed to single
spaces and the string is NOT trimmed
|
static String |
outputFloat(int nPlaces,
int nDec,
double value)
format for example f8.3 this is a mess; if cannot fit, then either
right-truncates or when that doesn't work, returns ****
|
static String |
outputNumber(int nPlaces,
int nDec,
double c)
as above, but trims trailing zeros
|
static double |
parseFlexibleDouble(String value)
Parses double, taking account of lexical forms of special cases allowed
by the XSD spec: INF, -INF and NaN.
|
static void |
print(String s)
outputs to sysout.
|
static void |
println()
outputs to sysout.
|
static void |
println(String s)
outputs to sysout.
|
static String |
quoteConcatenate(String[] s)
concatenate strings into quote-separated string
|
static byte[] |
readByteArray(DataInputStream d)
reads a byte array from DataInputStream, *including* line feeds
|
static byte[] |
readByteArray(String filename)
reads a byte array from file, *including* line feeds
|
static String[] |
removeElementFromStringArray(String[] array,
String s)
convenience method to remove element from array of Strings.
|
static String |
removeHTML(String s)
remove balanced (well-formed) markup from a string.
|
static String |
replaceISOControlsByMnemonic(String s)
remove all control (non-printing) characters
|
static String |
replaceNumericEntityByGreekMnemonics(String s,
String ent) |
static String |
replaceNumericEntityByISOLatinString(String s,
String ent) |
static String |
replaceTabs(String s,
int width)
replace tabs with spaces while trying to preserve the formatting
|
static String |
rightTrim(String s)
remove trailing blanks
|
static void |
sortByEmbeddedInteger(List<?> list)
sorts a list of string on integers within them.
|
static String |
spaces(int nspace)
make a String of a given number of spaces
|
static double[] |
splitToDoubleArray(String s)
splits string into doubles.
|
static double[] |
splitToDoubleArray(String s,
String delim)
splits string into doubles.
|
static int[] |
splitToIntArray(String s,
String delim)
splits string into ints.
|
static String |
stripISOControls(String s)
remove all control (non-printing) characters
|
static byte[] |
stripNewlines(byte[] b)
strip linefeeds from a byte array
|
static String |
substituteDOSbyAscii(String s)
substitute certain DOS-compatible diacriticals by the Unicode value.
|
static String |
substituteEquals(String s)
substitute hex representation of character, for example =2E by char(46).
|
static String |
substituteNonASCIIChars(String s,
char replacement) |
static String |
substituteSmartCharacters(String s) |
static String |
substituteString(String s,
String oldSubstring,
String newSubstring,
int count)
make substitutions in a string.
|
static String |
substituteStrings(String s,
String[] oldSubstrings,
String[] newSubstrings)
make substitutions in a string.
|
static void |
throwNYI()
Deprecated.
|
static String |
toCamelCase(String s)
Description of the Method
|
static String |
translateToMnemonic(char ch)
translate non-printing character to ISO mnemonic.
|
static String |
trim(double d)
trim trailing zeroes and trailing decimal point.
|
static double |
trimFloat(double dd,
int ndec)
rounds to decimal place.
|
static String |
truncateAndAddEllipsis(String s,
int maxlength)
return the first n characters of a string and add ellipses if truncated
|
static String |
truncateAndAddNewlinesAndEllipsis(String s,
int maxlength)
return the first n characters of a string and add ellipses if truncated
|
static void |
warning(String s)
Warning message - nothing fancy at present
|
public static final String[] LOWER_ROMAN_NUMERAL
public static final String LOWER_ROMAN_REGEX
public static final String UPPER_ROMAN_REGEX
public static final String[] ISOLATIN_ENTITIES
public static final int ISOLATIN_LO
public static final int ISOLATIN_HI
public static final String[] GREEK_ENTITIES
public static final String[] UPPER_GREEK_ENTITIES
public static final String DATE_REGEX1
public static final String DATE_REGEX2
public static final String[] months
public static File getTEMP_DIRECTORY()
public static File getTestOutputDirectory(Class<?> classx)
classx - public static final String[] addElementToStringArray(String[] array, String s)
array - to extends - element to addpublic static final String[] removeElementFromStringArray(String[] array, String s)
array - to edits - element to removepublic static void BUG(String msg, Exception e)
RuntimeExceptionmsg - e - public static void BUG(Exception e)
e - BUG(String, Throwable)public static void throwNYI()
RuntimeExceptionpublic static void BUG(String msg)
msg - BUG(String, Throwable)public static InputStream getInputStreamFromResource(String filename) throws IOException
filename - relative to current class hierarchy.IOExceptionpublic static void createFile(File dir, String filename) throws IOException
dir - filename - IOExceptionpublic static URL getResource(String filename)
filename - name relative to classrootpublic static InputStream getResourceUsingContextClassLoader(String name, Class<?> clazz) throws FileNotFoundException
FileNotFoundExceptionpublic static File getResourceFile(String... path) throws URISyntaxException
path - URISyntaxExceptionpublic static String buildPath(String... parts)
parts - public static boolean deleteFile(File file, boolean deleteDirectory)
file - Description of the ParameterdeleteDirectory - Description of the Parameterpublic static void copyFile(File inFile, File outFile) throws FileNotFoundException, IOException
inFile - Description of the ParameteroutFile - Description of the ParameterFileNotFoundException - Description of the ExceptionIOException - Description of the Exceptionpublic static String dump(URL url) throws Exception
url - Description of the ParameterException - Description of the Exceptionpublic static String spaces(int nspace)
nspace - Description of the Parameterpublic static String getSuffix(String filename)
filename - Description of the Parameterpublic static String truncateAndAddEllipsis(String s, int maxlength)
s - maxlength - public static String truncateAndAddNewlinesAndEllipsis(String s, int maxlength)
s - maxlength - public static String deQuote(String s)
s - Description of the Parameterpublic static String rightTrim(String s)
s - Description of the Parameterpublic static String leftTrim(String s)
s - Description of the Parameterpublic static int indexOfBalancedBracket(char lbrack,
String s)
lbrack - starting characters - string to searchpublic static List<String> getCommaSeparatedStrings(String s) throws RuntimeException
s - Description of the ParameterRuntimeException - missing quotepublic static String createCommaSeparatedStrings(List<String> v)
v - vector of strings to be concatenated (null returns null)public static String quoteConcatenate(String[] s)
s - Description of the Parameterpublic static int indexOf(String string, String[] strings, boolean ignoreCase)
string - Description of the Parameterstrings - Description of the ParameterignoreCase - ignore casepublic static String removeHTML(String s)
"This is <A
HREF="foo">bar</A> and </BR> a break" goes to "This is bar
and a break"
s - Description of the Parameterpublic static void warning(String s)
s - Description of the Parameterpublic static void message(String s)
s - Description of the Parameterpublic static void error(String s)
s - Description of the Parameterpublic static void BUG(String msg, Throwable t)
RuntimeExceptionmsg - t - public static void BUG(Throwable t)
t - BUG(String, Throwable)public static String getPWDName()
public static File createNewFile(String fileName) throws IOException
fileName - IOExceptionpublic static String substituteString(String s, String oldSubstring, String newSubstring, int count)
s - oldSubstring - newSubstring - count - public static String substituteStrings(String s, String[] oldSubstrings, String[] newSubstrings)
s - oldSubstrings - newSubstrings - RuntimeExceptionpublic static String replaceNumericEntityByISOLatinString(String s, String ent)
s - string to be editedent - leading entitypublic static String replaceISOControlsByMnemonic(String s)
s - Description of the Parameterpublic static String translateToMnemonic(char ch)
ch - [0 - 31] or 127public static char convertUTF8ToLatin1(char a,
char b)
a - leading character (ignored if not C2 and not C3)b - range 80-bfpublic static char[] convertLatin1ToUTF8(char a)
a - char to be converted (a >= x80 AND a <xff)public static String replaceNumericEntityByGreekMnemonics(String s, String ent)
s - string to be editedent - leading entitypublic static String substituteDOSbyAscii(String s)
s - Description of the Parameterpublic static String replaceTabs(String s, int width)
s - width - public static String substituteEquals(String s)
s - Description of the Parameterpublic static int getIntFromHex(String hex)
hex - Description of the Parameterpublic static String capitalise(String s)
s - Description of the Parameterpublic static String toCamelCase(String s)
s - Description of the Parameterpublic static byte[] readByteArray(String filename) throws FileNotFoundException, IOException
filename - Description of the ParameterFileNotFoundException - Description of the ExceptionIOException - Description of the Exceptionpublic static byte[] readByteArray(DataInputStream d) throws IOException
d - Description of the ParameterIOException - Description of the Exceptionpublic static String stripISOControls(String s)
s - Description of the Parameterpublic static String normaliseWhitespace(String s)
s - Description of the Parameterpublic static byte[] stripNewlines(byte[] b)
b - Description of the Parameterpublic static FileOutputStream getFileOutputStream(String fileName) throws FileNotFoundException
fileName - Description of the ParameterFileNotFoundException - Description of the Exceptionpublic static String outputFloat(int nPlaces, int nDec, double value) throws EuclidRuntimeException
nPlaces - Description of the ParameternDec - Description of the Parametervalue - Description of the ParameterEuclidRuntimeException - Description of the Exceptionpublic static String outputNumber(int nPlaces, int nDec, double c)
nPlaces - Description of the ParameternDec - Description of the Parameterc - Description of the Parameterpublic static Hashtable<Object,Object> invert(Hashtable<Object,Object> table)
table - Description of the Parameterpublic static void check(double[] array,
int size)
throws EuclidRuntimeException
array - to checksize - required sizeEuclidRuntimeException - if null or wrong sizepublic static void check(int n,
int low,
int high)
throws EuclidRuntimeException
n - to checklow - inclusive lowerhigh - inclusive higherEuclidRuntimeException - if out of rangepublic static boolean isEqual(double[] a,
double[] b,
double eps)
a - first arrayb - second arrayeps - maximum allowed differencepublic static boolean isEqual(int[] a,
int[] b,
int eps)
a - first arrayb - second arrayeps - maximum allowed differencepublic static final String concatenate(boolean[] bb, String separator)
bb - the valuesseparator - public static final String concatenate(double[] ss, String separator)
ss - the valuesseparator - public static final String concatenate(double[][] ss, String separator)
ss - the valuesseparator - public static final int[] splitToIntArray(String s, String delim) throws EuclidRuntimeException
s - the stringdelim - EuclidRuntimeException - cannot parse as intspublic static final double[] splitToDoubleArray(String s)
s - the stringEuclidRuntimeException - cannot parse as intspublic static double parseFlexibleDouble(String value) throws ParseException
value - ParseExceptionpublic static final double[] splitToDoubleArray(String s, String delim) throws EuclidRuntimeException
s - the stringdelim - EuclidRuntimeException - cannot parse as intspublic static final String concatenate(int[] ss, String separator)
ss - the valuesseparator - public static final String concatenate(String[] ss, String separator)
ss - the valuesseparator - public static final boolean containsString(String[] strings, String s)
strings - s - string to search forpublic static double format(double d,
int ndec)
d - value to be formattedndec - max number of decimals (3 = ****.ddd)public static String trim(double d)
d - public static List<String> createList(String[] ss)
ss - strings (can include null)public static int getPrime(int i)
i - public static boolean isInt(String s)
s - public static boolean isIntArray(String s, String delimiterRegex)
s - delimiterRegex - public static boolean isFloatArray(String s, String delimiterRegex)
s - delimiterRegex - public static boolean isFloat(String s)
s - public static String getCanonicalDate(String s)
s - public static double getDouble(String s)
public static double trimFloat(double dd,
int ndec)
dd - number to be roundedndec - number of placespublic static void sortByEmbeddedInteger(List<?> list)
list - public static void print(String s)
s - public static void println(String s)
s - public static void println()
public static List<String> getRESTQueryAsLines(String s, String u, String mediaType) throws IOException
IOExceptionpublic static byte[] getRESTQuery(String serviceUrl, String urlString, String mediaType) throws IOException
IOExceptionpublic static String calculateMD5(String s)
s - public static String getCanonicalPath(File file)
file - public static String getRelativeFilename(File file1, File file2, String newSeparator)
file1 - file2 - newSeparator - if not null, use as new separatorpublic static String getRelativePath(String targetPath, String basePath, String pathSeparator)
targetPath - targetPath is calculated to this filebasePath - basePath is calculated from this filepathSeparator - directory separator. The platform default is not assumed so that we can test Unix behaviour when running on Windows (for example)public static boolean checkPMR()
Copyright © 1994–2024 Peter Murray-Rust. All rights reserved.