|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectutil.TextParser
public class TextParser
Collection of basic string formatting operations. These have the purpose of simplifying the use and creation of human readable configuration files. Each operation has both an encode and decode version. Decoding renders text into usable data structures while encoding reverts it back into a human readable form. These are simple tools, not meant for heavy operations (most running in O(n) time).
Method Summary | |
---|---|
static LinkedHashMap<String,String> |
decodeLabels(List<String> text,
String divider)
Parses each line of text for a sentinel, associating the text before the first instance to the text after in a mapping. |
static ArrayList<String> |
decodeLineDivisions(String str,
String divider)
Takes a line of text and parses a list of segments divided by a token (excluding the divider itself). |
static ArrayList<ArrayList<String>> |
decodeSubsections(List<String> text,
String divider)
Separates text into its subsections based upon a given sentinel. |
static ArrayList<String> |
encodeLabels(Map<String,String> data,
String divider)
Collapses mappings of text into a single listing of key and value divided by a specified sentinel. |
static String |
encodeLineDivisions(List<String> text,
String divider)
Provides a list of text as a single string with elements divided by a given delimiter. |
static ArrayList<String> |
encodeSubsections(List<ArrayList<String>> data,
String divider)
Collapses lists of text into a single section, dividing segments with a specified sentinel. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static LinkedHashMap<String,String> decodeLabels(List<String> text, String divider)
Location: Wonderland Climate: Funky Population: 426 Species: 426 Climate: Especially Funky The divider is: ': ' // Entry has multiple instances of divider. Blank Entry: // Entry has a space after the colon. Other Notes: // Entry ends with the colon. Includes the devouring of many 'magic' substances.would return a mapping:
Index 0: ("Location" -> "Wonderland") Index 1: ("Climate" -> "Especially Funky") Index 2: ("Population" -> "426") Index 3: ("Species" -> "426") Index 4: ("The divider is" -> "': '") Index 5: ("Blank Entry" -> "") Index 6: ("Other Notes:" -> null) Index 7: ("Includes the devouring of many 'magic' substances." -> null)
text
- text to be parseddivider
- sentinel on which to divide mapped key and value
IllegalArgumentException
- if divider is an empty stringpublic static ArrayList<String> encodeLabels(Map<String,String> data, String divider)
data
- text mapping to be collapseddivider
- sentinel used to divide keys and values
public static ArrayList<ArrayList<String>> decodeSubsections(List<String> text, String divider)
Name: Alice Age: 15 ----- Name: White Rabbit Age: 6 Quote: 'I'm late! I'm Late!' ----- ----- Name: Mad Hatter Age: 22 Divider is '-----' -----would return a list:
Index 0: ("Name: Alice", "Age: 15") Index 1: ("Name: White Rabbit", "Age: 6", "Quote: 'I'm late! I'm Late!'", "") Index 2: () Index 3: ("Name: Mad Hatter", "Age: 22", "Divider is '-----'") Index 4: ()
text
- text to be parseddivider
- sentinels on which to break text
public static ArrayList<String> encodeSubsections(List<ArrayList<String>> data, String divider)
data
- divided list of text to be collapseddivider
- sentinels used to divide text (excluded if null)
public static ArrayList<String> decodeLineDivisions(String str, String divider)
str
- text to be parseddivider
- token to break segments on
IllegalArgumentException
- if divider is an empty stringpublic static String encodeLineDivisions(List<String> text, String divider)
Index 0: "`What a curious feeling!' " Index 1: "said Alice; `I must be " Index 2: "shutting up like a telescope.'"would return:
"`What a curious feeling!' said Alice; `I must be shutting up like a telescope.'"
text
- text to be parseddivider
- delimiter used to divide text
IllegalArgumentException
- if text is empty
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |