public final class ToHashMap<E> extends Object implements JSONParseListener
HashMap
.
This is preferable to new HashMap(new JSONObject(string))
if a Reader
has to be used in the parser, for example,
due to a huge file that would cause an OutOfMemoryError
if
attempted to turned into a String. Or, just because the JSONObject
is
just unwanted.HashMap
Constructor and Description |
---|
ToHashMap(JSONDecoder<E> decoder) |
Modifier and Type | Method and Description |
---|---|
boolean |
abort()
returns false.
|
static ToHashMap<Object> |
apply()
Creates a ToHashMap using a
ToJavaCollectionJSONDecoder decoder |
static <E> ToHashMap<E> |
apply(JSONDecoder<E> decoder) |
void |
charRead(int index,
char character)
Reads the given character
|
void |
elemEnded(int commaIndex,
char character)
An element has ended
|
void |
elemStarted(int commaIndex,
char character)
An element has started
|
void |
ended()
Called when the parsing ends.
|
void |
endingBracket(int index,
char character)
The level has changed
|
HashMap<String,E> |
getResult()
returns the generated HashMap
|
void |
keyValueSeparation(int colonIndex,
char character)
A key has ended and a value has started
|
void |
openingBracket(int index,
char character)
Indicates that the initial bracket has been reached
|
void |
started()
Called when the parsing starts.
|
public ToHashMap(JSONDecoder<E> decoder)
public static ToHashMap<Object> apply()
ToJavaCollectionJSONDecoder
decoderpublic static <E> ToHashMap<E> apply(JSONDecoder<E> decoder)
public boolean abort()
abort
in interface JSONParseListener
public void charRead(int index, char character) throws IllegalStateException
charRead
in interface JSONParseListener
index
- the index of he character that was readcharacter
- the character to readIllegalStateException
- if the parser is in an inappropriate place to red characterspublic void elemStarted(int commaIndex, char character) throws IllegalStateException
JSONParseListener
elemStarted
in interface JSONParseListener
commaIndex
- the index of the commacharacter
- the character that started the elementIllegalStateException
- if this is called before started or between started and endedpublic void elemEnded(int commaIndex, char character) throws IllegalStateException, ParseException
JSONParseListener
elemEnded
in interface JSONParseListener
commaIndex
- the index of the commacharacter
- the character that ended the elementIllegalStateException
- if this is called before started or between started and endedParseException
- if there was a problem with the elementpublic void openingBracket(int index, char character) throws IllegalStateException, ParseException
JSONParseListener
openingBracket
in interface JSONParseListener
index
- the location of the bracketcharacter
- the bracket characterIllegalStateException
- if this is called before started or between started and endedParseException
- if there bracket was the wrong onepublic void endingBracket(int index, char character) throws IllegalStateException, ParseException
JSONParseListener
endingBracket
in interface JSONParseListener
index
- the location of the changecharacter
- the character used in the changeIllegalStateException
- if this is called before started or between started and endedParseException
- if there bracket was the wrong onepublic void keyValueSeparation(int colonIndex, char character) throws IllegalStateException, ParseException
JSONParseListener
keyValueSeparation
in interface JSONParseListener
colonIndex
- the index of the commacharacter
- the character that split the elementIllegalStateException
- if this is called before started or between started and endedParseException
- if there was a problem with the keypublic void started() throws IllegalStateException
JSONParseListener
started
in interface JSONParseListener
IllegalStateException
- if this is called before started or between started and endedpublic void ended()
JSONParseListener
ended
in interface JSONParseListener