Skip to content

Commit

Permalink
Remove effectively dead code, consolidate text state checking in reader
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeEdgar committed Jul 6, 2021
1 parent f18c5ae commit b611449
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void requireEvent(String message, EDIStreamEvent... events) {
}

private CharBuffer getBuffer() {
checkTextState();
return proxy.getCharacters();
}

Expand Down Expand Up @@ -365,19 +366,13 @@ private void checkTextState() {

@Override
public String getText() {
ensureOpen();
checkTextState();
final CharBuffer buffer = getBuffer();

return buffer.toString();
}

@Override
public char[] getTextCharacters() {
ensureOpen();
checkTextState();
final CharBuffer buffer = getBuffer();

return Arrays.copyOf(buffer.array(), buffer.length());
}

Expand All @@ -387,9 +382,6 @@ public int getTextCharacters(int sourceStart,
int targetStart,
int length) {

ensureOpen();
checkTextState();

if (target == null) {
throw new NullPointerException("Null target array");
}
Expand Down Expand Up @@ -426,19 +418,13 @@ public int getTextCharacters(int sourceStart,

@Override
public int getTextStart() {
ensureOpen();
checkTextState();
final CharBuffer buffer = getBuffer();

return buffer.position();
}

@Override
public int getTextLength() {
ensureOpen();
checkTextState();
final CharBuffer buffer = getBuffer();

return buffer.limit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ public void resetEvents() {
}

public EDIStreamEvent getEvent() {
return current(StreamEvent::getType, false, null);
return current(StreamEvent::getType, null);
}

public CharBuffer getCharacters() {
return current(StreamEvent::getData, true, null);
return current(StreamEvent::getData, null);
}

public boolean nextEvent() {
Expand All @@ -132,24 +132,21 @@ public boolean nextEvent() {
}

public EDIStreamValidationError getErrorType() {
return current(StreamEvent::getErrorType, false, null);
return current(StreamEvent::getErrorType, null);
}

public String getReferenceCode() {
return current(StreamEvent::getReferenceCode, false, null);
return current(StreamEvent::getReferenceCode, null);
}

public Location getLocation() {
return current(StreamEvent::getLocation, false, this.location);
return current(StreamEvent::getLocation, this.location);
}

<T> T current(Function<StreamEvent, T> mapper, boolean required, T defaultValue) {
<T> T current(Function<StreamEvent, T> mapper, T defaultValue) {
final T value;

if (eventQueue.isEmpty()) {
if (required) {
throw new IllegalStateException();
}
value = defaultValue;
} else {
value = mapper.apply(eventQueue.getFirst());
Expand All @@ -171,7 +168,7 @@ public void setBinary(InputStream binary) {
}

public EDIReference getSchemaTypeReference() {
return current(StreamEvent::getTypeReference, false, null);
return current(StreamEvent::getTypeReference, null);
}

@Override
Expand Down

0 comments on commit b611449

Please sign in to comment.