Class NumericFormatCompressed

Direct Known Subclasses:
NumericFormatBinary, NumericFormatBinaryX, NumericFormatDouble, NumericFormatPackedDecimal

public abstract class NumericFormatCompressed extends NumericFormat
Provides a formatter that emulates COBOL's NumericFormatCompressed (COMP-3) functionality in Java. Given a decimal value and specified integer and fractional digit counts, this class:
1) encodes the value into packed decimal (two digits per byte, high-order nibble first)
2) appends a sign nibble ('C','D','F') in the low-order nibble of the last byte
3) decodes packed decimal back into numeric values, respecting sign and scale
4) enforces correct byte length based on digit counts
This implementation delivers a reliable, high-performance Java equivalent of COBOL's compressed numeric format for mission-critical data-conversion workflows.
  • Constructor Details

    • NumericFormatCompressed

      protected NumericFormatCompressed(String picture)
  • Method Details

    • isCompressed

      public final boolean isCompressed()
      Specified by:
      isCompressed in class Format
    • convertFromCompressedStorageToDisplayFormat

      public abstract String convertFromCompressedStorageToDisplayFormat(String formattedString)
      Convert from Storage-Compressed to Display This methods returns the actual stored value, even it is bigger than the defined format.
      E.g. PIC 9(2) COMP can store a value of 30000 ! This method will return "30000", but convertFromStorageToDisplayFormat will return "30".
      Parameters:
      formattedString -
      Returns:
    • convertFromDisplayToStorage

      public String convertFromDisplayToStorage(double value, boolean[] sizeError)
      format a value according to the PIC definition
      Specified by:
      convertFromDisplayToStorage in class Format
    • convertFromDisplayToStorage

      public String convertFromDisplayToStorage(String _value, boolean[] sizeError)
      format a value according to the PIC definition
      Specified by:
      convertFromDisplayToStorage in class Format
    • convertFromDisplayToStorage

      public String convertFromDisplayToStorage(BigDecimal value, boolean[] sizeError)
      format a value according to the PIC definition
      Specified by:
      convertFromDisplayToStorage in class Format
    • convertFromDisplayToStorage

      public String convertFromDisplayToStorage(BigInteger value, boolean[] sizeError)
      format a value according to the PIC definition
      Specified by:
      convertFromDisplayToStorage in class Format