|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectharpoon.Util.Util
public abstract class 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 String |
code2str(HCodeElement q)
Returns the string representation of the code instruction q in the formay: source_file:line_number instruction . |
|
static Object |
convert(Object obj,
Map map)
Converts an objects using the reflexive closure of a map. |
|
static
|
copy(ArrayFactory<T> factory,
T[] src)
Deprecated. The clone() method on arrays works
much better, and should be used instead of this method. |
|
static String |
doubleRep(double d,
int decimals)
Returns the string representation of the double d, with a certain number of decimals. |
|
static String |
doubleRep(double d,
int digits,
int decimals)
Returns the string representation of the double d, with a certain number of decimals. |
|
static String |
escape(String str)
Escape the contents of a String so they are safe to print. |
|
static ArrayFactory |
genericFactory(Object[] src)
Deprecated. requires java language reflection. |
|
static String |
getLine(HCodeElement q)
Returns the line of the instruction q in the format source_file:line_number . |
|
static
|
grow(ArrayFactory<T> factory,
T[] src,
T 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 String |
longProportion(long a,
long b,
int digits,
int decimals)
Convenient version of longProportion that uses
null for the memSizeFormat . |
|
static String |
longProportion(long a,
long b,
int digits,
int decimals,
boolean memSizeFormat)
Pretty printer for a proportion: " a out of total = proportion" (where total=a+b). |
|
static String |
memSizeFormat(long size)
Nicely formats the memory size size , using normal
units for memory size. |
|
static String |
percentage(double a,
double total)
Returns a string representing the proportion a/total (in percents). |
|
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 |
proportion2str(long a,
long b)
Returns the string representation of the proportion a/b. |
|
static HMethod |
quad2method(Quad q)
|
|
static
|
safeCopy(ArrayFactory<T> factory,
T[] src)
Copy an array type to prevent modification. |
|
static
|
set_diff(Set<A> a,
Set<B> b)
Computes the difference of two sets: a-b . |
|
static
|
shrink(ArrayFactory<T> factory,
T[] src,
int n)
Remove element 'n' from array 'src'. |
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 <T> T[] safeCopy(ArrayFactory<T> factory, T[] src)
public static final <T> T[] copy(ArrayFactory<T> factory, T[] src)
clone()
method on arrays works
much better, and should be used instead of this method.
public static final <T> T[] shrink(ArrayFactory<T> factory, T[] src, int n)
public static final <T> T[] grow(ArrayFactory<T> factory, T[] src, T 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 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 <A,B> Set<A> set_diff(Set<A> a, Set<B> b)
a-b
.
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).
public static Object convert(Object obj, Map map)
obj
- object to be convertedmap
- conversion map
obj
is in the key set of
map
, returns map.get(obj)
. Otherwise,
the method simply returns obj
.public static String doubleRep(double d, int decimals)
public static String doubleRep(double d, int digits, int decimals)
public static String percentage(double a, double total)
public static String getLine(HCodeElement q)
source_file:line_number
.
public static String code2str(HCodeElement q)
source_file:line_number instruction
.
public static HMethod quad2method(Quad q)
public static String proportion2str(long a, long b)
public static String longProportion(long a, long b, int digits, int decimals, boolean memSizeFormat)
memSizeFormat is true,
a and total are displayed as memory size
(i.e., 2048 is 2K). digits
and
decimals
indicates the formatting for the
proportion.
public static String longProportion(long a, long b, int digits, int decimals)
longProportion
that uses
null
for the memSizeFormat
.
public static String memSizeFormat(long size)
size
, using normal
units for memory size. For example, 2048 is printed as 2.00K.
The biggest unit we support now is Tera.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |