|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.unibi.techfak.misc.IOTools
public class IOTools
Tools for input and output operations and format conversions.
| Field Summary | |
|---|---|
static java.util.Random |
rand
The random number generator used by some methods within the class. |
private static long |
serialVersionUID
The seriel version number of this class. |
| Constructor Summary | |
|---|---|
IOTools()
|
|
| Method Summary | |
|---|---|
static java.lang.String |
combineStrings(java.lang.Object[] array,
java.lang.String delim)
An array of objects is combined into one string ready for output. |
static java.lang.String |
createRandomSequence(int length,
char[] chars,
double[] distr)
Creates a sequence of random characters using the given distribution. |
static java.lang.String |
cutString(java.lang.String s,
int size)
This method reduces any given string to be less or equal the given size. |
static java.lang.String |
dbl2str(double nr)
Converts a double to string with a 2-figures-precision |
static java.lang.String |
dbl2str(double nr,
int fig)
Converts a double to string with the number of figures after the point (rounded). |
static java.lang.String |
formatTime(long msec)
Short call for formatTime( msec, -1, true ). |
static java.lang.String |
formatTime(long msec,
int count,
boolean ms)
Gets the number of milliseconds and builds a time string. |
static java.io.BufferedReader |
openFile(java.lang.String filename)
Opens an existing file and returns a BufferedReader. |
static java.io.BufferedWriter |
openFile(java.lang.String filename,
char how)
Opens an file to write data. |
static boolean |
test(int flag,
int bits)
Using this method you can test a flag for various settings. |
static boolean |
testA(int flag,
int onBits,
int offBits)
Using this method you can test a flag for various settings and off settings. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static java.util.Random rand
null, otherwise the method using this throw
a NullPointerException. This object is made public, so
it can be set by any out-sider class. This might be neccessary if
the seed has to be known.
private static final long serialVersionUID
| Constructor Detail |
|---|
public IOTools()
| Method Detail |
|---|
public static java.io.BufferedReader openFile(java.lang.String filename)
filename - The name of the file to open for reading.
BufferedReader, null
in case of error
public static java.io.BufferedWriter openFile(java.lang.String filename,
char how)
filename - The name of the file to open for writing.how - The mode of writing, recognized is 'a' for appending.
BufferedWriter or null
in case of error
public static java.lang.String dbl2str(double nr,
int fig)
nr is less then 0.0, otherwise a blank.
nr - The number to be converted to a String.fig - The precision of the conversion.
String representing the double number.public static java.lang.String dbl2str(double nr)
nr - The number to be converted to a String.
public static boolean test(int flag,
int bits)
Using this method you can test a flag for various settings.
This method test, whether at least one of the given 'bits' is set,
e.g. imagine flag=1 and bits=3, than this method would return
true.
If either flag or bits is zero,
false is returned.
flag - The flag to be tested.bits - The bits that must be set in the flag.
true, if at least one bit in bits is set in
flag, false otherwise.
public static boolean testA(int flag,
int onBits,
int offBits)
true, two conditions must
be met. First, all offBits must be off in
flag, second, at least one onBit must be
on. If flag=0 false is returned.
onBits and offBits might share some bits.
flag - The flag to be tested.onBits - At least one of these bits must be set in the flag.offBits - The bits that must be off in the flag.
true, if at least one required bit is set in
flag AND ALL tested bits are off, false
otherwise.
public static java.lang.String cutString(java.lang.String s,
int size)
s - The string which size should be reduced.size - The size the string is meant to be after cutting.
String is returned.
public static java.lang.String combineStrings(java.lang.Object[] array,
java.lang.String delim)
Object in the array the method
toString() is called and the resulting
Strings are combined with delim
between them.
array - The objects from which the describing strings are got.delim - The String to seperate two objects
description.
Objects.
public static java.lang.String createRandomSequence(int length,
char[] chars,
double[] distr)
length - The lenght of the generated random sequence.chars - The characters used for the random sequence.distr - The distribution of the characters.
public static java.lang.String formatTime(long msec,
int count,
boolean ms)
Gets the number of milliseconds and builds a time string. The time
string has the format '[[[wwd ]xxh ]yym ]zz.zzzs'. msec
is recalcalated to days (ww), hours (xx), minutes (yy), seconds
(zz) and milliseconds (.zzz). If leading time values are zero, they
are skipped.
Example: for msec=4500, the resulting string is '4.5s', for msec=450,000, it is '7m 30s' and for msec=45,001,803 it is '12h 30m 1.803s'
The parameter count defines how many values should be
included in the formated time string. Set count to
less than zero to get the format like in the above examples. Give
count greater or equal one to include values (from
left to right) and exclude the residues. If count is
zero, the empty String is returned.
Example: msec may always be 45,001,803, (ms=true for
count=0 one gets the
same as in the example above, '12h 30m 1.803s'. For count=1 the
resulting string contains only the first time value, '12h', all
other values are left out. For count=2 the result is '12h 30m',
for count=3 it is '12h 30m 1s', the milliseconds are skipped, and
for count greater than 3 it is '12h 30m 1.803s'.
msec - The number of milliseconds.count - The number of time values included in the string.ms - Should millisecond be printed or not.
public static java.lang.String formatTime(long msec)
formatTime( msec, -1, true ).
msec - The number of milliseconds.
formatTime(long, int, boolean)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||