be.SIRAPRISE.util
Class BracketParser

java.lang.Object
  extended by be.SIRAPRISE.util.BracketParser

public class BracketParser
extends java.lang.Object

Provides methods for working with bracketed expressions.

Author:
Erwin

Constructor Summary
BracketParser()
           
 
Method Summary
static java.util.LinkedList<java.lang.String> createListFromEscaped(java.lang.String s)
          Creates a HashMap for a String in the general format Name1(value1)Name2(value2)...
static java.util.LinkedList<java.lang.String> createListFromNonEscaped(java.lang.String s)
          Creates a HashMap for a String in the general format Name1(value1)Name2(value2)...
static java.util.HashMap<java.lang.String,java.lang.String> createMapFromEscaped(java.lang.String s)
          Creates a HashMap for a String in the general format Name1(value1)Name2(value2)...
static java.util.Map<java.lang.String,java.lang.String> createMapFromEscapedString(java.lang.String s, boolean emptyMapAllowed)
          Parses a bracketed String and builds a hashmap with the information contained within the (map) value is the (attribute) value, also in string format.
static java.util.HashMap<java.lang.String,java.lang.String> createMapFromNonEscaped(java.lang.String s)
          Creates a HashMap for a String in the general format Name1(value1)Name2(value2)...
static java.util.HashMap<java.lang.String,java.lang.String> createMapWithMandatoryValuesFromEscaped(java.lang.String s)
          Creates a HashMap for a String in the general format Name1(value1)Name2(value2)...
static java.util.HashMap<java.lang.String,java.lang.String> createMapWithMandatoryValuesFromNonEscaped(java.lang.String s)
          Creates a HashMap for a String in the general format Name1(value1)Name2(value2)...
static void fillMapWithMandatoryValuesFromEscaped(java.lang.String s, java.util.Map<java.lang.String,java.lang.String> attributeValueMap)
           
static void fillMapWithMandatoryValuesFromNonEscaped(java.lang.String s, java.util.Map<java.lang.String,java.lang.String> attributeValueMap)
           
static void fillNonEmptyMapWithMandatoryValuesFromEscaped(java.lang.String s, java.util.Map<java.lang.String,java.lang.String> attributeValueMap)
           
static void fillNonEmptyMapWithMandatoryValuesFromNonEscaped(java.lang.String s, java.util.Map<java.lang.String,java.lang.String> attributeValueMap)
           
static int findCorrespondingClosingBracket(java.lang.String s)
          Find the position of the closing bracket that matches the opening bracket in position 0.
static NameValueResult getNameAndMandatoryValueFromEscaped(java.lang.String s, int startPos)
          Returns the 'name' part of an expression of the form "name(content)"
static NameValueResult getNameAndMandatoryValueFromNonEscaped(java.lang.String s, int startPos)
          Returns the 'name' part of an expression of the form "name(content)"
static NameValueResult getNameAndMandatoryValueUntrimmedFromEscaped(java.lang.String s, int startPos)
          Returns the 'name' part of an expression of the form "name(content)"
static BracketParseResult getNameBeforeBracket(java.lang.String s)
          Deprecated.  
static NameValueResult getNameValueFromEscaped(java.lang.String s, int startPos)
          Returns the 'name' part of an expression of the form "name(content)"
static NameValueResult getNameValueFromNonEscaped(java.lang.String s, int startPos)
          Returns the 'name' part of an expression of the form "name(content)"
static NameValueResult getNameValueUntrimmedFromEscaped(java.lang.String s, int startPos)
          Returns the 'name' part of an expression of the form "name(content)"
static BracketParseResult getUnMetaContentsWithinBrackets(java.lang.String s)
          Deprecated.  
static BracketParseResult getUnMetaContentsWithinBracketsUntrimmed(java.lang.String s)
          Deprecated.  
static java.lang.String meta(java.lang.String s)
          Adapts a given string for representation of the siraprise metalanguage characters ()\
static java.lang.String removeSuperfluousOuterBrackets(java.lang.String arg)
          Removes superfluous outer brackets from arg. e.g.
