Skip to content

Commit

Permalink
More idiomatic JSON usage
Browse files Browse the repository at this point in the history
The selenium json helper classes provide mechanisms for serialising
and deserialising. Use these in preference to helper methods.
  • Loading branch information
dratler authored and shs96c committed Jun 6, 2019
1 parent 516a24b commit 02817a2
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ private static ConsoleProfileFinished fromJson(JsonInput input) {
while (input.hasNext()) {
switch (input.nextName()) {
case "location":
location = Location.fromJson(input);
location = input.read(Location.class);
break;
case "profile":
profile = Profile.fromJson(input);
profile = input.read(Profile.class);
break;
case "title":
title = input.nextString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static ConsoleProfileStarted fromJson(JsonInput input) {
while (input.hasNext()) {
switch (input.nextName()) {
case "location":
location = Location.fromJson(input);
location = input.read(Location.class);
break;
case "title":
title = input.nextString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CoverageRange(int startOffset, int endOffset, int count) {
this.count = count;
}

static CoverageRange fromJson(JsonInput input) {
private static CoverageRange fromJson(JsonInput input) {
int startOffset = 0;
int endOffset = 0;
int count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public FunctionCoverage(String functionName,
this.isBlockCoverage = isBlockCoverage;
}

public static FunctionCoverage fromJson(JsonInput input) {
private static FunctionCoverage fromJson(JsonInput input) {

String functionName = null;
List<CoverageRange> ranges = null;
Expand All @@ -64,7 +64,7 @@ public static FunctionCoverage fromJson(JsonInput input) {
ranges = new ArrayList<>();
input.beginArray();
while (input.hasNext()) {
ranges.add(CoverageRange.fromJson(input));
ranges.add(input.read(CoverageRange.class));
}
input.endArray();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Location(String scriptId, int lineNumber, Integer columnNumber) {
this.columnNumber = columnNumber;
}

public static Location fromJson(JsonInput input) {
private static Location fromJson(JsonInput input) {
String scriptId = input.nextString();
int lineNumber = -1;
Integer columnNumber = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public PositionTickInfo(int line, int ticks) {
this.ticks = ticks;
}

static PositionTickInfo fromJson(JsonInput input) {
private static PositionTickInfo fromJson(JsonInput input) {
int line = input.read(Integer.class);
int ticks = 0;
while (input.hasNext()) {
Expand All @@ -66,7 +66,9 @@ public int getTicks() {

@Override
public boolean equals(Object obj) {
Objects.requireNonNull(obj, "obj is mandatory for equals method");
if (null == obj || !(obj instanceof PositionTickInfo)) {
return false;
}

return this.getLine() == ((PositionTickInfo) obj).getLine()
&& this.getTicks() == ((PositionTickInfo) obj).getTicks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public List<ProfileNode> getNodes() {
return nodes;
}

static Profile fromJson(JsonInput input) {
private static Profile fromJson(JsonInput input) {
List<ProfileNode> nodes = null;
Instant startTime = null;
Instant endTime = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static ProfileNode fromJson(JsonInput input) {
positionTicks = new ArrayList<>();
input.beginArray();
while (input.hasNext()) {
positionTicks.add(PositionTickInfo.fromJson(input));
positionTicks.add(input.read(PositionTickInfo.class));
}
input.endArray();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static ScriptCoverage parse(JsonInput input) {
functionCoverages = new ArrayList<>();
input.beginArray();
while (input.hasNext()) {
functionCoverages.add(FunctionCoverage.fromJson(input));
functionCoverages.add(input.read(FunctionCoverage.class));
}
input.endArray();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ScriptTypeProfile {

public ScriptTypeProfile(String scriptId, String url,
List<TypeProfileEntry> entries) {
validateEntrie(entries);
validateEntries(entries);
Objects.requireNonNull(url, "url is require");
Objects.requireNonNull(scriptId, "scriptId is require");

Expand All @@ -68,7 +68,7 @@ private static ScriptTypeProfile fromJson(JsonInput input) {
entries = new ArrayList<>();
input.beginArray();
while (input.hasNext()) {
entries.add(TypeProfileEntry.fromJson(input));
entries.add(input.read(ScriptTypeProfile.class));
}
input.endArray();
break;
Expand All @@ -92,8 +92,7 @@ public List<TypeProfileEntry> getEntries() {
return entries;
}

public void validateEntrie(
List<TypeProfileEntry> entries) {
private void validateEntries(List<TypeProfileEntry> entries) {
Objects.requireNonNull(entries, "entries are require");
if (entries.isEmpty()) {
throw new DevToolsException("entries are require");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public TypeObject(String name) {
this.name = name;
}

static TypeObject fromJson(JsonInput input) {
private static TypeObject fromJson(JsonInput input) {
return new TypeObject(input.nextString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static TypeProfileEntry fromJson(JsonInput input) {
types = new ArrayList<>();
input.beginArray();
while (input.hasNext()) {
types.add(TypeObject.fromJson(input));
types.add(input.read(TypeObject.class));
}
input.endArray();
break;
Expand Down

0 comments on commit 02817a2

Please sign in to comment.