org.problets.domain
Class Library

java.lang.Object
  extended by org.problets.domain.Library

public class Library
extends java.lang.Object

Class for methods to be used by multiple classes

Author:
Amruth Kumar

Constructor Summary
Library()
           
 
Method Summary
static void copyExplanationVector(java.util.Vector fromVector, java.util.Vector toVector)
           
static void copyStringVector(java.util.Vector fromVector, java.util.Vector toVector)
           
static void extractTable(java.util.Vector newTable, java.lang.String token, java.util.Vector identifierTable)
           
static java.util.Vector flattenVector(java.util.Vector sourceVector)
          Flattens a vector of vectors into a single vector, inserting a blank string between elements
static java.util.Vector getAllSelectedOptions(java.io.BufferedReader input, java.util.Vector options)
          Given a vector of options, lets user choose multiple options and returns the chosen options.
static java.util.Vector getAllSelectedOptions(java.util.Vector options)
           
static java.lang.String getClassInstanceFieldValue(java.lang.String className, java.lang.Object classInstance, java.lang.String fieldName)
          Returns the value of any public field of String type of any class
static java.lang.String getComplementString(int currentSize, int maxSize)
           
static java.util.Vector getFileNames(java.lang.String path, java.lang.String extension)
          Returns a list of the names of files with the given extension at the given path
static java.lang.String getLanguageString(int language)
           
static int getMaxLength(java.lang.String[] stringArray)
          Method returns the length of the longest string in the string array
static int getNumericResponse(java.io.BufferedReader input, java.lang.String question)
           
static int getNumericResponse(java.lang.String question)
          Returns the numeric input from the user
static int getNumLinesInString(java.lang.String content)
          Returns the number of lines in the string, based on \n, i.e., the number of the line where the cursor will end up after printing the string
static java.lang.String getOrdinalString(int num)
          Given a number, returns its ordinality as a string, with a space afterwards
static java.lang.String getResponse(java.io.BufferedReader input, java.lang.String question)
           
static java.lang.String getResponse(java.lang.String question)
          Given a question, get an answer to it and return it
static java.lang.String getSelectedOption(java.io.BufferedReader input, java.lang.String[] options)
           
static java.lang.String getSelectedOption(java.io.BufferedReader input, java.util.Vector options)
          Presents the options, validates user choice and returns the choice as the ordinality of the choice
static java.lang.String getSuffixedNumber(int number)
          Given a number, returns it with its ordinal suffix
static boolean getYesNo(java.io.BufferedReader input, java.lang.String question)
           
static boolean getYesNo(java.lang.String question)
          Given a question, get a yes/no answer to it and return true/false correspondingly
static boolean hasIntersection(boolean[] correctAnswerArray, boolean[] userAnswerArray)
           
static boolean hasIntersection(java.util.Vector firstVector, java.util.Vector secondVector)
           
static void insertTable(java.util.Vector identifierTable, java.lang.String token, java.lang.String name)
           
static void insertTable(java.util.Vector identifierTable, java.lang.String token, java.lang.String name, int insertionIndex)
           
static boolean isAnElementOf(java.lang.String selectedAnswer, java.lang.String correctAnswer)
           
static boolean isEquivalent(java.lang.String selectedAnswer, java.lang.String correctAnswer)
           
static boolean isEquivalentArray(boolean[] correctAnswerArray, boolean[] userAnswerArray)
           
static boolean isSupersetArray(boolean[] correctAnswerArray, boolean[] userAnswerArray)
           
static boolean isSupersetOf(java.lang.String selectedAnswer, java.lang.String correctAnswer)
           
static void main(java.lang.String[] args)
           
static int nthIndexOf(java.lang.String string, java.lang.String key, int count)
           
static void printAnyVector(java.lang.String header, java.util.Vector text)
           
static void printVector(java.lang.String header, java.util.Vector text)
           
static void printVectorIndexed(java.util.Vector text)
           
static java.util.Vector readFromFile(java.lang.String path, java.lang.String fileName, java.lang.String commentPrefix)
          This method returns a vector containing the contents of a resource file included with the Jar file It strips all comments and blank lines from the file It also trims each entry.
static java.util.Vector readFromLocalFile(java.lang.String path, java.lang.String fileName)
          This method returns a vector containing the contents of a file included with Jar file.
static void recursivePrint(java.util.Vector explanation)
           