static java.lang.String unMeta(java.lang.String s)
          Translates strings in sira_prise meta language to their actual value.
static java.lang.String unMetaWithoutException(java.lang.String s)
          Translates strings in sira_prise meta language to their actual value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BracketParser

public BracketParser()
Method Detail

createListFromEscaped

public static java.util.LinkedList<java.lang.String> createListFromEscaped(java.lang.String s)
                                                                    throws NoClosingBracketException,
                                                                           InvalidEscapedCharacterException,
                                                                           MissingEscapedCharacterException,
                                                                           NoOpeningBracketException
Creates a HashMap for a String in the general format Name1(value1)Name2(value2)... An entry is added to the map for each name in the String, and the corresponding value is the value that appears within parentheses with that name

Parameters:
s - A string in the general format name1(value1)name2(value2)...
Returns:
A hashmap holding an entry for each name(value) pair in the input text, where key=name and value=value
Throws:
MissingEscapedCharacterException
NoOpeningBracketException
InvalidEscapedCharacterException
NoClosingBracketException

createListFromNonEscaped

public static java.util.LinkedList<java.lang.String> createListFromNonEscaped(java.lang.String s)
                                                                       throws NoClosingBracketException,
                                                                              NoOpeningBracketException
Creates a HashMap for a String in the general format Name1(value1)Name2(value2)... An entry is added to the map for each name in the String, and the corresponding value is the value that appears within parentheses with that name

Parameters:
s - A string in the general format name1(value1)name2(value2)...
Returns:
A hashmap holding an entry for each name(value) pair in the input text, where key=name and value=value
Throws:
NoOpeningBracketException
NoClosingBracketException

createMapFromEscaped

public static java.util.HashMap<java.lang.String,java.lang.String> createMapFromEscaped(java.lang.String s)
                                                                                 throws NoClosingBracketException,
                                                                                        InvalidEscapedCharacterException,
                                                                                        MissingEscapedCharacterException,
                                                                                        DuplicateNameException
Creates a HashMap for a String in the general format Name1(value1)Name2(value2)... An entry is added to the map for each name in the String, and the corresponding value is the value that appears within parentheses with that name

Parameters:
s - A string in the general format name1(value1)name2(value2)...
Returns:
A hashmap holding an entry for each name(value) pair in the input text, where key=name and value=value
Throws:
InvalidEscapedCharacterException
MissingEscapedCharacterException
NoClosingBracketException
DuplicateNameException

createMapFromNonEscaped

public static java.util.HashMap<java.lang.String,java.lang.String> createMapFromNonEscaped(java.lang.String s)
                                                                                    throws NoClosingBracketException,
                                                                                           DuplicateNameException
Creates a HashMap for a String in the general format Name1(value1)Name2(value2)... An entry is added to the map for each name in the String, and the corresponding value is the value that appears within parentheses with that name

Parameters:
s - A string in the general format name1(value1)name2(value2)...
Returns:
A hashmap holding an entry for each name(value) pair in the input text, where key=name and value=value
Throws:
NoClosingBracketException
DuplicateNameException

createMapWithMandatoryValuesFromEscaped

public static java.util.HashMap<java.lang.String,java.lang.String> createMapWithMandatoryValuesFromEscaped(java.lang.String s)
                                                                                                    throws DuplicateNameException,
                                                                                                           NoClosingBracketException,
                                                                                                           InvalidEscapedCharacterException,
                                                                                                           MissingEscapedCharacterException,
                                                                                                           NoOpeningBracketException
Creates a HashMap for a String in the general format Name1(value1)Name2(value2)... An entry is added to the map for each name in the String, and the corresponding value is the value that appears within parentheses with that name

Parameters:
s - A string in the general format name1(value1)name2(value2)...
Returns:
A hashmap holding an entry for each name(value) pair in the input text, where key=name and value=value
Throws:
DuplicateNameException
NoClosingBracketException
InvalidEscapedCharacterException
MissingEscapedCharacterException
NoOpeningBracketException

