Class AmexField<M,T>

java.lang.Object
cl.netswitch.iso.amex8583.AmexField<M,T>
Type Parameters:
M - the type of the AMEX message.
T - the type of the field value.
Direct Known Subclasses:
AmexBinF4, AmexBinF8, AmexBinH4, AmexDecFL, AmexNumF1, AmexNumF10, AmexNumF11, AmexNumF12, AmexNumF2, AmexNumF3, AmexNumF4, AmexNumF5, AmexNumF6, AmexNumF7, AmexNumF8, AmexNumF9, AmexNumFX, AmexNumV2L, AmexNumV2X, AmexStrFL, AmexStrV2, AmexStrV3

public abstract class AmexField<M,T> extends Object
Definition of a data element of an AMEX message.
  • Constructor Details

    • AmexField

      public AmexField(int index, String format, int minlen, int maxlen, Class<T> vtype, String name)
      Constructs a new AmexField instance.
      Parameters:
      index - the index of this field.
      format - the format of this field.
      minlen - min number of elements of this field value.
      maxlen - max number of elements of this field value.
      vtype - the class type of this field value.
      name - the name of this field.
      Throws:
      NullPointerException - if an argument is null.
      IllegalArgumentException - if an argument is invalid.
  • Method Details

    • getIndex

      public final int getIndex()
      Returns the index of this field.
      Returns:
      the index of this field.
    • getFormat

      public final String getFormat()
      Returns the name of the format of this field.
      Returns:
      the name of the format of this field.
    • getMinLength

      public final int getMinLength()
      Returns the minimum length of this field.
      Returns:
      the minimum length of this field.
    • getMaxLength

      public final int getMaxLength()
      Returns the maximum length of this field.
      Returns:
      the maximum length of this field.
    • getName

      public final String getName()
      Returns the name of this field.
      Returns:
      the name of this field.
    • getType

      public final Class<T> getType()
      Returns the type of the value of this field.
      Returns:
      the type of the value of this field.
    • getObfuscate

      public final AmexObfuscate getObfuscate()
      Returns the obfuscate option of this field.
      Returns:
      the obfuscate option of this field.
    • setObfuscate

      public final void setObfuscate(AmexObfuscate obfuscate)
      Changes the obfuscate option of this field.
      Parameters:
      obfuscate - the new obfuscate option.
      Throws:
      NullPointerException - if obfuscate is null.
    • decodeAndSetValue

      public final T decodeAndSetValue(ByteBuffer buffer, M message)
      Decodes the field value from buffer and stores value in message.
      Parameters:
      buffer - the buffer containing the encoded field value.
      message - the message where the field value is stored.
      Returns:
      the non-null field value decoded from buffer.
      Throws:
      NullPointerException - if an argument is null.
      AmexException - if an expected decoder error occurs.
    • setValue

      public final void setValue(M message, T value)
      Changes the value of this field in the supplied message.
      Parameters:
      message - the message to be modified.
      value - the new value of this field (can be null).
      Throws:
      NullPointerException - if message is null.
      IllegalArgumentException - if value is invalid.
      AmexException - if another error occurs changing the value.
    • decodeValue

      public abstract T decodeValue(ByteBuffer buffer)
      Decodes the value of this field from the supplied byte buffer.
      Parameters:
      buffer - the buffer containing the encoded field value.
      Returns:
      the value decoded from supplied byte buffer.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • getValueAndEncode

      public final T getValueAndEncode(M message, ByteArray barray)
      Gets the field value from message and encodes into supplied byte array.
      Parameters:
      message - the message that contains the field value.
      barray - the byte array containing encoded field values.
      Returns:
      the field value that was encoded into the byte array.
      Throws:
      NullPointerException - if an argument is null.
      ClassCastException - if the field value is of wrong type.
      AmexException - if the field value in message is invalid.
    • getValue

      public final T getValue(M message)
      Returns the value of this field from the supplied message.
      Parameters:
      message - the message that contains the field value.
      Returns:
      the value of this field read from supplied message.
      Throws:
      NullPointerException - if message is null.
      ClassCastException - if the retrieved value is invalid.
      AmexException - if another error occurs getting the value.
    • encodeValue

      public abstract void encodeValue(T value, ByteArray barray)
      Encodes the value of this field into the supplied byte array.
      Parameters:
      value - the field value to be encoded into byte array.
      barray - the byte array containing encoded field values.
      Throws:
      NullPointerException - if an argument is null.
      AmexException - if value is invalid.
    • writeMessageValue

      public final void writeMessageValue(M message, AmexWriter<M> writer)
      Writes the field value contained in message using writer.
      Parameters:
      message - the message that contains the field value.
      writer - the writer used to write the field value.
      Throws:
      NullPointerException - if an argument is null.
      ClassCastException - if type of field value is invalid.
      AmexException - if another error occurs.
    • writeValue

      protected void writeValue(T value, AmexWriter<M> writer)
      Writes the supplied field value using the specified writer.
      Parameters:
      value - the field value to write with writer.
      writer - the writer used to write the field value.
      Throws:
      NullPointerException - if an argument is null.
      AmexException - if another error occurs.
    • fieldError

      public final String fieldError(String error)
      Returns a string used to build exception related to this field.
      Parameters:
      error - a description of the error condition found.
      Returns:
      a string used to build errors related to this field.
    • rightTrim

      public final String rightTrim(String str)
      Returns the supplied string with trailing spaces removed.
      Parameters:
      str - the string to be inspected.
      Returns:
      the supplied string with trailing spaces removed.
      Throws:
      NullPointerException - if str is null.
    • readFieldBuffer

      public final ByteBuffer readFieldBuffer(ByteBuffer buffer, int length)
      Returns a ByteBuffer with the bytes of the specified length.
      Parameters:
      buffer - the buffer containing the variable-length field value.
      length - the number of bytes to read in buffer.
      Returns:
      a ByteBuffer with the byte array of the specified length.
      Throws:
      NullPointerException - if buffer is null.
      BufferUnderflowException - if buffer is missing bytes.
    • readDigit

      public final byte readDigit(ByteBuffer buffer)
      Returns a byte with the value of a numeric digit.
      Parameters:
      buffer - the buffer containing the digit.
      Returns:
      a byte with the value of a numeric digit.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • readNumber1

      public final byte readNumber1(ByteBuffer buffer)
      Returns a byte with the value of a 1 digit number.
      Parameters:
      buffer - the buffer containing the digit.
      Returns:
      a byte with the value of a 1 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber1

      public final void writeNumber1(byte value, ByteArray barray)
      Writes 1 digit of supplied byte value to a byte array.
      Parameters:
      value - the byte value to be written to barray.
      barray - the byte array where the digit are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber2

      public final byte readNumber2(ByteBuffer buffer)
      Returns a byte with the value of a 2 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      a byte with the value of a 2 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber2

      public final int writeNumber2(byte value, ByteArray barray)
      Writes 2 digits of supplied byte value to a byte array.
      Parameters:
      value - the byte value to be written to barray.
      barray - the byte array where the digits are written.
      Returns:
      the absolute index where the byte value was written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber3

      public final short readNumber3(ByteBuffer buffer)
      Returns a short with the value of a 3 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      a short with the value of a 3 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber3

      public final int writeNumber3(short value, ByteArray barray)
      Writes 3 digits of a short value to a byte array.
      Parameters:
      value - the short value to be written to barray.
      barray - the byte array where the digits are written.
      Returns:
      the absolute index where the short value was written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • writeNumberLLL

      public final void writeNumberLLL(ByteArray barray, int position)
      Writes 3 digits of field length to a byte array at position.
      Parameters:
      barray - the byte array where the digits are written.
      position - the absolute position to write the field length.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber4

      public final short readNumber4(ByteBuffer buffer)
      Returns a short with the value of a 4 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      a short with the value of a 4 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber4

      public final int writeNumber4(short value, ByteArray barray)
      Writes 4 digits of supplied short value to a byte array.
      Parameters:
      value - the short value to be written to barray.
      barray - the byte array where the digits are written.
      Returns:
      the absolute index where the short value was written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber5

      public final int readNumber5(ByteBuffer buffer)
      Returns an integer with the value of a 5 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      an integer with the value of a 5 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber5

      public final void writeNumber5(int value, ByteArray barray)
      Writes 5 digits of supplied integer value to a byte array.
      Parameters:
      value - the integer value to be written to barray.
      barray - the byte array where the digits are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber6

      public final int readNumber6(ByteBuffer buffer)
      Returns an integer with the value of a 6 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      an integer with the value of a 6 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber6

      public final void writeNumber6(int value, ByteArray barray)
      Writes 6 digits of supplied integer value to a byte array.
      Parameters:
      value - the integer value to be written to barray.
      barray - the byte array where the digits are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber7

      public final int readNumber7(ByteBuffer buffer)
      Returns an integer with the value of a 7 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      an integer with the value of a 7 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber7

      public final void writeNumber7(int value, ByteArray barray)
      Writes 7 digits of supplied integer value to a byte array.
      Parameters:
      value - the integer value to be written to barray.
      barray - the byte array where the digits are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber8

      public final int readNumber8(ByteBuffer buffer)
      Returns an integer with the value of a 8 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      an integer with the value of a 8 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber8

      public final void writeNumber8(int value, ByteArray barray)
      Writes 8 digits of supplied integer value to a byte array.
      Parameters:
      value - the integer value to be written to barray.
      barray - the byte array where the digits are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber9

      public final int readNumber9(ByteBuffer buffer)
      Returns an integer with the value of a 9 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      an integer with the value of a 9 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber9

      public final void writeNumber9(int value, ByteArray barray)
      Writes 9 digits of supplied integer value to a byte array.
      Parameters:
      value - the integer value to be written to barray.
      barray - the byte array where the digits are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber10

      public final long readNumber10(ByteBuffer buffer)
      Returns a long with the value of a 10 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      a long with the value of a 10 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber10

      public final void writeNumber10(long value, ByteArray barray)
      Writes 10 digits of supplied long value to a byte array.
      Parameters:
      value - the long value to be written to barray.
      barray - the byte array where the digits are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber11

      public final long readNumber11(ByteBuffer buffer)
      Returns a long with the value of a 11 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      a long with the value of a 11 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber11

      public final void writeNumber11(long value, ByteArray barray)
      Writes 11 digits of supplied long value to a byte array.
      Parameters:
      value - the long value to be written to barray.
      barray - the byte array where the digits are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber12

      public final long readNumber12(ByteBuffer buffer)
      Returns a long with the value of a 12 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      a long with the value of a 12 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber12

      public final void writeNumber12(long value, ByteArray barray)
      Writes 12 digits of supplied long value to a byte array.
      Parameters:
      value - the long value to be written to barray.
      barray - the byte array where the digits are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readNumber14

      public final long readNumber14(ByteBuffer buffer)
      Returns a long with the value of a 14 digit number.
      Parameters:
      buffer - the buffer containing the digits.
      Returns:
      a long with the value of a 14 digit number.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeNumber14

      public final void writeNumber14(long value, ByteArray barray)
      Writes 14 digits of supplied long value to a byte array.
      Parameters:
      value - the long value to be written to barray.
      barray - the byte array where the digits are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if value is out-of-range.
    • readBigDecimal

      public final BigDecimal readBigDecimal(ByteBuffer buffer, int length)
      Returns a BigDecimal value of length digits.
      Parameters:
      buffer - the buffer containing the digits.
      length - the number of digits of the value.
      Returns:
      a BigDecimal value read from supplied buffer.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • readBigInteger

      public final BigInteger readBigInteger(ByteBuffer buffer, int length)
      Returns a BigInteger value of length digits.
      Parameters:
      buffer - the buffer containing the digits.
      length - the number of digits of the value.
      Returns:
      a BigInteger value read from supplied buffer.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • checkNumericString

      public final void checkNumericString(String text)
      Checks that all the characters of the supplied string are digits.
      Parameters:
      text - the string to be inspected and checked.
      Throws:
      NullPointerException - if text is null.
      AmexException - if text contains non-digit chars.
    • strFromEBCDIC

      public final String strFromEBCDIC(ByteBuffer buffer)
      Converts a ByteBuffer to a string using EBCDIC encoding.
      Parameters:
      buffer - the byte buffer to be converted.
      Returns:
      a string created using supplied EBCDIC byte buffer.
      Throws:
      NullPointerException - if buffer is null.
    • strToEBCDIC

      public final byte[] strToEBCDIC(String str)
      Converts a string to a byte array using EBCDIC encoding.
      Parameters:
      str - the string to be converted.
      Returns:
      the EBCDIC byte array obtain from supplied string.
      Throws:
      NullPointerException - if str is null.
    • chrToEBCDIC

      public final byte chrToEBCDIC(char ch)
      Converts a character to a byte using EBCDIC encoding.
      Parameters:
      ch - the character to be converted.
      Returns:
      the a character to a byte using EBCDIC encoding.
    • readChar

      public final char readChar(ByteBuffer buffer)
      Returns the EBCDIC character contained in supplied buffer.
      Parameters:
      buffer - the buffer containing the EBCDIC character.
      Returns:
      the EBCDIC character contained in supplied buffer.
      Throws:
      NullPointerException - if buffer is null.
      BufferUnderflowException - if buffer is missing bytes.
    • writeChar

      public final void writeChar(char ch, ByteArray barray)
      Writes an EBCDIC character in supplied byte array.
      Parameters:
      ch - the EBCDIC character to write in barray.
      barray - the byte array where the character is written.
      Throws:
      NullPointerException - if barray is null.
    • writeChar

      public final void writeChar(Character ch, char defval, ByteArray barray)
      Writes an EBCDIC character in supplied byte array.
      Parameters:
      ch - the EBCDIC character to write in barray.
      defval - the default value written if ch is null.
      barray - the byte array where the character is written.
      Throws:
      NullPointerException - if barray is null.
    • readString

      public final String readString(ByteBuffer buffer, int length, boolean rtrim)
      Returns an EBCDIC string of specified length.
      Parameters:
      buffer - the buffer containing the EBCDIC string.
      length - the number of character of the EBCDIC string.
      rtrim - if true trailing spaces are removed.
      Returns:
      an EBCDIC string of specified length.
      Throws:
      NullPointerException - if buffer is null.
      IllegalArgumentException - if length is negative.
      BufferUnderflowException - if buffer is missing bytes.
    • writeString

      public final void writeString(String value, int length, char fill, ByteArray barray)
      Writes a left-justified fixed-length EBCDIC string to a byte array.
      Parameters:
      value - the string to convert and write in barray (can be null).
      length - the number of characters to write with padding.
      fill - the character used to right-fill to complete length.
      barray - the byte array where the resulting bytes are written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if string value is too long.
    • writeString

      public final void writeString(char fill, String value, int length, ByteArray barray)
      Writes a right-justified fixed-length EBCDIC string to a byte array.
      Parameters:
      fill - the character used to left-fill to complete length.
      value - the string to be written to barray (can be null).
      length - the length of the fixed-length of the string.
      barray - the byte array where the string is written.
      Throws:
      NullPointerException - if barray is null.
      AmexException - if string value is too long.
    • readHexBytes

      public final byte[] readHexBytes(ByteBuffer buffer, int length)
      Reads EBCDIC-500 hexadecimal characters and returns the converted bytes.
      Parameters:
      buffer - the buffer containing hexadecimal characters.
      length - the number of hexadecimal characters to read.
      Returns:
      the byte array built using input hexadecimal characters.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if length is negative or not even.
      BufferUnderflowException - if buffer is missing bytes.
    • writeHexBytes

      public final void writeHexBytes(byte[] bytes, int length, ByteArray barray)
      Writes the EBCDIC-500 hexadecimal characters of bytes into byte array.
      Parameters:
      bytes - the array of bytes to be converted.
      length - the number of hexadecimal characters to write.
      barray - the byte array where the bytes are written.
      Throws:
      NullPointerException - if an argument is null.
      AmexException - if bytes is too long.
    • readHex8

      public final int readHex8(ByteBuffer buffer)
      Reads 8 EBCDIC-500 hexadecimal characters and converts them to integer.
      Parameters:
      buffer - the buffer containing hexadecimal characters.
      Returns:
      the integer built with input hexadecimal characters.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeHex8

      public final void writeHex8(int value, ByteArray barray)
      Writes 8 EBCDIC-500 hexadecimal characters of an integer into byte array.
      Parameters:
      value - the long to be converted and written to barray.
      barray - the byte array where the long is written.
      Throws:
      NullPointerException - if barray is null.
    • readHex16

      public final long readHex16(ByteBuffer buffer)
      Reads 16 EBCDIC-500 hexadecimal characters and converts them to long.
      Parameters:
      buffer - the buffer containing hexadecimal characters.
      Returns:
      the long built with input hexadecimal characters.
      Throws:
      NullPointerException - if buffer is null.
      AmexException - if contents of buffer is invalid.
      BufferUnderflowException - if buffer is missing bytes.
    • writeHex16

      public final void writeHex16(long value, ByteArray barray)
      Writes 16 EBCDIC-500 hexadecimal characters of a long into byte array.
      Parameters:
      value - the long to be converted and written to barray.
      barray - the byte array where the long is written.
      Throws:
      NullPointerException - if barray is null.