static void saveVectorInFile(java.lang.String path, java.lang.String fileName, java.util.Vector data)
          Saves the given vector to the given file, one element per line
static void shuffle(java.util.Vector data)
          Shuffles the vector of n elements 3n times
static java.util.Vector string2Vector(java.lang.String content, java.lang.String delimiter)
          Given a string, returns a vector of its "elements" as separated by delimiter
static int toInteger(java.lang.String entry)
          Given a string, returns the number represented by the string, -1 if it is not a number
static java.lang.String toPrecision(double value, int precision)
           
static java.lang.String[] vector2Array(java.util.Vector content)
          For any vector to whose contents toString() can be applied, returns a corresponding array of strings.
static java.lang.String vector2String(java.util.Vector content)
          Given a vector of strings, return a single string concatenating all the elements
static java.lang.String vector2String(java.util.Vector content, int start, int finish)
           
static java.lang.String xmlEnclose(java.lang.String content, java.lang.String tagSpecifier)
          Returns the content enclosed in open and close tag specifier
static java.lang.String xmlEnclose(java.util.Vector contents, java.lang.String contentTag, java.lang.String elementTag)
          Return all elements of a vector enclosed in XML format
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Library

public Library()
Method Detail

isAnElementOf

public static boolean isAnElementOf(java.lang.String selectedAnswer,
                                    java.lang.String correctAnswer)

isSupersetOf

public static boolean isSupersetOf(java.lang.String selectedAnswer,
                                   java.lang.String correctAnswer)

hasIntersection

public static boolean hasIntersection(boolean[] correctAnswerArray,
                                      boolean[] userAnswerArray)

hasIntersection

public static boolean hasIntersection(java.util.Vector firstVector,
                                      java.util.Vector secondVector)

isSupersetArray

public static boolean isSupersetArray(boolean[] correctAnswerArray,
                                      boolean[] userAnswerArray)

isEquivalentArray

public static boolean isEquivalentArray(boolean[] correctAnswerArray,
                                        boolean[] userAnswerArray)

isEquivalent

public static boolean isEquivalent(java.lang.String selectedAnswer,
                                   java.lang.String correctAnswer)

flattenVector

public static java.util.Vector flattenVector(java.util.Vector sourceVector)
Flattens a vector of vectors into a single vector, inserting a blank string between elements


saveVectorInFile

public static void saveVectorInFile(java.lang.String path,
                                    java.lang.String fileName,
                                    java.util.Vector data)
Saves the given vector to the given file, one element per line


readFromFile

public static java.util.Vector readFromFile(java.lang.String path,
                                            java.lang.String fileName,
                                            java.lang.String commentPrefix)
This method returns a vector containing the contents of a resource file included with the Jar file It strips all comments and blank lines from the file It also trims each entry.


readFromLocalFile

public static java.util.Vector readFromLocalFile(java.lang.String path,
                                                 java.lang.String fileName)
This method returns a vector containing the contents of a file included with Jar file. It strips all comments and blank lines from the file.


getFileNames

public static java.util.Vector getFileNames(java.lang.String path,
                                            java.lang.String extension)
Returns a list of the names of files with the given extension at the given path


getOrdinalString

public static java.lang.String getOrdinalString(int num)
Given a number, returns its ordinality as a string, with a space afterwards


getSuffixedNumber

public static java.lang.String getSuffixedNumber(int number)
Given a number, returns it with its ordinal suffix


shuffle

public static void shuffle(java.util.Vector data)
Shuffles the vector of n elements 3n times


toPrecision

public static java.lang.String toPrecision(double value,
                                           int precision)
Parameters:
value - Real double value
precision - int Desired precision for the real number Returns the value correct to precision digits after the decimal point

vector2String

public static java.lang.String vector2String(java.util.Vector content)
Given a vector of strings, return a single string concatenating all the elements


vector2String

public static java.lang.String vector2String(java.util.Vector content,
                                             int start,
                                             int finish)

vector2Array

public static java.lang.String[] vector2Array(java.util.Vector content)
For any vector to whose contents toString() can be applied, returns a corresponding array of strings. Defined here to avoid casting problems with Vector.toArray()


getNumLinesInString

public static int getNumLinesInString(java.lang.String content)
Returns the number of lines in the string, based on \n, i.e., the number of the line where the cursor will end up after printing the string


string2Vector

public static java.util.Vector string2Vector(java.lang.String content,
                                             java.lang.String delimiter)
