diff --git a/src/main/java/edu/nps/moves/dis/GridAxisRecordRepresentation0.java b/src/main/java/edu/nps/moves/dis/GridAxisRecordRepresentation0.java index 75a7eaed..2d7a9484 100644 --- a/src/main/java/edu/nps/moves/dis/GridAxisRecordRepresentation0.java +++ b/src/main/java/edu/nps/moves/dis/GridAxisRecordRepresentation0.java @@ -20,7 +20,7 @@ public class GridAxisRecordRepresentation0 extends GridAxisRecord implements Ser protected int numberOfBytes; /** variable length variablelist of data parameters ^^^this is wrong--need padding as well */ - protected List< OneByteChunk > dataValues = new ArrayList< OneByteChunk >(); + protected byte[] dataValues = new byte[0]; /** Constructor */ public GridAxisRecordRepresentation0() @@ -33,18 +33,14 @@ public int getMarshalledSize() marshalSize = super.getMarshalledSize(); marshalSize = marshalSize + 2; // numberOfBytes - for(int idx=0; idx < dataValues.size(); idx++) - { - OneByteChunk listElement = dataValues.get(idx); - marshalSize = marshalSize + listElement.getMarshalledSize(); - } + marshalSize = marshalSize + dataValues.length; return marshalSize; } public int getNumberOfBytes() -{ return (int)dataValues.size(); +{ return dataValues.length; } /** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose. @@ -55,11 +51,11 @@ public void setNumberOfBytes(int pNumberOfBytes) { numberOfBytes = pNumberOfBytes; } -public void setDataValues(List pDataValues) +public void setDataValues(byte[] pDataValues) { dataValues = pDataValues; } -public List getDataValues() +public byte[] getDataValues() { return dataValues; } @@ -68,13 +64,7 @@ public void marshal(DataOutputStream dos) super.marshal(dos); try { - dos.writeShort( (short)dataValues.size()); - - for(int idx = 0; idx < dataValues.size(); idx++) - { - OneByteChunk aOneByteChunk = dataValues.get(idx); - aOneByteChunk.marshal(dos); - } // end of list marshalling + dos.write(dataValues); } // end try catch(Exception e) @@ -89,13 +79,8 @@ public void unmarshal(DataInputStream dis) try { numberOfBytes = (int)dis.readUnsignedShort(); - for(int idx = 0; idx < numberOfBytes; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(dis); - dataValues.add(anX); - } - + dataValues = new byte[numberOfBytes]; + dis.read(dataValues); } // end try catch(Exception e) { @@ -115,14 +100,8 @@ public void unmarshal(DataInputStream dis) public void marshal(java.nio.ByteBuffer buff) { super.marshal(buff); - buff.putShort( (short)dataValues.size()); - - for(int idx = 0; idx < dataValues.size(); idx++) - { - OneByteChunk aOneByteChunk = (OneByteChunk)dataValues.get(idx); - aOneByteChunk.marshal(buff); - } // end of list marshalling - + buff.putShort((short)dataValues.length); + buff.put(dataValues); } // end of marshal method /** @@ -137,13 +116,8 @@ public void unmarshal(java.nio.ByteBuffer buff) super.unmarshal(buff); numberOfBytes = (int)(buff.getShort() & 0xFFFF); - for(int idx = 0; idx < numberOfBytes; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(buff); - dataValues.add(anX); - } - + dataValues = new byte[numberOfBytes]; + buff.get(dataValues); } // end of unmarshal method @@ -179,12 +153,7 @@ public boolean equalsImpl(Object obj) final GridAxisRecordRepresentation0 rhs = (GridAxisRecordRepresentation0)obj; if( ! (numberOfBytes == rhs.numberOfBytes)) ivarsEqual = false; - - for(int idx = 0; idx < dataValues.size(); idx++) - { - if( ! ( dataValues.get(idx).equals(rhs.dataValues.get(idx)))) ivarsEqual = false; - } - + if( ! (Arrays.equals(dataValues, rhs.dataValues))) ivarsEqual = false; return ivarsEqual && super.equalsImpl(rhs); } diff --git a/src/main/java/edu/nps/moves/dis/IntercomCommunicationsParameters.java b/src/main/java/edu/nps/moves/dis/IntercomCommunicationsParameters.java index c49d1ab2..e80166a8 100644 --- a/src/main/java/edu/nps/moves/dis/IntercomCommunicationsParameters.java +++ b/src/main/java/edu/nps/moves/dis/IntercomCommunicationsParameters.java @@ -23,7 +23,7 @@ public class IntercomCommunicationsParameters extends Object implements Serializ protected int recordLength; /** variable length variablelist of data parameters */ - protected List< OneByteChunk > parameterValues = new ArrayList< OneByteChunk >(); + protected byte[] parameterValues = new byte[0]; /** Constructor */ public IntercomCommunicationsParameters() @@ -36,11 +36,7 @@ public int getMarshalledSize() marshalSize = marshalSize + 2; // recordType marshalSize = marshalSize + 2; // recordLength - for(int idx=0; idx < parameterValues.size(); idx++) - { - OneByteChunk listElement = parameterValues.get(idx); - marshalSize = marshalSize + listElement.getMarshalledSize(); - } + marshalSize = marshalSize + parameterValues.length; return marshalSize; } @@ -55,7 +51,7 @@ public int getRecordType() } public int getRecordLength() -{ return (int)parameterValues.size(); +{ return parameterValues.length; } /** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose. @@ -66,11 +62,11 @@ public void setRecordLength(int pRecordLength) { recordLength = pRecordLength; } -public void setParameterValues(List pParameterValues) +public void setParameterValues(byte[] pParameterValues) { parameterValues = pParameterValues; } -public List getParameterValues() +public byte[] getParameterValues() { return parameterValues; } @@ -79,14 +75,8 @@ public void marshal(DataOutputStream dos) try { dos.writeShort( (short)recordType); - dos.writeShort( (short)parameterValues.size()); - - for(int idx = 0; idx < parameterValues.size(); idx++) - { - OneByteChunk aOneByteChunk = parameterValues.get(idx); - aOneByteChunk.marshal(dos); - } // end of list marshalling - + dos.writeShort( (short)parameterValues.length); + dos.write(parameterValues); } // end try catch(Exception e) { @@ -99,13 +89,8 @@ public void unmarshal(DataInputStream dis) { recordType = (int)dis.readUnsignedShort(); recordLength = (int)dis.readUnsignedShort(); - for(int idx = 0; idx < recordLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(dis); - parameterValues.add(anX); - } - + parameterValues = new byte[recordLength]; + dis.read(parameterValues); } // end try catch(Exception e) { @@ -125,14 +110,8 @@ public void unmarshal(DataInputStream dis) public void marshal(java.nio.ByteBuffer buff) { buff.putShort( (short)recordType); - buff.putShort( (short)parameterValues.size()); - - for(int idx = 0; idx < parameterValues.size(); idx++) - { - OneByteChunk aOneByteChunk = (OneByteChunk)parameterValues.get(idx); - aOneByteChunk.marshal(buff); - } // end of list marshalling - + buff.putShort( (short)parameterValues.length); + buff.put(parameterValues); } // end of marshal method /** @@ -146,13 +125,8 @@ public void unmarshal(java.nio.ByteBuffer buff) { recordType = (int)(buff.getShort() & 0xFFFF); recordLength = (int)(buff.getShort() & 0xFFFF); - for(int idx = 0; idx < recordLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(buff); - parameterValues.add(anX); - } - + parameterValues = new byte[recordLength]; + buff.get(parameterValues); } // end of unmarshal method @@ -194,12 +168,7 @@ public boolean equalsImpl(Object obj) if( ! (recordType == rhs.recordType)) ivarsEqual = false; if( ! (recordLength == rhs.recordLength)) ivarsEqual = false; - - for(int idx = 0; idx < parameterValues.size(); idx++) - { - if( ! ( parameterValues.get(idx).equals(rhs.parameterValues.get(idx)))) ivarsEqual = false; - } - + if( ! (Arrays.equals(parameterValues, rhs.parameterValues))) ivarsEqual = false; return ivarsEqual; } diff --git a/src/main/java/edu/nps/moves/dis/IntercomSignalPdu.java b/src/main/java/edu/nps/moves/dis/IntercomSignalPdu.java index af28bb1f..b2bb9ca8 100644 --- a/src/main/java/edu/nps/moves/dis/IntercomSignalPdu.java +++ b/src/main/java/edu/nps/moves/dis/IntercomSignalPdu.java @@ -38,7 +38,7 @@ public class IntercomSignalPdu extends RadioCommunicationsFamilyPdu implements S protected int samples; /** data bytes */ - protected List< OneByteChunk > data = new ArrayList< OneByteChunk >(); + protected byte[] data = new byte[0]; /** Constructor */ public IntercomSignalPdu() @@ -58,11 +58,7 @@ public int getMarshalledSize() marshalSize = marshalSize + 4; // sampleRate marshalSize = marshalSize + 2; // dataLength marshalSize = marshalSize + 2; // samples - for(int idx=0; idx < data.size(); idx++) - { - OneByteChunk listElement = data.get(idx); - marshalSize = marshalSize + listElement.getMarshalledSize(); - } + marshalSize = marshalSize + data.length; return marshalSize; } @@ -109,7 +105,7 @@ public long getSampleRate() } public int getDataLength() -{ return (int)data.size(); +{ return data.length; } /** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose. @@ -128,11 +124,11 @@ public int getSamples() { return samples; } -public void setData(List pData) +public void setData(byte[] pData) { data = pData; } -public List getData() +public byte[] getData() { return data; } @@ -146,15 +142,9 @@ public void marshal(DataOutputStream dos) dos.writeShort( (short)encodingScheme); dos.writeShort( (short)tdlType); dos.writeInt( (int)sampleRate); - dos.writeShort( (short)data.size()); + dos.writeShort( (short)data.length); dos.writeShort( (short)samples); - - for(int idx = 0; idx < data.size(); idx++) - { - OneByteChunk aOneByteChunk = data.get(idx); - aOneByteChunk.marshal(dos); - } // end of list marshalling - + dos.write(data); } // end try catch(Exception e) { @@ -174,13 +164,8 @@ public void unmarshal(DataInputStream dis) sampleRate = dis.readInt(); dataLength = (int)dis.readUnsignedShort(); samples = (int)dis.readUnsignedShort(); - for(int idx = 0; idx < dataLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(dis); - data.add(anX); - } - + data = new byte[dataLength]; + dis.read(data); } // end try catch(Exception e) { @@ -205,15 +190,9 @@ public void marshal(java.nio.ByteBuffer buff) buff.putShort( (short)encodingScheme); buff.putShort( (short)tdlType); buff.putInt( (int)sampleRate); - buff.putShort( (short)data.size()); + buff.putShort( (short)data.length); buff.putShort( (short)samples); - - for(int idx = 0; idx < data.size(); idx++) - { - OneByteChunk aOneByteChunk = (OneByteChunk)data.get(idx); - aOneByteChunk.marshal(buff); - } // end of list marshalling - + buff.put(data); } // end of marshal method /** @@ -234,13 +213,8 @@ public void unmarshal(java.nio.ByteBuffer buff) sampleRate = buff.getInt(); dataLength = (int)(buff.getShort() & 0xFFFF); samples = (int)(buff.getShort() & 0xFFFF); - for(int idx = 0; idx < dataLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(buff); - data.add(anX); - } - + data = new byte[dataLength]; + buff.get(data); } // end of unmarshal method @@ -282,12 +256,7 @@ public boolean equalsImpl(Object obj) if( ! (sampleRate == rhs.sampleRate)) ivarsEqual = false; if( ! (dataLength == rhs.dataLength)) ivarsEqual = false; if( ! (samples == rhs.samples)) ivarsEqual = false; - - for(int idx = 0; idx < data.size(); idx++) - { - if( ! ( data.get(idx).equals(rhs.data.get(idx)))) ivarsEqual = false; - } - + if( ! (Arrays.equals(data, rhs.data))) ivarsEqual = false; return ivarsEqual && super.equalsImpl(rhs); } diff --git a/src/main/java/edu/nps/moves/dis/OneByteChunk.java b/src/main/java/edu/nps/moves/dis/OneByteChunk.java deleted file mode 100644 index 62bd0d70..00000000 --- a/src/main/java/edu/nps/moves/dis/OneByteChunk.java +++ /dev/null @@ -1,157 +0,0 @@ -package edu.nps.moves.dis; - -import java.util.*; -import java.io.*; -import edu.nps.moves.disenum.*; -import edu.nps.moves.disutil.*; - - -/** - * 8 bit piece of data - * - * Copyright (c) 2008-2016, MOVES Institute, Naval Postgraduate School. All rights reserved. - * This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html - * - * @author DMcG - */ -public class OneByteChunk extends Object implements Serializable -{ - /** one byte of arbitrary data */ - protected byte[] otherParameters = new byte[1]; - - -/** Constructor */ - public OneByteChunk() - { - } - -public int getMarshalledSize() -{ - int marshalSize = 0; - - marshalSize = marshalSize + 1 * 1; // otherParameters - - return marshalSize; -} - - -public void setOtherParameters(byte[] pOtherParameters) -{ otherParameters = pOtherParameters; -} - -public byte[] getOtherParameters() -{ return otherParameters; } - - -public void marshal(DataOutputStream dos) -{ - try - { - - for(int idx = 0; idx < otherParameters.length; idx++) - { - dos.writeByte(otherParameters[idx]); - } // end of array marshaling - - } // end try - catch(Exception e) - { - System.out.println(e);} - } // end of marshal method - -public void unmarshal(DataInputStream dis) -{ - try - { - for(int idx = 0; idx < otherParameters.length; idx++) - { - otherParameters[idx] = dis.readByte(); - } // end of array unmarshaling - } // end try - catch(Exception e) - { - System.out.println(e); - } - } // end of unmarshal method - - -/** - * Packs a Pdu into the ByteBuffer. - * @throws java.nio.BufferOverflowException if buff is too small - * @throws java.nio.ReadOnlyBufferException if buff is read only - * @see java.nio.ByteBuffer - * @param buff The ByteBuffer at the position to begin writing - * @since ?? - */ -public void marshal(java.nio.ByteBuffer buff) -{ - - for(int idx = 0; idx < otherParameters.length; idx++) - { - buff.put((byte)otherParameters[idx]); - } // end of array marshaling - - } // end of marshal method - -/** - * Unpacks a Pdu from the underlying data. - * @throws java.nio.BufferUnderflowException if buff is too small - * @see java.nio.ByteBuffer - * @param buff The ByteBuffer at the position to begin reading - * @since ?? - */ -public void unmarshal(java.nio.ByteBuffer buff) -{ - for(int idx = 0; idx < otherParameters.length; idx++) - { - otherParameters[idx] = buff.get(); - } // end of array unmarshaling - } // end of unmarshal method - - - /* - * The equals method doesn't always work--mostly it works only on classes that consist only of primitives. Be careful. - */ -@Override - public boolean equals(Object obj) - { - - if(this == obj){ - return true; - } - - if(obj == null){ - return false; - } - - if(getClass() != obj.getClass()) - return false; - - return equalsImpl(obj); - } - - /** - * Compare all fields that contribute to the state, ignoring - transient and static fields, for this and the supplied object - * @param obj the object to compare to - * @return true if the objects are equal, false otherwise. - */ - public boolean equalsImpl(Object obj) - { - boolean ivarsEqual = true; - - if(!(obj instanceof OneByteChunk)) - return false; - - final OneByteChunk rhs = (OneByteChunk)obj; - - - for(int idx = 0; idx < 1; idx++) - { - if(!(otherParameters[idx] == rhs.otherParameters[idx])) ivarsEqual = false; - } - - - return ivarsEqual; - } -} // end of class diff --git a/src/main/java/edu/nps/moves/dis/SignalPdu.java b/src/main/java/edu/nps/moves/dis/SignalPdu.java index d9ec083b..4f9d9509 100644 --- a/src/main/java/edu/nps/moves/dis/SignalPdu.java +++ b/src/main/java/edu/nps/moves/dis/SignalPdu.java @@ -38,7 +38,7 @@ public class SignalPdu extends RadioCommunicationsFamilyPdu implements Serializa protected int samples; /** list of eight bit values. Must be padded to fall on a 32 bit boundary. */ - protected List< OneByteChunk > data = new ArrayList< OneByteChunk >(); + protected byte[] data = new byte[0]; /** Constructor */ public SignalPdu() @@ -57,12 +57,8 @@ public int getMarshalledSize() marshalSize = marshalSize + 2; // tdlType marshalSize = marshalSize + 4; // sampleRate marshalSize = marshalSize + 2; // dataLength - marshalSize = marshalSize + 2; // samples - for(int idx=0; idx < data.size(); idx++) - { - OneByteChunk listElement = data.get(idx); - marshalSize = marshalSize + listElement.getMarshalledSize(); - } + marshalSize = marshalSize + 2; // samples + marshalSize = marshalSize + data.length; return marshalSize; } @@ -128,11 +124,11 @@ public int getSamples() { return samples; } -public void setData(List pData) +public void setData(byte[] pData) { data = pData; } -public List getData() +public byte[] getData() { return data; } @@ -148,13 +144,7 @@ public void marshal(DataOutputStream dos) dos.writeInt( (int)sampleRate); dos.writeShort( (short)dataLength); dos.writeShort( (short)samples); - - for(int idx = 0; idx < data.size(); idx++) - { - OneByteChunk aOneByteChunk = data.get(idx); - aOneByteChunk.marshal(dos); - } // end of list marshalling - + dos.write(data); } // end try catch(Exception e) { @@ -175,13 +165,8 @@ public void unmarshal(DataInputStream dis) dataLength = (int)dis.readUnsignedShort(); samples = (int)dis.readUnsignedShort(); final int dataLengthBytes = dataLength / Byte.SIZE; - for(int idx = 0; idx < dataLengthBytes; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(dis); - data.add(anX); - } - + data = new byte[dataLengthBytes]; + dis.read(data); } // end try catch(Exception e) { @@ -208,13 +193,7 @@ public void marshal(java.nio.ByteBuffer buff) buff.putInt( (int)sampleRate); buff.putShort( (short)dataLength); buff.putShort( (short)samples); - - for(int idx = 0; idx < data.size(); idx++) - { - OneByteChunk aOneByteChunk = (OneByteChunk)data.get(idx); - aOneByteChunk.marshal(buff); - } // end of list marshalling - + buff.put(data); } // end of marshal method /** @@ -236,13 +215,8 @@ public void unmarshal(java.nio.ByteBuffer buff) dataLength = (int)(buff.getShort() & 0xFFFF); samples = (int)(buff.getShort() & 0xFFFF); final int dataLengthBytes = dataLength / Byte.SIZE; - for(int idx = 0; idx < dataLengthBytes; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(buff); - data.add(anX); - } - + data = new byte[dataLengthBytes]; + buff.get(data); } // end of unmarshal method @@ -284,12 +258,7 @@ public boolean equalsImpl(Object obj) if( ! (sampleRate == rhs.sampleRate)) ivarsEqual = false; if( ! (dataLength == rhs.dataLength)) ivarsEqual = false; if( ! (samples == rhs.samples)) ivarsEqual = false; - - for(int idx = 0; idx < data.size(); idx++) - { - if( ! ( data.get(idx).equals(rhs.data.get(idx)))) ivarsEqual = false; - } - + if( ! (Arrays.equals(data, rhs.data))) ivarsEqual = false; return ivarsEqual && super.equalsImpl(rhs); } diff --git a/src/main/java/edu/nps/moves/dis/VariableDatum.java b/src/main/java/edu/nps/moves/dis/VariableDatum.java index b7d946ad..c3b3f545 100644 --- a/src/main/java/edu/nps/moves/dis/VariableDatum.java +++ b/src/main/java/edu/nps/moves/dis/VariableDatum.java @@ -23,7 +23,7 @@ public class VariableDatum extends Object implements Serializable protected long variableDatumLength; /** data can be any length, but must increase in 8 byte quanta. This requires some postprocessing patches. Note that setting the data allocates a new internal array to account for the possibly increased size. The default initial size is 64 bits. */ - protected List< OneByteChunk > variableData = new ArrayList< OneByteChunk >(); + protected byte[] variableData; /** Constructor */ public VariableDatum() @@ -36,11 +36,7 @@ public int getMarshalledSize() marshalSize = marshalSize + 4; // variableDatumID marshalSize = marshalSize + 4; // variableDatumLength - for(int idx=0; idx < variableData.size(); idx++) - { - OneByteChunk listElement = variableData.get(idx); - marshalSize = marshalSize + listElement.getMarshalledSize(); - } + marshalSize = marshalSize + variableData.length; // Account for required padding. marshalSize = marshalSize + datumPaddingSize(); @@ -58,7 +54,7 @@ public long getVariableDatumID() } public long getVariableDatumLength() -{ return (long)variableData.size() * Byte.SIZE; +{ return (long)variableData.length * Byte.SIZE; } /** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose. @@ -69,11 +65,11 @@ public void setVariableDatumLength(long pVariableDatumLength) { variableDatumLength = pVariableDatumLength; } -public void setVariableData(List pVariableData) +public void setVariableData(byte[] pVariableData) { variableData = pVariableData; } -public List getVariableData() +public byte[] getVariableData() { return variableData; } @@ -83,12 +79,7 @@ public void marshal(DataOutputStream dos) { dos.writeInt( (int)variableDatumID); dos.writeInt( (int)getVariableDatumLength()); - - for(int idx = 0; idx < variableData.size(); idx++) - { - OneByteChunk aOneByteChunk = variableData.get(idx); - aOneByteChunk.marshal(dos); - } // end of list marshalling + dos.write(variableData); // Add padding. for (int i = 0; i < datumPaddingSize(); i++) { @@ -107,13 +98,9 @@ public void unmarshal(DataInputStream dis) { variableDatumID = dis.readInt(); variableDatumLength = dis.readInt(); - for(int idx = 0; idx < variableDatumLength / Byte.SIZE; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(dis); - variableData.add(anX); - } - + final int dataLengthBytes = (int)variableDatumLength / Byte.SIZE; + variableData = new byte[dataLengthBytes]; + dis.read(variableData); } // end try catch(Exception e) { @@ -134,12 +121,7 @@ public void marshal(java.nio.ByteBuffer buff) { buff.putInt( (int)variableDatumID); buff.putInt( (int)getVariableDatumLength()); - - for(int idx = 0; idx < variableData.size(); idx++) - { - OneByteChunk aOneByteChunk = (OneByteChunk)variableData.get(idx); - aOneByteChunk.marshal(buff); - } // end of list marshalling + buff.put(variableData); // Add padding. for (int i = 0; i < datumPaddingSize(); i++) { @@ -158,12 +140,9 @@ public void unmarshal(java.nio.ByteBuffer buff) { variableDatumID = buff.getInt(); variableDatumLength = buff.getInt(); - for(int idx = 0; idx < variableDatumLength / Byte.SIZE; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(buff); - variableData.add(anX); - } + final int dataLengthBytes = (int)variableDatumLength / Byte.SIZE; + variableData = new byte[dataLengthBytes]; + buff.get(variableData); } // end of unmarshal method @@ -206,12 +185,7 @@ public boolean equalsImpl(Object obj) if( ! (variableDatumID == rhs.variableDatumID)) ivarsEqual = false; if( ! (variableDatumLength == rhs.variableDatumLength)) ivarsEqual = false; - - for(int idx = 0; idx < variableData.size(); idx++) - { - if( ! ( variableData.get(idx).equals(rhs.variableData.get(idx)))) ivarsEqual = false; - } - + if( ! (Arrays.equals(variableData, rhs.variableData))) ivarsEqual = false; return ivarsEqual; } @@ -220,7 +194,7 @@ public boolean equalsImpl(Object obj) private int datumPaddingSize() { final int BYTES_IN_64_BITS = 8; int padding = 0; - final int remainder = variableData.size() % BYTES_IN_64_BITS; + final int remainder = (int)variableData.length % BYTES_IN_64_BITS; if (remainder != 0) { padding = BYTES_IN_64_BITS - remainder; } diff --git a/src/main/java/edu/nps/moves/dis7/IFFData.java b/src/main/java/edu/nps/moves/dis7/IFFData.java index 80f3c87a..ec391129 100644 --- a/src/main/java/edu/nps/moves/dis7/IFFData.java +++ b/src/main/java/edu/nps/moves/dis7/IFFData.java @@ -23,7 +23,7 @@ public class IFFData extends Object implements Serializable protected int recordLength; /** IFF data. */ - protected List< OneByteChunk > iffData = new ArrayList< OneByteChunk >(); + protected byte[] iffData = new byte[0]; /** Constructor */ public IFFData() @@ -36,11 +36,7 @@ public int getMarshalledSize() marshalSize = marshalSize + 4; // recordType marshalSize = marshalSize + 2; // recordLength - for(int idx=0; idx < iffData.size(); idx++) - { - OneByteChunk listElement = iffData.get(idx); - marshalSize = marshalSize + listElement.getMarshalledSize(); - } + marshalSize = marshalSize + iffData.length; return marshalSize; } @@ -55,7 +51,7 @@ public long getRecordType() } public int getRecordLength() -{ return (int)iffData.size(); +{ return iffData.length; } /** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose. @@ -66,11 +62,11 @@ public void setRecordLength(int pRecordLength) { recordLength = pRecordLength; } -public void setIffData(List pIffData) +public void setIffData(byte[] pIffData) { iffData = pIffData; } -public List getIffData() +public byte[] getIffData() { return iffData; } @@ -79,14 +75,8 @@ public void marshal(DataOutputStream dos) try { dos.writeInt( (int)recordType); - dos.writeShort( (short)iffData.size()); - - for(int idx = 0; idx < iffData.size(); idx++) - { - OneByteChunk aOneByteChunk = iffData.get(idx); - aOneByteChunk.marshal(dos); - } // end of list marshalling - + dos.writeShort( (short)iffData.length); + dos.write(iffData); } // end try catch(Exception e) { @@ -99,13 +89,8 @@ public void unmarshal(DataInputStream dis) { recordType = dis.readInt(); recordLength = (int)dis.readUnsignedShort(); - for(int idx = 0; idx < recordLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(dis); - iffData.add(anX); - } - + iffData = new byte[recordLength]; + dis.read(iffData); } // end try catch(Exception e) { @@ -125,14 +110,8 @@ public void unmarshal(DataInputStream dis) public void marshal(java.nio.ByteBuffer buff) { buff.putInt( (int)recordType); - buff.putShort( (short)iffData.size()); - - for(int idx = 0; idx < iffData.size(); idx++) - { - OneByteChunk aOneByteChunk = (OneByteChunk)iffData.get(idx); - aOneByteChunk.marshal(buff); - } // end of list marshalling - + buff.putShort( (short)iffData.length); + buff.put(iffData); } // end of marshal method /** @@ -146,13 +125,8 @@ public void unmarshal(java.nio.ByteBuffer buff) { recordType = buff.getInt(); recordLength = (int)(buff.getShort() & 0xFFFF); - for(int idx = 0; idx < recordLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(buff); - iffData.add(anX); - } - + iffData = new byte[recordLength]; + buff.get(iffData); } // end of unmarshal method @@ -194,12 +168,7 @@ public boolean equalsImpl(Object obj) if( ! (recordType == rhs.recordType)) ivarsEqual = false; if( ! (recordLength == rhs.recordLength)) ivarsEqual = false; - - for(int idx = 0; idx < iffData.size(); idx++) - { - if( ! ( iffData.get(idx).equals(rhs.iffData.get(idx)))) ivarsEqual = false; - } - + if( ! (Arrays.equals(iffData, rhs.iffData))) ivarsEqual = false; return ivarsEqual; } diff --git a/src/main/java/edu/nps/moves/dis7/IntercomSignalPdu.java b/src/main/java/edu/nps/moves/dis7/IntercomSignalPdu.java index 570a6be1..a32cad90 100644 --- a/src/main/java/edu/nps/moves/dis7/IntercomSignalPdu.java +++ b/src/main/java/edu/nps/moves/dis7/IntercomSignalPdu.java @@ -38,7 +38,7 @@ public class IntercomSignalPdu extends RadioCommunicationsFamilyPdu implements S protected int samples; /** data bytes */ - protected List< OneByteChunk > data = new ArrayList< OneByteChunk >(); + protected byte[] data = new byte[0]; /** Constructor */ public IntercomSignalPdu() @@ -58,11 +58,7 @@ public int getMarshalledSize() marshalSize = marshalSize + 4; // sampleRate marshalSize = marshalSize + 2; // dataLength marshalSize = marshalSize + 2; // samples - for(int idx=0; idx < data.size(); idx++) - { - OneByteChunk listElement = data.get(idx); - marshalSize = marshalSize + listElement.getMarshalledSize(); - } + marshalSize = marshalSize + data.length; return marshalSize; } @@ -109,7 +105,7 @@ public long getSampleRate() } public int getDataLength() -{ return (int)data.size(); +{ return (int)data.length; } /** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose. @@ -128,11 +124,11 @@ public int getSamples() { return samples; } -public void setData(List pData) +public void setData(byte[] pData) { data = pData; } -public List getData() +public byte[] getData() { return data; } @@ -146,15 +142,9 @@ public void marshal(DataOutputStream dos) dos.writeShort( (short)encodingScheme); dos.writeShort( (short)tdlType); dos.writeInt( (int)sampleRate); - dos.writeShort( (short)data.size()); + dos.writeShort( (short)data.length); dos.writeShort( (short)samples); - - for(int idx = 0; idx < data.size(); idx++) - { - OneByteChunk aOneByteChunk = data.get(idx); - aOneByteChunk.marshal(dos); - } // end of list marshalling - + dos.write(data); } // end try catch(Exception e) { @@ -174,13 +164,8 @@ public void unmarshal(DataInputStream dis) sampleRate = dis.readInt(); dataLength = (int)dis.readUnsignedShort(); samples = (int)dis.readUnsignedShort(); - for(int idx = 0; idx < dataLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(dis); - data.add(anX); - } - + data = new byte[dataLength]; + dis.read(data); } // end try catch(Exception e) { @@ -205,15 +190,9 @@ public void marshal(java.nio.ByteBuffer buff) buff.putShort( (short)encodingScheme); buff.putShort( (short)tdlType); buff.putInt( (int)sampleRate); - buff.putShort( (short)data.size()); + buff.putShort( (short)data.length); buff.putShort( (short)samples); - - for(int idx = 0; idx < data.size(); idx++) - { - OneByteChunk aOneByteChunk = (OneByteChunk)data.get(idx); - aOneByteChunk.marshal(buff); - } // end of list marshalling - + buff.put(data); } // end of marshal method /** @@ -234,13 +213,8 @@ public void unmarshal(java.nio.ByteBuffer buff) sampleRate = buff.getInt(); dataLength = (int)(buff.getShort() & 0xFFFF); samples = (int)(buff.getShort() & 0xFFFF); - for(int idx = 0; idx < dataLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(buff); - data.add(anX); - } - + data = new byte[dataLength]; + buff.get(data); } // end of unmarshal method @@ -282,12 +256,7 @@ public boolean equalsImpl(Object obj) if( ! (sampleRate == rhs.sampleRate)) ivarsEqual = false; if( ! (dataLength == rhs.dataLength)) ivarsEqual = false; if( ! (samples == rhs.samples)) ivarsEqual = false; - - for(int idx = 0; idx < data.size(); idx++) - { - if( ! ( data.get(idx).equals(rhs.data.get(idx)))) ivarsEqual = false; - } - + if( ! (Arrays.equals(data, rhs.data))) ivarsEqual = false; return ivarsEqual && super.equalsImpl(rhs); } diff --git a/src/main/java/edu/nps/moves/dis7/OneByteChunk.java b/src/main/java/edu/nps/moves/dis7/OneByteChunk.java deleted file mode 100644 index f6bd4706..00000000 --- a/src/main/java/edu/nps/moves/dis7/OneByteChunk.java +++ /dev/null @@ -1,157 +0,0 @@ -package edu.nps.moves.dis7; - -import java.util.*; -import java.io.*; -import edu.nps.moves.disenum.*; -import edu.nps.moves.disutil.*; - - -/** - * 8 bit piece of data - * - * Copyright (c) 2008-2016, MOVES Institute, Naval Postgraduate School. All rights reserved. - * This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html - * - * @author DMcG - */ -public class OneByteChunk extends Object implements Serializable -{ - /** one byte of arbitrary data */ - protected byte[] otherParameters = new byte[1]; - - -/** Constructor */ - public OneByteChunk() - { - } - -public int getMarshalledSize() -{ - int marshalSize = 0; - - marshalSize = marshalSize + 1 * 1; // otherParameters - - return marshalSize; -} - - -public void setOtherParameters(byte[] pOtherParameters) -{ otherParameters = pOtherParameters; -} - -public byte[] getOtherParameters() -{ return otherParameters; } - - -public void marshal(DataOutputStream dos) -{ - try - { - - for(int idx = 0; idx < otherParameters.length; idx++) - { - dos.writeByte(otherParameters[idx]); - } // end of array marshaling - - } // end try - catch(Exception e) - { - System.out.println(e);} - } // end of marshal method - -public void unmarshal(DataInputStream dis) -{ - try - { - for(int idx = 0; idx < otherParameters.length; idx++) - { - otherParameters[idx] = dis.readByte(); - } // end of array unmarshaling - } // end try - catch(Exception e) - { - System.out.println(e); - } - } // end of unmarshal method - - -/** - * Packs a Pdu into the ByteBuffer. - * @throws java.nio.BufferOverflowException if buff is too small - * @throws java.nio.ReadOnlyBufferException if buff is read only - * @see java.nio.ByteBuffer - * @param buff The ByteBuffer at the position to begin writing - * @since ?? - */ -public void marshal(java.nio.ByteBuffer buff) -{ - - for(int idx = 0; idx < otherParameters.length; idx++) - { - buff.put((byte)otherParameters[idx]); - } // end of array marshaling - - } // end of marshal method - -/** - * Unpacks a Pdu from the underlying data. - * @throws java.nio.BufferUnderflowException if buff is too small - * @see java.nio.ByteBuffer - * @param buff The ByteBuffer at the position to begin reading - * @since ?? - */ -public void unmarshal(java.nio.ByteBuffer buff) -{ - for(int idx = 0; idx < otherParameters.length; idx++) - { - otherParameters[idx] = buff.get(); - } // end of array unmarshaling - } // end of unmarshal method - - - /* - * The equals method doesn't always work--mostly it works only on classes that consist only of primitives. Be careful. - */ -@Override - public boolean equals(Object obj) - { - - if(this == obj){ - return true; - } - - if(obj == null){ - return false; - } - - if(getClass() != obj.getClass()) - return false; - - return equalsImpl(obj); - } - - /** - * Compare all fields that contribute to the state, ignoring - transient and static fields, for this and the supplied object - * @param obj the object to compare to - * @return true if the objects are equal, false otherwise. - */ - public boolean equalsImpl(Object obj) - { - boolean ivarsEqual = true; - - if(!(obj instanceof OneByteChunk)) - return false; - - final OneByteChunk rhs = (OneByteChunk)obj; - - - for(int idx = 0; idx < 1; idx++) - { - if(!(otherParameters[idx] == rhs.otherParameters[idx])) ivarsEqual = false; - } - - - return ivarsEqual; - } -} // end of class diff --git a/src/main/java/edu/nps/moves/dis7/SignalPdu.java b/src/main/java/edu/nps/moves/dis7/SignalPdu.java index 138c7325..0e0f9727 100644 --- a/src/main/java/edu/nps/moves/dis7/SignalPdu.java +++ b/src/main/java/edu/nps/moves/dis7/SignalPdu.java @@ -32,7 +32,7 @@ public class SignalPdu extends RadioCommunicationsFamilyPdu implements Serializa protected short samples; /** list of eight bit values */ - protected List< OneByteChunk > data = new ArrayList< OneByteChunk >(); + protected byte[] data = new byte[0]; /** Constructor */ public SignalPdu() @@ -50,11 +50,7 @@ public int getMarshalledSize() marshalSize = marshalSize + 4; // sampleRate marshalSize = marshalSize + 2; // dataLength marshalSize = marshalSize + 2; // samples - for(int idx=0; idx < data.size(); idx++) - { - OneByteChunk listElement = data.get(idx); - marshalSize = marshalSize + listElement.getMarshalledSize(); - } + marshalSize = marshalSize + data.length; return marshalSize; } @@ -85,7 +81,7 @@ public long getSampleRate() } public short getDataLength() -{ return (short)data.size(); +{ return (short)data.length; } /** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose. @@ -104,11 +100,11 @@ public short getSamples() { return samples; } -public void setData(List pData) +public void setData(byte[] pData) { data = pData; } -public List getData() +public byte[] getData() { return data; } @@ -120,15 +116,9 @@ public void marshal(DataOutputStream dos) dos.writeShort( (short)encodingScheme); dos.writeShort( (short)tdlType); dos.writeInt( (int)sampleRate); - dos.writeShort( (short)data.size()); + dos.writeShort( (short)data.length); dos.writeShort( (short)samples); - - for(int idx = 0; idx < data.size(); idx++) - { - OneByteChunk aOneByteChunk = data.get(idx); - aOneByteChunk.marshal(dos); - } // end of list marshalling - + dos.write(data); } // end try catch(Exception e) { @@ -146,13 +136,8 @@ public void unmarshal(DataInputStream dis) sampleRate = dis.readInt(); dataLength = dis.readShort(); samples = dis.readShort(); - for(int idx = 0; idx < dataLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(dis); - data.add(anX); - } - + data = new byte[dataLength]; + dis.read(data); } // end try catch(Exception e) { @@ -175,15 +160,9 @@ public void marshal(java.nio.ByteBuffer buff) buff.putShort( (short)encodingScheme); buff.putShort( (short)tdlType); buff.putInt( (int)sampleRate); - buff.putShort( (short)data.size()); + buff.putShort( (short)data.length); buff.putShort( (short)samples); - - for(int idx = 0; idx < data.size(); idx++) - { - OneByteChunk aOneByteChunk = (OneByteChunk)data.get(idx); - aOneByteChunk.marshal(buff); - } // end of list marshalling - + buff.put(data); } // end of marshal method /** @@ -202,13 +181,8 @@ public void unmarshal(java.nio.ByteBuffer buff) sampleRate = buff.getInt(); dataLength = buff.getShort(); samples = buff.getShort(); - for(int idx = 0; idx < dataLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(buff); - data.add(anX); - } - + data = new byte[dataLength]; + buff.get(data); } // end of unmarshal method @@ -248,12 +222,7 @@ public boolean equalsImpl(Object obj) if( ! (sampleRate == rhs.sampleRate)) ivarsEqual = false; if( ! (dataLength == rhs.dataLength)) ivarsEqual = false; if( ! (samples == rhs.samples)) ivarsEqual = false; - - for(int idx = 0; idx < data.size(); idx++) - { - if( ! ( data.get(idx).equals(rhs.data.get(idx)))) ivarsEqual = false; - } - + if( ! (Arrays.equals(data, rhs.data))) ivarsEqual = false; return ivarsEqual && super.equalsImpl(rhs); } diff --git a/src/main/java/edu/nps/moves/dis7/VariableDatum.java b/src/main/java/edu/nps/moves/dis7/VariableDatum.java index 7c750f93..3f27ef91 100644 --- a/src/main/java/edu/nps/moves/dis7/VariableDatum.java +++ b/src/main/java/edu/nps/moves/dis7/VariableDatum.java @@ -23,7 +23,7 @@ public class VariableDatum extends Object implements Serializable protected long variableDatumLength; /** Variable length data class */ - protected List< OneByteChunk > variableDatumData = new ArrayList< OneByteChunk >(); + protected byte[] variableDatumData = new byte[0]; /** Constructor */ public VariableDatum() @@ -36,11 +36,7 @@ public int getMarshalledSize() marshalSize = marshalSize + 4; // variableDatumID marshalSize = marshalSize + 4; // variableDatumLength - for(int idx=0; idx < variableDatumData.size(); idx++) - { - OneByteChunk listElement = variableDatumData.get(idx); - marshalSize = marshalSize + listElement.getMarshalledSize(); - } + marshalSize = marshalSize + variableDatumData.length; return marshalSize; } @@ -55,7 +51,7 @@ public long getVariableDatumID() } public long getVariableDatumLength() -{ return (long)variableDatumData.size(); +{ return (long)variableDatumData.length; } /** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose. @@ -66,11 +62,11 @@ public void setVariableDatumLength(long pVariableDatumLength) { variableDatumLength = pVariableDatumLength; } -public void setVariableDatumData(List pVariableDatumData) +public void setVariableDatumData(byte[] pVariableDatumData) { variableDatumData = pVariableDatumData; } -public List getVariableDatumData() +public byte[] getVariableDatumData() { return variableDatumData; } @@ -79,14 +75,8 @@ public void marshal(DataOutputStream dos) try { dos.writeInt( (int)variableDatumID); - dos.writeInt( (int)variableDatumData.size()); - - for(int idx = 0; idx < variableDatumData.size(); idx++) - { - OneByteChunk aOneByteChunk = variableDatumData.get(idx); - aOneByteChunk.marshal(dos); - } // end of list marshalling - + dos.writeInt( (int)variableDatumData.length); + dos.write(variableDatumData); } // end try catch(Exception e) { @@ -99,13 +89,8 @@ public void unmarshal(DataInputStream dis) { variableDatumID = dis.readInt(); variableDatumLength = dis.readInt(); - for(int idx = 0; idx < variableDatumLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(dis); - variableDatumData.add(anX); - } - + variableDatumData = new byte[(int) variableDatumLength]; + dis.read(variableDatumData); } // end try catch(Exception e) { @@ -125,14 +110,8 @@ public void unmarshal(DataInputStream dis) public void marshal(java.nio.ByteBuffer buff) { buff.putInt( (int)variableDatumID); - buff.putInt( (int)variableDatumData.size()); - - for(int idx = 0; idx < variableDatumData.size(); idx++) - { - OneByteChunk aOneByteChunk = (OneByteChunk)variableDatumData.get(idx); - aOneByteChunk.marshal(buff); - } // end of list marshalling - + buff.putInt( (int)variableDatumData.length); + buff.put(variableDatumData); } // end of marshal method /** @@ -146,13 +125,8 @@ public void unmarshal(java.nio.ByteBuffer buff) { variableDatumID = buff.getInt(); variableDatumLength = buff.getInt(); - for(int idx = 0; idx < variableDatumLength; idx++) - { - OneByteChunk anX = new OneByteChunk(); - anX.unmarshal(buff); - variableDatumData.add(anX); - } - + variableDatumData = new byte[(int) variableDatumLength]; + buff.get(variableDatumData); } // end of unmarshal method @@ -194,12 +168,7 @@ public boolean equalsImpl(Object obj) if( ! (variableDatumID == rhs.variableDatumID)) ivarsEqual = false; if( ! (variableDatumLength == rhs.variableDatumLength)) ivarsEqual = false; - - for(int idx = 0; idx < variableDatumData.size(); idx++) - { - if( ! ( variableDatumData.get(idx).equals(rhs.variableDatumData.get(idx)))) ivarsEqual = false; - } - + if( ! (Arrays.equals(variableDatumData, rhs.variableDatumData))) ivarsEqual = false; return ivarsEqual; } diff --git a/src/main/java/edu/nps/moves/logger/LogReplay.java b/src/main/java/edu/nps/moves/logger/LogReplay.java index 8ba638c5..6d13d4e6 100644 --- a/src/main/java/edu/nps/moves/logger/LogReplay.java +++ b/src/main/java/edu/nps/moves/logger/LogReplay.java @@ -219,7 +219,6 @@ public void replayExercise() edu.nps.moves.dis.ApaData.class, edu.nps.moves.dis.BeamData.class, edu.nps.moves.dis.PropulsionSystemData.class, - edu.nps.moves.dis.OneByteChunk.class, edu.nps.moves.dis.AcousticEmitter.class, edu.nps.moves.dis.TransmitterPdu.class, edu.nps.moves.dis.EventID.class, diff --git a/src/main/java/edu/nps/moves/logger/LogWriter.java b/src/main/java/edu/nps/moves/logger/LogWriter.java index 8077a80d..b6724d52 100644 --- a/src/main/java/edu/nps/moves/logger/LogWriter.java +++ b/src/main/java/edu/nps/moves/logger/LogWriter.java @@ -228,7 +228,6 @@ public void run() { edu.nps.moves.dis.ApaData.class, edu.nps.moves.dis.BeamData.class, edu.nps.moves.dis.PropulsionSystemData.class, - edu.nps.moves.dis.OneByteChunk.class, edu.nps.moves.dis.AcousticEmitter.class, edu.nps.moves.dis.TransmitterPdu.class, edu.nps.moves.dis.EventID.class, diff --git a/src/test/java/edu/nps/moves/dis/DataPduTest.java b/src/test/java/edu/nps/moves/dis/DataPduTest.java index e1ffdc47..879f907e 100644 --- a/src/test/java/edu/nps/moves/dis/DataPduTest.java +++ b/src/test/java/edu/nps/moves/dis/DataPduTest.java @@ -42,10 +42,7 @@ public void unmarshal() throws IOException { assertEquals(1, vd.getVariableDatumID()); assertEquals(1976, vd.getVariableDatumLength()); - byte[] datumValue = new byte[(int) vd.getVariableData().size()]; - for (int i = 0; i < vd.getVariableData().size(); i++) { - datumValue[i] = vd.getVariableData().get(i).getOtherParameters()[0]; - } + byte[] datumValue = vd.getVariableData(); assertEquals("[UAV2_PAYLOAD,UAV2_PLANNER,unit_7,UAV1_PLANNER,UAV1_PAYLOAD,unit_3,B 1-1-C-4:1,B 1-1-C-4:2,B 1-1-C-4:3,B 1-1-C-5:1,B 1-1-C-5:2,B 1-1-C-5:3,B 1-1-C-6:1,B 1-1-C-6:2,B 1-1-C-6:3,B 1-1-A-4:1,B 1-1-A-9:1,B 1-1-A-5:1,B 1-1-B-4:1,B 1-1-A-6:1,B 1-1-A-6:2]", new String(datumValue)); } diff --git a/src/test/java/edu/nps/moves/dis/IntercomSignalPduUnitTest.java b/src/test/java/edu/nps/moves/dis/IntercomSignalPduUnitTest.java index 330eb223..6861b907 100644 --- a/src/test/java/edu/nps/moves/dis/IntercomSignalPduUnitTest.java +++ b/src/test/java/edu/nps/moves/dis/IntercomSignalPduUnitTest.java @@ -32,18 +32,7 @@ public void setUp() { eid.setEntity(101); eid.setSite(102); - /** - * Ugh. The data for each chunk is a one byte array, rather than just - * a byte. Why did I do this? - */ - List signalData = new ArrayList(); - for (int i = 0; i < 100; i++) { - OneByteChunk chunk = new OneByteChunk(); - byte data[] = new byte[1]; - data[0] = (byte) i; - chunk.setOtherParameters(data); - signalData.add(chunk); - } + byte[] signalData = new byte[100]; isp = new IntercomSignalPdu(); isp.setCommunicationsDeviceID(1); @@ -68,15 +57,11 @@ public void testFields() { assertEquals("CommunicationsDeviceID", isp.getCommunicationsDeviceID(), 1); - List retrievedData = isp.getData(); + byte[] retrievedData = isp.getData(); assertEquals("Signal data length wrong", isp.getDataLength(), 100); // Check that each value in the variable-length array is the same as we set - for (int i = 0; i < 100; i++) { - OneByteChunk chunk = retrievedData.get(i); - byte[] data = chunk.getOtherParameters(); - assertEquals("Signal data mismatch", data[0], i); - } + assertArrayEquals("Signal data mismatch", retrievedData, new byte[100]); assertEquals("EncodingScheme", isp.getEncodingScheme(), 2); @@ -108,14 +93,10 @@ public void testMarshalUnmarshal() { assertEquals("CommunicationsDeviceID", isp.getCommunicationsDeviceID(), newIsp.getCommunicationsDeviceID()); - List oldData = isp.getData(); - List retrievedData = newIsp.getData(); + byte[] oldData = isp.getData(); + byte[] retrievedData = newIsp.getData(); assertEquals("Signal data length wrong", isp.getDataLength(), newIsp.getDataLength()); - for (int idx = 0; idx < 100; idx++) { - OneByteChunk oldChunk = oldData.get(idx); - OneByteChunk newChunk = retrievedData.get(idx); - assertEquals("Signal data mismatch", oldChunk.getOtherParameters()[0], newChunk.getOtherParameters()[0]); - } + assertArrayEquals("Signal data mismatch", oldData, retrievedData); assertEquals("EncodingScheme", isp.getEncodingScheme(), newIsp.getEncodingScheme()); diff --git a/src/test/java/edu/nps/moves/dis/SetDataPduTest.java b/src/test/java/edu/nps/moves/dis/SetDataPduTest.java index 023494b4..bd921b46 100644 --- a/src/test/java/edu/nps/moves/dis/SetDataPduTest.java +++ b/src/test/java/edu/nps/moves/dis/SetDataPduTest.java @@ -42,10 +42,7 @@ public void unmarshal() throws IOException { assertEquals(1, vd.getVariableDatumID()); assertEquals(64, vd.getVariableDatumLength()); - byte[] datumValue = new byte[(int) vd.getVariableData().size()]; - for (int i = 0; i < vd.getVariableData().size(); i++) { - datumValue[i] = vd.getVariableData().get(i).getOtherParameters()[0]; - } + byte[] datumValue = vd.getVariableData(); assertEquals("allunits", new String(datumValue)); } diff --git a/src/test/java/edu/nps/moves/dis/SignalPduTest.java b/src/test/java/edu/nps/moves/dis/SignalPduTest.java index c8758252..c5dc2ca9 100644 --- a/src/test/java/edu/nps/moves/dis/SignalPduTest.java +++ b/src/test/java/edu/nps/moves/dis/SignalPduTest.java @@ -34,24 +34,16 @@ public void unmarshal() throws IOException { assertEquals(22050, spdu.getSampleRate()); assertEquals(8192, spdu.getDataLength()); assertEquals(512, spdu.getSamples()); - assertEquals(8192 / Byte.SIZE, spdu.getData().size()); + assertEquals(8192 / Byte.SIZE, spdu.getData().length); } @Test public void marshal() { SignalPdu spdu = new SignalPdu(); - List audioChunks = new ArrayList(); final int numChunks = 10; + byte[] data = new byte[numChunks]; - for (int i = 0; i < numChunks; i++) { - OneByteChunk obc = new OneByteChunk(); - byte[] onebyte = new byte[1]; - onebyte[0] = 1; // fake audio data, whatever. - obc.setOtherParameters(onebyte); - audioChunks.add(obc); - } - - spdu.setData(audioChunks); + spdu.setData(data); spdu.setDataLength((short) numChunks * Byte.SIZE); assertEquals(numChunks * Byte.SIZE, spdu.getDataLength()); diff --git a/src/test/java/edu/nps/moves/dis/VariableDatumTest.java b/src/test/java/edu/nps/moves/dis/VariableDatumTest.java index da4f4619..8b60d081 100644 --- a/src/test/java/edu/nps/moves/dis/VariableDatumTest.java +++ b/src/test/java/edu/nps/moves/dis/VariableDatumTest.java @@ -27,16 +27,7 @@ public void VariableDatumPatchTest() VariableDatum vd = new VariableDatum(); final String datum = "1234567"; // seven bytes - - List datumBytes = new ArrayList(); - for (byte b : datum.getBytes()) { - OneByteChunk obc = new OneByteChunk(); - byte[] onebyte = new byte[1]; - onebyte[0] = b; - obc.setOtherParameters(onebyte); - datumBytes.add(obc); - } - + byte[] datumBytes = datum.getBytes(); vd.setVariableData(datumBytes); assertEquals(56, vd.getVariableDatumLength()); // Ensure length is in bits.