Skip to content

Commit

Permalink
Add unit tests; resolve warnings; clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeEdgar committed Sep 3, 2019
1 parent fba49f7 commit 4ce4ed0
Show file tree
Hide file tree
Showing 17 changed files with 1,441 additions and 1,118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,19 @@ public static EDIInputFactory newFactory(String factoryId,
return FactoryFinder.newInstance(factoryId, classLoader, false);
}

public abstract EDIStreamReader createEDIStreamReader(InputStream stream)
throws EDIStreamException;
public abstract EDIStreamReader createEDIStreamReader(InputStream stream) throws EDIStreamException;

public abstract EDIStreamReader createEDIStreamReader(InputStream stream,
String encoding) throws EDIStreamException;

public abstract EDIStreamReader createEDIStreamReader(InputStream stream,
Schema schema) throws EDIStreamException;
public abstract EDIStreamReader createEDIStreamReader(InputStream stream, Schema schema) throws EDIStreamException;

public abstract EDIStreamReader createEDIStreamReader(InputStream stream,
String encoding,
Schema schema) throws EDIStreamException;

public abstract EDIStreamReader createFilteredReader(
EDIStreamReader reader,
EDIStreamFilter filter)
throws EDIStreamException;
public abstract EDIStreamReader createFilteredReader(EDIStreamReader reader,
EDIStreamFilter filter) throws EDIStreamException;