Given a string, returns a vector of its "elements" as separated by delimiter


nthIndexOf

public static int nthIndexOf(java.lang.String string,
                             java.lang.String key,
                             int count)
Parameters:
string - The string to be searched
key - The key to be located in the string
count - The number of occurrences of key to be located in string
Returns:
Returns the nth index of the shown key in the given string, e.g., nthIndexOf( "A / B / C / D / E", '/', 3 ) returns the index of / between C and D. Returns -1 if nth occurrence of key is out of bounds of the string or illegal value is provided for count

xmlEnclose

public static java.lang.String xmlEnclose(java.lang.String content,
                                          java.lang.String tagSpecifier)
Returns the content enclosed in open and close tag specifier


xmlEnclose

public static java.lang.String xmlEnclose(java.util.Vector contents,
                                          java.lang.String contentTag,
                                          java.lang.String elementTag)
Return all elements of a vector enclosed in XML format

Parameters:
contentTag - the tag for the whole group of elements
elementTag - the tag for each individual element
Returns:
a string with the XML representation of the vector

toInteger

public static int toInteger(java.lang.String entry)
Given a string, returns the number represented by the string, -1 if it is not a number


getLanguageString

public static java.lang.String getLanguageString(int language)

getClassInstanceFieldValue

public static java.lang.String getClassInstanceFieldValue(java.lang.String className,
                                                          java.lang.Object classInstance,
                                                          java.lang.String fieldName)
Returns the value of any public field of String type of any class

Parameters:
className - String representing the name of the class. The case is important.
classInstance - Object whose field value we want. If the field is static, this will be null.
fieldName - String representing the field name whose value is desired. This must be a String type. The case is not important.
Returns:
String value of the fieldName of the classInstance of className class. Returns empty string if class is not found, field is not accessible, or the field is not of String type

extractTable

public static void extractTable(java.util.Vector newTable,
                                java.lang.String token,
                                java.util.Vector identifierTable)

insertTable

public static void insertTable(java.util.Vector identifierTable,
                               java.lang.String token,
                               java.lang.String name)

insertTable

public static void insertTable(java.util.Vector identifierTable,
                               java.lang.String token,
                               java.lang.String name,
                               int insertionIndex)

copyStringVector

public static void copyStringVector(java.util.Vector fromVector,
                                    java.util.Vector toVector)

copyExplanationVector

public static void copyExplanationVector(java.util.Vector fromVector,
                                         java.util.Vector toVector)

getMaxLength

public static int getMaxLength(java.lang.String[] stringArray)
Method returns the length of the longest string in the string array


getComplementString

public static java.lang.String getComplementString(int currentSize,
                                                   int maxSize)

getYesNo

public static boolean getYesNo(java.lang.String question)
Given a question, get a yes/no answer to it and return true/false correspondingly


getYesNo

public static boolean getYesNo(java.io.BufferedReader input,
                               java.lang.String question)

getResponse

public static java.lang.String getResponse(java.lang.String question)
Given a question, get an answer to it and return it


getResponse

public static java.lang.String getResponse(java.io.BufferedReader input,
                                           java.lang.String question)

getNumericResponse

public static int getNumericResponse(java.lang.String question)
Returns the numeric input from the user


getNumericResponse

public static int getNumericResponse(java.io.BufferedReader input,
                                     java.lang.String question)

getSelectedOption

public static java.lang.String getSelectedOption(java.io.BufferedReader input,
                                                 java.util.Vector options)
Presents the options, validates user choice and returns the choice as the ordinality of the choice


getSelectedOption

public static java.lang.String getSelectedOption(java.io.BufferedReader input,
                                                 java.lang.String[] options)

getAllSelectedOptions

public static java.util.Vector getAllSelectedOptions(java.util.Vector options)

getAllSelectedOptions

public static java.util.Vector getAllSelectedOptions(java.io.BufferedReader input,
                                                     java.util.Vector options)
Given a vector of options, lets user choose multiple options and returns the chosen options. Prevents duplicates, validates all input


printVectorIndexed

public static void printVectorIndexed(java.util.Vector text)

printVector

public static void printVector(java.lang.String header,
                               java.util.Vector text)

printAnyVector

public static void printAnyVector(java.lang.String header,
                                  java.util.Vector text)

recursivePrint

public static void recursivePrint(java.util.Vector explanation)

main

public static void main(java.lang.String[] args)