-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from techatpark/perf-prep
merge Perf prep to develop
- Loading branch information
Showing
19 changed files
with
950 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.techatpark.sjson.core; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static com.techatpark.sjson.core.util.ReaderUtil.getCharacter; | ||
|
||
public final class ArrayParser { | ||
|
||
/** | ||
* util classes. | ||
*/ | ||
private ArrayParser() { | ||
} | ||
|
||
/** | ||
* Reades an Array. Reader stops at next clean character. | ||
* @param reader | ||
* @param contentExtractor | ||
* @return list | ||
* @throws IOException | ||
*/ | ||
public static List<Object> getArray(final Reader reader, | ||
final Json.ContentExtractor | ||
contentExtractor) throws IOException { | ||
final Object value = contentExtractor.getValue(); | ||
// If not Empty Array | ||
if (value == contentExtractor) { | ||
contentExtractor.moveCursorToNextClean(); | ||
return Collections.emptyList(); | ||
} | ||
final List<Object> list = new ArrayList<>(); | ||
list.add(value); | ||
while (!endOfArray(reader, contentExtractor)) { | ||
list.add(contentExtractor.getValue()); | ||
} | ||
contentExtractor.moveCursorToNextClean(); | ||
return list; | ||
} | ||
/** | ||
* Determine array close character. | ||
* @param reader | ||
* @param contentExtractor | ||
* @return flag | ||
* @throws IOException | ||
*/ | ||
private static boolean endOfArray(final Reader reader, | ||
final Json.ContentExtractor | ||
contentExtractor) throws IOException { | ||
char character; | ||
if (contentExtractor.getCursor() == ',') { | ||
return false; | ||
} | ||
if (contentExtractor.getCursor() == ']') { | ||
return true; | ||
} | ||
|
||
while ((character = getCharacter(reader.read())) != ',' | ||
&& character != ']') { | ||
continue; | ||
} | ||
return character == ']'; | ||
} | ||
|
||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/com/techatpark/sjson/core/BooleanParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.techatpark.sjson.core; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
|
||
import static com.techatpark.sjson.core.util.ReaderUtil.ILLEGAL_JSON_VALUE; | ||
import static com.techatpark.sjson.core.util.ReaderUtil.next; | ||
|
||
/** | ||
* Boolean Parser. | ||
* */ | ||
|
||
public final class BooleanParser { | ||
|
||
/** | ||
* This is for length. | ||
*/ | ||
public static final int THREE = 3; | ||
/** | ||
* This is for length. | ||
*/ | ||
public static final int FOUR = 4; | ||
|
||
/** | ||
* util classes. | ||
*/ | ||
private BooleanParser() { | ||
|
||
} | ||
/** | ||
* Reads True from Reader. Reader will stip at the "e" symbol. | ||
* @param reader | ||
* @return string | ||
* @throws IOException | ||
*/ | ||
public static boolean getTrue(final Reader reader) throws IOException { | ||
char[] charBuffer = next(reader, THREE); | ||
if (charBuffer[0] == 'r' | ||
&& charBuffer[1] == 'u' | ||
&& charBuffer[2] == 'e') { | ||
// cursor = 'e'; | ||
return true; | ||
} else { | ||
throw new IllegalArgumentException(ILLEGAL_JSON_VALUE); | ||
} | ||
} | ||
/** | ||
* Reads False from Reader. Reader will strip at the "e" symbol. | ||
* @param reader | ||
* @return string | ||
* @throws IOException | ||
*/ | ||
public static boolean getFalse(final Reader reader) throws IOException { | ||
char[] charBuffer = next(reader, FOUR); | ||
if (charBuffer[0] == 'a' | ||
&& charBuffer[1] == 'l' | ||
&& charBuffer[2] == 's' | ||
&& charBuffer[THREE] == 'e') { | ||
// cursor = 'e'; | ||
return false; | ||
} else { | ||
throw new IllegalArgumentException(ILLEGAL_JSON_VALUE); | ||
} | ||
} | ||
} |
Oops, something went wrong.