UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.gesture.util
Class Misc

java.lang.Object
  |
  +--edu.berkeley.guir.lib.gesture.util.Misc

public class Misc
extends Object

Various useful things that didn't fit elsewhere


Inner Class Summary
static interface Misc.Acceptor
           
static interface Misc.MapAcceptor
           
static interface Misc.UnaryOperator
           
 
Field Summary
static Misc.UnaryOperator IDENTITY_OPERATOR
           
 
Method Summary
static Collection accept(Collection in, Misc.Acceptor acceptor)
          Return a Collection that contains all elements of in for which acceptor returns true.
static boolean areEqualOrNull(String a, String b)
          returns true if both a and b are null, or if both have the same string value (as determined by equals())
static void bitStringTest(String[] args)
           
static Collection cloneCollection(Collection c)
          Clones the collection.
static Collection cloneCollection(Collection c, boolean cloneMembers)
          If cloneMembers, clone the members of the collection if possible.
static Collection deepCopy(Collection c)
          make a deep copy of c, as far as possible.
static Map deepCopy(Map m)
           
static Map deepCopy(Map m, Misc.MapAcceptor acceptor)
          deep copy only key/value pairs that are accepted by acceptor
static Object deepCopy(Object obj)
           
static Object[] deepCopy(Object[] a)
          make a deep copy of a, as far as possible.
static String escapeString(String s)
           
static Object findLargest(Collection collection, Comparator comp)
           
static Object findLargest(Iterator iter, Comparator comp)
           
static int indexOf(Object[] array, Object target)
           
static Object invokeClone(Object o)
          Invoke the clone() method and return the result, or null if it fails.
static void main(String[] args)
           
static Collection makeEmptyClone(Collection c)
          Return an empty collection of the same type as c, if possible (using Class.newInstance()).
static Collection mapcar(Collection in, Misc.UnaryOperator op)
          Apply op to all elements of in, and make a new Collection of the results.
static List mapcar(Iterator iter, Misc.UnaryOperator op)
           
static int maxAbsIndex(Number[] a)
          Return the index of the highest absolute value (or -1 if a has no elements).
static int maxIndex(Number[] a)
          Return the index of the highest value (or -1 if a has no elements).
static BitSet not(BitSet bs)
           
static String ordinal(int n)
           
static String ordinalSuffix(int n)
           
static void printVector(PrintStream out, double[] v, int sigFigs)
           
static Double[] promoteArray(double[] a)
           
static Double[][] promoteMatrix(double[][] m)
           
static String readEscapedString(Reader reader)
           
static String readEscapedString(Reader reader, boolean ignoreInitialWhitespace)
           
static int sgn(double d)
           
static void shuffle(int[] a)
           
static void shuffle(int[] a, Random r)
           
static void shuffle(Object[] a)
           
static void shuffle(Object[] a, Random r)
           
static void shuffle(Vector v)
           
static void shuffle(Vector v, Random r)
           
static int sign(double x)
          return -1 if x is negative, 0 if x is 0, or 1 if x is positive
static String toString(double x, int sigFigs)
          I couldn't find a routine to correctly convert a double to a string with a specified number of significant figures, so I wrote one myself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDENTITY_OPERATOR

public static final Misc.UnaryOperator IDENTITY_OPERATOR
Method Detail

toString

public static String toString(double x,
                              int sigFigs)
I couldn't find a routine to correctly convert a double to a string with a specified number of significant figures, so I wrote one myself. I believe it works in all cases, but would be very appreciative of bug reports if it does not.

promoteArray

public static Double[] promoteArray(double[] a)

promoteMatrix

public static Double[][] promoteMatrix(double[][] m)

maxIndex

public static int maxIndex(Number[] a)
Return the index of the highest value (or -1 if a has no elements).

maxAbsIndex

public static int maxAbsIndex(Number[] a)
Return the index of the highest absolute value (or -1 if a has no elements).

sgn

public static int sgn(double d)

not

public static BitSet not(BitSet bs)

shuffle

public static void shuffle(int[] a)

shuffle

public static void shuffle(int[] a,
                           Random r)

shuffle

public static void shuffle(Object[] a)

shuffle

public static void shuffle(Object[] a,
                           Random r)

shuffle

public static void shuffle(Vector v)

shuffle

public static void shuffle(Vector v,
                           Random r)

bitStringTest

public static void bitStringTest(String[] args)

main

public static void main(String[] args)

ordinalSuffix

public static String ordinalSuffix(int n)

ordinal

public static String ordinal(int n)

printVector

public static void printVector(PrintStream out,
                               double[] v,
                               int sigFigs)

indexOf

public static int indexOf(Object[] array,
                          Object target)

findLargest

public static Object findLargest(Collection collection,
                                 Comparator comp)

findLargest

public static Object findLargest(Iterator iter,
                                 Comparator comp)

makeEmptyClone

public static Collection makeEmptyClone(Collection c)
Return an empty collection of the same type as c, if possible (using Class.newInstance()). If that fails, make an ArrayList.

mapcar

public static Collection mapcar(Collection in,
                                Misc.UnaryOperator op)
Apply op to all elements of in, and make a new Collection of the results. It tries to make a new Collection of the same type as in. If this fails it returns an ArrayList.

mapcar

public static List mapcar(Iterator iter,
                          Misc.UnaryOperator op)

accept

public static Collection accept(Collection in,
                                Misc.Acceptor acceptor)
Return a Collection that contains all elements of in for which acceptor returns true.

cloneCollection

public static Collection cloneCollection(Collection c)
Clones the collection. Does not clone its members.

invokeClone

public static Object invokeClone(Object o)
Invoke the clone() method and return the result, or null if it fails.

cloneCollection

public static Collection cloneCollection(Collection c,
                                         boolean cloneMembers)
If cloneMembers, clone the members of the collection if possible. If one or more members cannot be cloned, they will silently not be.

deepCopy

public static Object[] deepCopy(Object[] a)
make a deep copy of a, as far as possible. If the Collection contains Collections or arrays, they are deep copied, too.

deepCopy

public static Collection deepCopy(Collection c)
make a deep copy of c, as far as possible. If the Collection contains Collections or arrays, they are deep copied, too.

deepCopy

public static Object deepCopy(Object obj)

deepCopy

public static Map deepCopy(Map m)

deepCopy

public static Map deepCopy(Map m,
                           Misc.MapAcceptor acceptor)
deep copy only key/value pairs that are accepted by acceptor

escapeString

public static String escapeString(String s)

readEscapedString

public static String readEscapedString(Reader reader)
                                throws ParseException,
                                       IOException

readEscapedString

public static String readEscapedString(Reader reader,
                                       boolean ignoreInitialWhitespace)
                                throws ParseException,
                                       IOException

areEqualOrNull

public static boolean areEqualOrNull(String a,
                                     String b)
returns true if both a and b are null, or if both have the same string value (as determined by equals())

sign

public static int sign(double x)
return -1 if x is negative, 0 if x is 0, or 1 if x is positive

Copyright Information