|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--harpoon.Util.Util
Miscellaneous static utility functions.
Constructor Summary | |
Util()
|
Method Summary | |
static String |
adjust_quotes(String str)
Returns a string that is identical to str , except
that every " character has been replaced with
the sequence \" . |
static void |
ASSERT(boolean val)
Assertion facility. |
static void |
ASSERT(boolean val,
Object msg)
Assertion facility, with a Object as an explanation
string. |
static Object[] |
copy(ArrayFactory factory,
Object[] src)
Deprecated. The clone() method on arrays works
much better, and should be used instead of this method. |
static String |
escape(String str)
Escape the contents of a String so they are safe to print. |
static int |
ffs(int v)
Find first set (least significant bit). |
static int |
ffs(long v)
Find first set (least significant bit). |
static int |
fls(int v)
Find last set (most significant bit). |
static int |
fls(long v)
Find last set (most significant bit). |
static int |
gcd(int u,
int v)
Returns the greatest common divisor of a pair of numbers. |
static long |
gcd(long u,
long v)
Returns the greatest common divisor of a pair of numbers. |
static ArrayFactory |
genericFactory(Object[] src)
Deprecated. requires java language reflection. |
static FOOTER |
getFOOTER(HCode hcode)
Returns the unique FOOTER quad from hcode . |
static METHOD |
getMETHOD(HCode hcode)
Returns the unique METHOD quad from hcode . |
static Object[] |
grow(ArrayFactory factory,
Object[] src,
Object o,
int n)
Insert element o before src[n] . |
static String |
jasminEscape(String str)
Escape the contents of a String so they are safe to print. |
static int |
log2c(int v)
Returns ceil(log2(n)) |
static int |
popcount(int v)
Return the number of ones in the binary representation of the value of the argument. |
static int |
popcount(long v)
Return the number of ones in the binary representation of the value of the argument. |
static void |
print_collection(Collection c,
String c_name)
Even more simplified version of print_collection . |
static void |
print_collection(Collection c,
String c_name,
String indent)
Simplified version of print_collection . |
static void |
print_collection(Collection c,
String c_name,
String indent,
PrintWriter pw)
Pretty printer for collections. |
static String |
print(Collection collection)
Return a String representing the elements of
collection in a human readable format. |
static String |
repeatString(String s,
int n)
Repeat a given string a certain number of times. |
static Object[] |
safeCopy(ArrayFactory factory,
Object[] src)
Copy an array type to prevent modification. |
static Set |
set_diff(Set a,
Set b)
Computes the difference of two sets: a-b . |
static Object[] |
shrink(ArrayFactory factory,
Object[] src,
int n)
Remove element 'n' from array 'src'. |
static int |
zerocount(int v)
Return the number of zeros in the binary representation of the value of the argument. |
static int |
zerocount(long v)
Return the number of zeros in the binary representation of the value of the argument. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Util()
Method Detail |
public static final ArrayFactory genericFactory(Object[] src)
src
parameter (which should be an array of some
object type). This method uses run-time type information and
thus should not be used.
public static final Object[] safeCopy(ArrayFactory factory, Object[] src)
public static final Object[] copy(ArrayFactory factory, Object[] src)
clone()
method on arrays works
much better, and should be used instead of this method.
public static final Object[] shrink(ArrayFactory factory, Object[] src, int n)
public static final Object[] grow(ArrayFactory factory, Object[] src, Object o, int n)
o
before src[n]
.
After return, src[n]==o
.
public static final String escape(String str)
public static final String jasminEscape(String str)
public static final void ASSERT(boolean val)
RuntimeException
if
the boolean parameter is false
.
public static final void ASSERT(boolean val, Object msg)
Object
as an explanation
string.
Throws a RuntimeException
including the output of
msg.toString()
if the boolean parameter is
false
.
Note that this can be used as a Lazy Evaluation hack;
since it only evaluates msg.toString()
if
val
is false
), it can be used for code
where evaluating the msg
string takes too long to
do everytime the assertion is checked or the explanation string
can't be generated if val
is true.
public static final String repeatString(String s, int n)
s
repeated n
times.public static final int ffs(int v)
ffs(0)==0
and ffs(1)==1
.public static final int ffs(long v)
ffs(0)==0
and ffs(1)==1
.public static final int fls(int v)
fls(0)==0
and fls(1)==1
.public static final int fls(long v)
fls(0)==0
and fls(1)==1
.public static final int log2c(int v)
public static final int zerocount(int v)
public static final int zerocount(long v)
public static final int popcount(int v)
public static final int popcount(long v)
public static final long gcd(long u, long v)
public static final int gcd(int u, int v)
public static final String print(Collection collection)
String
representing the elements of
collection
in a human readable format.
collection
,
calling toString()
on each element and
appending the result to a String
. The format
of the returned String
is
String
representing
collection
.public static final void print_collection(Collection c, String c_name, String indent, PrintWriter pw)
c
- The Collection
to be printed.c_name
- The name of the collection.indent
- String used for indentation (eg "\t
".pw
- The PrintWriter
used to do the printing itself.
The collection is printed in the following format: the name of
the collection followed by the collection size (in parans) and one
opening curly bracet on the first line, the elements of the
collection, one by one, each on a separate line and indented with a
tab; on the last line, one closing curly bracet. In addition, each
line is prefixed with the string indent
.public static final void print_collection(Collection c, String c_name, String indent)
print_collection
.
Uses the default value
new java.io.PrintWriter(System.out, true)
for the pw
parameter.
public static final void print_collection(Collection c, String c_name)
print_collection
.
Uses the default value ""
for indent
and new java.io.PrintWriter(System.out, true)
for the pw
parameter.
public static final Set set_diff(Set a, Set b)
a-b
.
public static final METHOD getMETHOD(HCode hcode)
METHOD
quad from hcode
.
public static final FOOTER getFOOTER(HCode hcode)
FOOTER
quad from hcode
.
public static final String adjust_quotes(String str)
str
, except
that every "
character has been replaced with
the sequence \"
.
This is useful when we generate output for
tools like VCG which expects the value of some attributes to be put
between quotes (and of course any quote inside has to be given using
an escape sequence).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |