edu.stanford.nlp.ie.pcfg
Class Util

java.lang.Object
  |
  +--edu.stanford.nlp.ie.pcfg.Util

public class Util
extends Object

Provides basic utility operations


Constructor Summary
Util()
           
 
Method Summary
static void Beep()
          beep.
static int C(int n, int r)
          calculates choose(n, r)
static List Disjunction(List list1, List list2)
          Gets the disjunction of the two "sets", list1 and list2.
static double Exp(double a, double b)
          calculates a ^ b.
static int Exp(int a, int b)
          calculates a ^ b.
static int F(int n)
          Calculates the "n"th Fibonacci number.
static List GetAllCombinations(List list)
          Gets all possible combinations of the elements in a list.
static List GetAllCombinations(List list, int max, boolean allowDuplicates)
          Gets all possible combinations of the elements in a list.
static List GetCombinations(List list, int size, boolean allowDuplicates)
          Gets all possible combinations of the elements in a list.
static double GetElapsedTime(long start)
          Gets the difference between current time and "start".
static List GetPermutations(List list)
          Gets all possible combinations of the elements in a list.
static List GetPermutations(List list, int size, boolean allowDuplicates)
          Gets all possible permuations of the elements in a list.
static int IndexOf(List l, Object o)
          Gets the index of an index of an object within a list.
static List Intersection(List list1, List list2)
          calculates the intersection of list1 and list2.
static void main(String[] args)
           
static int Max(int a, int b)
          Max
static int Min(int a, int b)
          Min
static List RemoveDuplicates(List list)
          removes duplicates from a list.
static List RemoveOneOccurrence(List list, Object o)
          removes the first occurrence of o in list.
static void WriteLine(String s, BufferedWriter bw)
          writes a single-line string plus newline out to a buffered writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

WriteLine

public static void WriteLine(String s,
                             BufferedWriter bw)
                      throws IOException
writes a single-line string plus newline out to a buffered writer.

IOException

Disjunction

public static List Disjunction(List list1,
                               List list2)
Gets the disjunction of the two "sets", list1 and list2. calculates equality by object1.equals(object2)


IndexOf

public static int IndexOf(List l,
                          Object o)
Gets the index of an index of an object within a list. Calculates equality by object1.equals(object2)

Returns:
index of object if found in list, -1 otherwise

GetCombinations

public static List GetCombinations(List list,
                                   int size,
                                   boolean allowDuplicates)
Gets all possible combinations of the elements in a list. Only returns combination sets with exactly "size" elements.

Parameters:
size - all of the combination sets found by this method must contain exactly "size" elements
allowDuplicates - if the method should return combination sets that contain duplicates (each element in the list is assumed to be unique. so even if allowDuplicates is false, it would still be possible for combination sets to contain duplicates if the original list contained duplicates).

GetAllCombinations

public static List GetAllCombinations(List list,
                                      int max,
                                      boolean allowDuplicates)
Gets all possible combinations of the elements in a list. Only returns combination sets with AT MOST "max" elements

Parameters:
max - all of the combination sets found by this method must contain at most "size" elements
allowDuplicates - if the method should return combination sets that contain duplicates (each element in the list is assumed to be unique. so even if allowDuplicates is false, it would still be possible for combination sets to contain duplicates if the original list contained duplicates).

GetAllCombinations

public static List GetAllCombinations(List list)
Gets all possible combinations of the elements in a list. No duplicates allowed. Thus, the maximum combination set size is list.size()


RemoveDuplicates

public static List RemoveDuplicates(List list)
removes duplicates from a list. calculates equality by equals()


RemoveOneOccurrence

public static List RemoveOneOccurrence(List list,
                                       Object o)
removes the first occurrence of o in list. if list does not contain o, doesn't do anything. calculates equality by equals()


GetPermutations

public static List GetPermutations(List list,
                                   int size,
                                   boolean allowDuplicates)
Gets all possible permuations of the elements in a list. Only returns combination sets with exactly "size" elements.

Parameters:
size - all of the permutation sets found by this method must contain exactly "size" elements
allowDuplicates - if the method should return permutation sets that contain duplicates (each element in the list is assumed to be unique. so even if allowDuplicates is false, it would still be possible for permutation sets to contain duplicates if the original list contained duplicates).

GetPermutations

public static List GetPermutations(List list)
Gets all possible combinations of the elements in a list. No duplicates allowed. Thus, set size is list.size()


GetElapsedTime

public static double GetElapsedTime(long start)
Gets the difference between current time and "start". returns time in seconds (rounded off after the first decimal place)


Beep

public static void Beep()
beep. currently just uses Toolkit.getDefaultToolkit().beep();


F

public static int F(int n)
Calculates the "n"th Fibonacci number. By def, F(0) = F(1) = 1


C

public static int C(int n,
                    int r)
calculates choose(n, r)


Exp

public static int Exp(int a,
                      int b)
calculates a ^ b. dumb implementation. only valid for b >= 0

Returns:
1 if b < 0; a ^ b otherwise

Exp

public static double Exp(double a,
                         double b)
calculates a ^ b. uses Math.exp(b * Math.log(a))


Min

public static int Min(int a,
                      int b)
Min


Max

public static int Max(int a,
                      int b)
Max


Intersection

public static List Intersection(List list1,
                                List list2)
calculates the intersection of list1 and list2. calculates equality with equals()


main

public static void main(String[] args)


Stanford NLP Group