/**
* Query the set of properties that this factory supports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class StaEDIFilteredStreamReader implements EDIStreamReader {
private final EDIStreamFilter filter;
private EDIStreamEvent peekEvent = null;

public StaEDIFilteredStreamReader(
EDIStreamReader delegate,
EDIStreamFilter filter) {
super();
public StaEDIFilteredStreamReader(EDIStreamReader delegate, EDIStreamFilter filter) {
this.delegate = delegate;
this.filter = filter;
}
Expand Down Expand Up @@ -144,13 +141,11 @@ public char[] getTextCharacters() {
}

@Override
public int getTextCharacters(
int sourceStart,
public int getTextCharacters(int sourceStart,
char[] target,
int targetStart,
int length) {
return delegate.getTextCharacters(
sourceStart,
return delegate.getTextCharacters(sourceStart,
target,
targetStart,
length);
Expand Down
152 changes: 71 additions & 81 deletions staedi-impl/src/main/java/io/xlate/edi/stream/StaEDIInputFactory.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*******************************************************************************
* Copyright 2017 xlate.io LLC, http://www.xlate.io
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
Expand All @@ -25,78 +25,68 @@

public class StaEDIInputFactory extends EDIInputFactory {

private static final String DEFAULT_ENCODING = "US-ASCII";

private final Set<String> supportedCharsets;
private final Map<String, Object> properties;
private final Set<String> supportedProperties;

public StaEDIInputFactory() {
properties = new HashMap<>();
supportedProperties = new HashSet<>();
supportedCharsets = new HashSet<>();
supportedCharsets.add(DEFAULT_ENCODING);
//supportedCharsets.add("UTF-8");
}

@Override
public EDIStreamReader createEDIStreamReader(InputStream stream)
throws EDIStreamException {
return new StaEDIStreamReader(stream, DEFAULT_ENCODING, properties);
}

@Override
public EDIStreamReader createEDIStreamReader(InputStream stream,
String encoding) throws EDIStreamException {
if (!supportedCharsets.contains(encoding)) {
throw new EDIStreamException("Unsupported encoding: " + encoding);
}
return new StaEDIStreamReader(stream, encoding, properties);
}

@Override
public EDIStreamReader createEDIStreamReader(InputStream stream,
Schema schema) throws EDIStreamException {
return new StaEDIStreamReader(stream, DEFAULT_ENCODING, schema, properties);
}

@Override
public EDIStreamReader createEDIStreamReader(InputStream stream,
String encoding, Schema schema) throws EDIStreamException {
if (!supportedCharsets.contains(encoding)) {
throw new EDIStreamException("Unsupported encoding: " + encoding);
}
return new StaEDIStreamReader(stream, encoding, schema, properties);
}

@Override
public EDIStreamReader createFilteredReader(EDIStreamReader reader,
EDIStreamFilter filter) throws EDIStreamException {
return new StaEDIFilteredStreamReader(reader, filter);
}

@Override
public boolean isPropertySupported(String name) {
return supportedProperties.contains(name);
}

@Override
public Object getProperty(String name) throws IllegalArgumentException {
if (!isPropertySupported(name)) {
throw new IllegalArgumentException("Unsupported property: " + name);
}

return properties.get(name);
}

@Override
public void setProperty(String name, Object value)
throws IllegalArgumentException {

if (!isPropertySupported(name)) {
throw new IllegalArgumentException("Unsupported property: " + name);
}

properties.put(name, value);
}
private static final String DEFAULT_ENCODING = "US-ASCII";

private final Set<String> supportedCharsets;
private final Map<String, Object> properties;
private final Set<String> supportedProperties;

public StaEDIInputFactory() {
properties = new HashMap<>();
supportedProperties = new HashSet<>();
supportedCharsets = new HashSet<>();
supportedCharsets.add(DEFAULT_ENCODING);
}

@Override
public EDIStreamReader createEDIStreamReader(InputStream stream) throws EDIStreamException {
return createEDIStreamReader(stream, DEFAULT_ENCODING, null);
}

@Override
public EDIStreamReader createEDIStreamReader(InputStream stream, String encoding) throws EDIStreamException {
return createEDIStreamReader(stream, encoding, null);
}

@Override
public EDIStreamReader createEDIStreamReader(InputStream stream, Schema schema) throws EDIStreamException {
return createEDIStreamReader(stream, DEFAULT_ENCODING, schema);
}

@Override
public EDIStreamReader createEDIStreamReader(InputStream stream, String encoding, Schema schema) throws EDIStreamException {
if (supportedCharsets.contains(encoding)) {
return new StaEDIStreamReader(stream, encoding, schema, properties);
}

throw new EDIStreamException("Unsupported encoding: " + encoding);
}

@Override
public EDIStreamReader createFilteredReader(EDIStreamReader reader, EDIStreamFilter filter) throws EDIStreamException {
return new StaEDIFilteredStreamReader(reader, filter);
}

@Override
public boolean isPropertySupported(String name) {
return supportedProperties.contains(name);
}

@Override
public Object getProperty(String name) {
if (!isPropertySupported(name)) {
throw new IllegalArgumentException("Unsupported property: " + name);
}

return properties.get(name);
}

@Override
public void setProperty(String name, Object value) {
if (!isPropertySupported(name)) {
throw new IllegalArgumentException("Unsupported property: " + name);
}

properties.put(name, value);
}
}
145 changes: 70 additions & 75 deletions staedi-impl/src/main/java/io/xlate/edi/stream/StaEDIOutputFactory.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*******************************************************************************
* Copyright 2017 xlate.io LLC, http://www.xlate.io
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
Expand All @@ -23,72 +23,67 @@

public class StaEDIOutputFactory extends EDIOutputFactory {

public static final String PRETTY_PRINT = "io.xlate.edi.stream.prettyPrint";

private final Set<String> supportedCharsets;
private final Set<String> supportedProperties;
private final Map<String, Object> properties;

public StaEDIOutputFactory() {
supportedCharsets = new HashSet<>();
supportedCharsets.add("US-ASCII");

supportedProperties = new HashSet<>();
supportedProperties.add(EDIStreamConstants.Delimiters.SEGMENT);
supportedProperties.add(EDIStreamConstants.Delimiters.DATA_ELEMENT);
supportedProperties.add(EDIStreamConstants.Delimiters.COMPONENT_ELEMENT);
supportedProperties.add(EDIStreamConstants.Delimiters.REPETITION);
supportedProperties.add(EDIStreamConstants.Delimiters.RELEASE);

supportedProperties.add(PRETTY_PRINT);

properties = new HashMap<>();
properties.put(PRETTY_PRINT, Boolean.FALSE);
}

@Override
public EDIStreamWriter createEDIStreamWriter(OutputStream stream)
throws EDIStreamException {
return new StaEDIStreamWriter(stream, properties);
}

@Override
public EDIStreamWriter createEDIStreamWriter(OutputStream stream,
String encoding) throws EDIStreamException {
if (!supportedCharsets.contains(encoding)) {
throw new EDIStreamException("Unsupported encoding: " + encoding);
}
return new StaEDIStreamWriter(stream, encoding, properties);
}

@Override
public boolean isPropertySupported(String name) {
return supportedProperties.contains(name);
}

@Override
public Object getProperty(String name) throws IllegalArgumentException {
if (!isPropertySupported(name)) {
throw new IllegalArgumentException("Unsupported property: " + name);
}

return properties.get(name);
}

@Override
public void setProperty(String name, Object value)
throws IllegalArgumentException {

if (!isPropertySupported(name)) {
throw new IllegalArgumentException("Unsupported property: " + name);
}

if (PRETTY_PRINT.equals(name)) {
if (!(value instanceof Boolean)) {
throw new IllegalArgumentException(name + " must be Boolean");
}
}

properties.put(name, value);
}
public static final String PRETTY_PRINT = "io.xlate.edi.stream.prettyPrint";
private static final String DEFAULT_ENCODING = "US-ASCII";

private final Set<String> supportedCharsets;
private final Set<String> supportedProperties;
private final Map<String, Object> properties;

public StaEDIOutputFactory() {
supportedCharsets = new HashSet<>();
supportedCharsets.add(DEFAULT_ENCODING);

supportedProperties = new HashSet<>();
supportedProperties.add(EDIStreamConstants.Delimiters.SEGMENT);
supportedProperties.add(EDIStreamConstants.Delimiters.DATA_ELEMENT);
supportedProperties.add(EDIStreamConstants.Delimiters.COMPONENT_ELEMENT);
supportedProperties.add(EDIStreamConstants.Delimiters.REPETITION);
supportedProperties.add(EDIStreamConstants.Delimiters.RELEASE);

supportedProperties.add(PRETTY_PRINT);

properties = new HashMap<>();
properties.put(PRETTY_PRINT, Boolean.FALSE);
}

@Override
public EDIStreamWriter createEDIStreamWriter(OutputStream stream) throws EDIStreamException {
return createEDIStreamWriter(stream, DEFAULT_ENCODING);
}

@Override
public EDIStreamWriter createEDIStreamWriter(OutputStream stream, String encoding) throws EDIStreamException {
if (supportedCharsets.contains(encoding)) {
return new StaEDIStreamWriter(stream, encoding, properties);
}
throw new EDIStreamException("Unsupported encoding: " + encoding);
}

@Override
public boolean isPropertySupported(String name) {
return supportedProperties.contains(name);
}

@Override
public Object getProperty(String name) {
if (!isPropertySupported(name)) {
throw new IllegalArgumentException("Unsupported property: " + name);
}

return properties.get(name);
}

@Override
public void setProperty(String name, Object value) {
if (!isPropertySupported(name)) {
throw new IllegalArgumentException("Unsupported property: " + name);
}

if (PRETTY_PRINT.equals(name) && !(value instanceof Boolean)) {
throw new IllegalArgumentException(name + " must be Boolean");
}

properties.put(name, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ public class StaEDIStreamReader implements EDIStreamReader {
private boolean complete = false;
private boolean closed = false;

public StaEDIStreamReader(
InputStream stream,
String encoding,
Map<String, Object> properties) {
this(stream, encoding, null, properties);
}

public StaEDIStreamReader(
InputStream stream,
String encoding,
Expand Down
Loading

0 comments on commit 4ce4ed0

Please sign in to comment.