createMapWithMandatoryValuesFromNonEscaped

public static java.util.HashMap<java.lang.String,java.lang.String> createMapWithMandatoryValuesFromNonEscaped(java.lang.String s)
                                                                                                       throws DuplicateNameException,
                                                                                                              NoClosingBracketException,
                                                                                                              NoOpeningBracketException
Creates a HashMap for a String in the general format Name1(value1)Name2(value2)... An entry is added to the map for each name in the String, and the corresponding value is the value that appears within parentheses with that name

Parameters:
s - A string in the general format name1(value1)name2(value2)...
Returns:
A hashmap holding an entry for each name(value) pair in the input text, where key=name and value=value
Throws:
DuplicateNameException
NoClosingBracketException
NoOpeningBracketException

fillMapWithMandatoryValuesFromEscaped

public static void fillMapWithMandatoryValuesFromEscaped(java.lang.String s,
                                                         java.util.Map<java.lang.String,java.lang.String> attributeValueMap)
                                                  throws NoClosingBracketException,
                                                         InvalidEscapedCharacterException,
                                                         MissingEscapedCharacterException,
                                                         NoOpeningBracketException,
                                                         DuplicateNameException
Parameters:
s -
attributeValueMap -
Throws:
NoClosingBracketException
InvalidEscapedCharacterException
MissingEscapedCharacterException
NoOpeningBracketException
DuplicateNameException

fillMapWithMandatoryValuesFromNonEscaped

public static void fillMapWithMandatoryValuesFromNonEscaped(java.lang.String s,
                                                            java.util.Map<java.lang.String,java.lang.String> attributeValueMap)
                                                     throws NoClosingBracketException,
                                                            NoOpeningBracketException,
                                                            DuplicateNameException
Parameters:
s -
attributeValueMap -
Throws:
NoClosingBracketException
NoOpeningBracketException
DuplicateNameException

fillNonEmptyMapWithMandatoryValuesFromEscaped

public static void fillNonEmptyMapWithMandatoryValuesFromEscaped(java.lang.String s,
                                                                 java.util.Map<java.lang.String,java.lang.String> attributeValueMap)
                                                          throws NoClosingBracketException,
                                                                 InvalidEscapedCharacterException,
                                                                 MissingEscapedCharacterException,
                                                                 NoOpeningBracketException,
                                                                 DuplicateNameException
Parameters:
s -
attributeValueMap -
Throws:
DuplicateNameException
NoOpeningBracketException
MissingEscapedCharacterException
InvalidEscapedCharacterException
NoClosingBracketException

fillNonEmptyMapWithMandatoryValuesFromNonEscaped

public static void fillNonEmptyMapWithMandatoryValuesFromNonEscaped(java.lang.String s,
                                                                    java.util.Map<java.lang.String,java.lang.String> attributeValueMap)
                                                             throws NoClosingBracketException,
                                                                    NoOpeningBracketException,
                                                                    DuplicateNameException
Parameters:
s -
attributeValueMap -
Throws:
DuplicateNameException
NoOpeningBracketException
NoClosingBracketException

findCorrespondingClosingBracket

public static int findCorrespondingClosingBracket(java.lang.String s)
                                           throws NoClosingBracketException
Find the position of the closing bracket that matches the opening bracket in position 0. It is assumed that the input indeed starts with an opening bracket, otherwise there obviously is no need for calling this method in the first place.

Parameters:
s - A String holding a bracketed expression that begins with an opening bracket
Returns:
the position in the String that holds the closing bracket that corresponds to the opening bracket in position 0. -1 if there is no such closing bracket, or the String does not start with an opening bracket.
Throws:
NoClosingBracketException

getNameAndMandatoryValueFromEscaped

public static NameValueResult getNameAndMandatoryValueFromEscaped(java.lang.String s,
                                                                  int startPos)
                                                           throws NoClosingBracketException,
                                                                  InvalidEscapedCharacterException,
                                                                  MissingEscapedCharacterException,
                                                                  NoOpeningBracketException
Returns the 'name' part of an expression of the form "name(content)"

Parameters:
s - a string of the general form name(content)
startPos - The first position in s to inspect for the name, in the range [0...length-1]
Returns:
the name of the object that the command refers to
Throws:
NoClosingBracketException
InvalidEscapedCharacterException
MissingEscapedCharacterException
NoOpeningBracketException

getNameAndMandatoryValueFromNonEscaped

public static NameValueResult getNameAndMandatoryValueFromNonEscaped(java.lang.String s,
                                                                     int startPos)
                                                              throws NoClosingBracketException,
                                                                     NoOpeningBracketException
Returns the 'name' part of an expression of the form "name(content)"

Parameters:
s - a string of the general form name(content)
startPos - The first position in s to inspect for the name, in the range [0...length-1]
Returns:
the name of the object that the command refers to
Throws:
NoClosingBracketException
NoOpeningBracketException

getNameAndMandatoryValueUntrimmedFromEscaped

public static NameValueResult getNameAndMandatoryValueUntrimmedFromEscaped(java.lang.String s,
                                                                           int startPos)
                                                                    throws NoClosingBracketException,
                                                                           InvalidEscapedCharacterException,
                                                                           MissingEscapedCharacterException,
                                                                           NoOpeningBracketException
Returns the 'name' part of an expression of the form "name(content)"

Parameters:
s - a string of the general form name(content)
startPos - The first position in s to inspect for the name, in the range [0...length-1]
Returns:
the name of the object that the command refers to
Throws:
NoClosingBracketException
InvalidEscapedCharacterException
MissingEscapedCharacterException
NoOpeningBracketException

getNameBeforeBracket

public static BracketParseResult getNameBeforeBracket(java.lang.String s)
                                               throws NoOpeningBracketException
Deprecated. 

Returns the 'name' part of an expression of the form "name(content)"

Parameters:
s - a string of the general form name(content)
Returns:
the name of the object that the command refers to
Throws:
NoOpeningBracketException

getNameValueFromEscaped

public static NameValueResult getNameValueFromEscaped(java.lang.String s,
                                                      int startPos)
                                               throws NoClosingBracketException,
                                                      InvalidEscapedCharacterException,
                                                      MissingEscapedCharacterException
Returns the 'name' part of an expression of the form "name(content)"

Parameters:
s - a string of the general form name(content)
startPos - The first position in s to inspect for the name, in the range [0...length-1]
Returns:
the name of the object that the command refers to
Throws:
NoClosingBracketException
InvalidEscapedCharacterException
MissingEscapedCharacterException

getNameValueFromNonEscaped

public static NameValueResult getNameValueFromNonEscaped(java.lang.String s,
                                                         int startPos)
                                                  throws NoClosingBracketException
Returns the 'name' part of an expression of the form "name(content)"

Parameters:
s - a string of the general form name(content)
startPos - The first position in s to inspect for the name, in the range [0...length-1]
Returns:
the name of the object that the command refers to
Throws:
NoClosingBracketException

getNameValueUntrimmedFromEscaped

public static NameValueResult getNameValueUntrimmedFromEscaped(java.lang.String s,
                                                               int startPos)
                                                        throws NoClosingBracketException,
                                                               InvalidEscapedCharacterException,
                                                               MissingEscapedCharacterException
Returns the 'name' part of an expression of the form "name(content)"

Parameters:
s - a string of the general form name(content)
startPos - The first position in s to inspect for the name, in the range [0...length-1]
Returns:
the name of the object that the command refers to
Throws:
NoClosingBracketException
InvalidEscapedCharacterException
MissingEscapedCharacterException

getUnMetaContentsWithinBrackets

public static BracketParseResult getUnMetaContentsWithinBrackets(java.lang.String s)
                                                          throws NoOpeningBracketException,
                                                                 NoClosingBracketException,
                                                                 InvalidEscapedCharacterException,
                                                                 MissingEscapedCharacterException
Deprecated. 

An arbitrary string, presumed to be of the form 'somename(somecontent)somethingelse'. The 'somecontent' part is returned in a bracketparseresult object, along with the number of parsed characters + 1. The number thus represents the index in the input string of the first unparsed character.

Parameters:
s - the input string
Returns:
A BracketParseResult object holding the number of parsed characeters, and the string value that appears between the first opening bracket found in the input string and its corresponding closing bracket. The number of characters parsed includes the closing bracket.
Throws:
NoOpeningBracketException
NoClosingBracketException
MissingEscapedCharacterException
InvalidEscapedCharacterException

getUnMetaContentsWithinBracketsUntrimmed

public static BracketParseResult getUnMetaContentsWithinBracketsUntrimmed(java.lang.String s)
                                                                   throws NoOpeningBracketException,
                                                                          NoClosingBracketException,
                                                                          InvalidEscapedCharacterException,
                                                                          MissingEscapedCharacterException
Deprecated. 

An arbitrary string, presumed to be of the form 'somename(somecontent)somethingelse'. The 'somecontent' part is trimmed and then returned in a bracketparseresult object, along with the number of parsed characters + 1. The number thus represents the index in the input string of the first unparsed character.

Parameters:
s - the input string
Returns:
A BracketParseResult object holding the number of parsed characeters, and the string value that appears between the first opening bracket found in the input string and its corresponding closing bracket. The number of characters parsed includes the closing bracket.
Throws:
NoOpeningBracketException
NoClosingBracketException
MissingEscapedCharacterException
InvalidEscapedCharacterException

meta

public static java.lang.String meta(java.lang.String s)
Adapts a given string for representation of the siraprise metalanguage characters ()\

Parameters:
s - The string to be adapted for representation of the siraprise metalanguage characters ()\
Returns:
The string s, adapted for representation of the siraprise metalanguage characters ()\

removeSuperfluousOuterBrackets

public static java.lang.String removeSuperfluousOuterBrackets(java.lang.String arg)
Removes superfluous outer brackets from arg. e.g. (A) will return A, whereas (A)(B) will return its input.

Parameters:
arg - The argument from which superfluous outer brackets are to be removed
Returns:
The argument, with all its superfluous outer brackets removed.

unMeta

public static java.lang.String unMeta(java.lang.String s)
                               throws InvalidEscapedCharacterException,
                                      MissingEscapedCharacterException
Translates strings in sira_prise meta language to their actual value. This means any occurence of '\\' is replaced by '\', '\(' by '(' and '\)' by ')'

Parameters:
s - The string to be un-meta-ified
Returns:
The un-meta-ified string
Throws:
InvalidEscapedCharacterException
MissingEscapedCharacterException

unMetaWithoutException

public static java.lang.String unMetaWithoutException(java.lang.String s)
Translates strings in sira_prise meta language to their actual value. This means any occurence of '\\' is replaced by '\', '\(' by '(' and '\)' by ')'. Invalid escape sequences in the string argument result in an IllegalArgumentException.

Parameters:
s - The string to be un-meta-ified
Returns:
The un-meta-ified string

createMapFromEscapedString

public static java.util.Map<java.lang.String,java.lang.String> createMapFromEscapedString(java.lang.String s,
                                                                                          boolean emptyMapAllowed)
                                                                                   throws NoClosingBracketException,
                                                                                          InvalidEscapedCharacterException,
                                                                                          MissingEscapedCharacterException,
                                                                                          NoOpeningBracketException,
                                                                                          DuplicateNameException
Parses a bracketed String and builds a hashmap with the information contained within the (map) value is the (attribute) value, also in string format.

Parameters:
s - The textual representation of a bracketed expression
emptyMapAllowed - true if the result is not expected to contain at least one entry
Returns:
An attributevaluemap containing attribute name/value pairs. The key is the name in string format,
Throws:
DuplicateNameException
NoOpeningBracketException
MissingEscapedCharacterException
InvalidEscapedCharacterException
NoClosingBracketException