# unknown.java

    /*
    ** Module   : unknown.java
    ** Abstract : Progress 4GL compatible unknown object
    **
    ** Copyright (c) 2005-2023, Golden Code Development Corporation.
    **
    ** -#- -I- --Date-- --JPRM-- ---------------------------Description-----------------------------
    ** 001 GES 20050601   @21363 Created initial version which represents the Progress unknown value
    **                           literal.
    ** 002 GES 20050606   @21426 Minor addition to support new method reqt.
    ** 003 SVG 20050720   @21766 Cloning support for BaseDataType added.
    ** 004 GES 20050815   @22122 Added Undoable interface support.
    ** 005 ECF 20051005   @22972 Implement hashCode() method. Required to be consistent with
    **                           BaseDataType's implementation of equals() method.
    ** 006 GES 20060208   @24394 Added a default format string getter.
    ** 007 GES 20060724   @28164 Added a forced assign() abstract method.
    ** 008 GES 20060807   @28477 Moved to externalizable interface to optimize network performance.
    ** 009 GES 20171207          Removed explicit bypass on pending error (new silent error mode).
    ** 010 IAS 20201007          Added Type enum
    ** 011 CA  20230215          Added unknown.UNKNOWN singleton (used by FWD runtime at this time).
    **     CA  20230215          'duplicate()' method returns the real type instead of BDT.
    */

    /*
    ** This program is free software: you can redistribute it and/or modify
    ** it under the terms of the GNU Affero General Public License as
    ** published by the Free Software Foundation, either version 3 of the
    ** License, or (at your option) any later version.
    **
    ** This program is distributed in the hope that it will be useful,
    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ** GNU Affero General Public License for more details.
    **
    ** You may find a copy of the GNU Affero GPL version 3 at the following
    ** location: https://www.gnu.org/licenses/agpl-3.0.en.html
    **
    ** Additional terms under GNU Affero GPL version 3 section 7:
    **
    **   Under Section 7 of the GNU Affero GPL version 3, the following additional
    **   terms apply to the works covered under the License.  These additional terms
    **   are non-permissive additional terms allowed under Section 7 of the GNU
    **   Affero GPL version 3 and may not be removed by you.
    **
    **   0. Attribution Requirement.
    **
    **     You must preserve all legal notices or author attributions in the covered
    **     work or Appropriate Legal Notices displayed by works containing the covered
    **     work.  You may not remove from the covered work any author or developer
    **     credit already included within the covered work.
    **
    **   1. No License To Use Trademarks.
    **
    **     This license does not grant any license or rights to use the trademarks
    **     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
    **     of Golden Code Development Corporation. You are not authorized to use the
    **     name Golden Code, FWD, or the names of any author or contributor, for
    **     publicity purposes without written authorization.
    **
    **   2. No Misrepresentation of Affiliation.
    **
    **     You may not represent yourself as Golden Code Development Corporation or FWD.
    **
    **     You may not represent yourself for publicity purposes as associated with
    **     Golden Code Development Corporation, FWD, or any author or contributor to
    **     the covered work, without written authorization.
    **
    **   3. No Misrepresentation of Source or Origin.
    **
    **     You may not represent the covered work as solely your work.  All modified
    **     versions of the covered work must be marked in a reasonable way to make it
    **     clear that the modified work is not originating from Golden Code Development
    **     Corporation or FWD.  All modified versions must contain the notices of
    **     attribution required in this license.
    */

    package com.goldencode.p2j.util;

    import java.io.*;

    import com.goldencode.p2j.util.BaseDataType.*;

    /**
     * A class that represents a Progress 4GL compatible unknown value literal.
     *
     * @author    GES
     */
    public class unknown
    extends BaseDataType
    {
       /** Singleton instance (as this is immutable) which can be used in FWD runtime. */
       public static final unknown UNKNOWN = new unknown();

       /**
        * Default constructor, creates an instance that represents the unknown
        * value.
        */
       public unknown()
       {
       }

       /**
        * Creates a new instance of the same type that represents the
        * <code>unknown value</code>.
        *
        * @return   An instance that represents the <code>unknown value</code>.
        */
       public BaseDataType instantiateUnknown()
       {
          return UNKNOWN;
       }

       /**
        * Creates a new instance of the same type that represents the default initialized value.
        *
        * @return   An instance that represents the default value.
        */
       @Override
       public BaseDataType instantiateDefault()
       {
          return UNKNOWN;
       }

       /**
        * Get the type
        * @return type
        */
       public Type getType()
       {
          return Type.UNKNOWN;
       }

       /**
        * Does the same as standard <code>clone()</code> method but returns an
        * instance of <code>BaseDataType</code> and doesn't throw the
        * <code>CloneNotSupportedException</code>.
        *
        * @return   A clone of this instance.
        */
       public unknown duplicate()
       {
          return UNKNOWN;
       }

       /**
        * Hash code implementation which is consistent with {@link
        * BaseDataType#equals}.
        *
        * @return  Hash code value for this object instance. All instances of
        *          this class return the same hash code value, since all
        *          instances are inherently equal.
        */
       public int hashCode()
       {
          return 17;
       }

       /**
        * Determines if this instance represents the <code>unknown value</code>
        * (which is always the case).
        *
        * @return   Always <code>true</code>.
        */
       public boolean isUnknown()
       {
          return true;
       }

       /**
        * This instance always represents the <code>unknown value</code> so this
        * method does nothing.
        */
       public void setUnknown()
       {
          // nothing to do (we have no data!)
       }

       /**
        * Sets the state (data and unknown value) of this instance based on the
        * state of the passed instance.
        *
        * @param    value
        *           The instance from which to copy state.
        */
       public void assign(BaseDataType value)
       {
          // nothing to do (we have no data!)
       }

       /**
        * Modify the contained data of the instance to copy the instance data
        * from the given instance.  Generally, the class of the given instance
        * must match the class upon which the <code>assign</code> method is
        * called, although this is not a strict requirement.
        *
        * @param    old
        *           The backup instance from which to copy data.
        */
       public void assign(Undoable old)
       {
          // nothing to do (we have no data!)
       }

       /**
        * Compares this instance with the specified instance and returns a 0 if
        * the two instances are both <code>unknown</code> and 1 if the passed
        * instance is not <code>unknown</code>.  This is the implementation of
        * the <code>Comparable</code> interface, although the contract is not
        * really correct.  It is best NOT to use this method (it is required
        * as a concrete subclass of <code>BaseDataType</code>.
        *
        * @param    obj
        *           The instance to compare against.
        *
        * @return   0 or 1 depending on if the passed instance is or is not
        *           <code>unknown</code>.
        */
       public int compareTo(Object obj)
       {
          int result = 0;

          if (obj instanceof unknown || ((obj instanceof BaseDataType) && ((BaseDataType) obj).isUnknown()))
          {
             result = 0;
          }
          else
          {
             result = 1;
          }

          return result;
       }

       /**
        * Creates a string representation of the <code>unknown value</code> which
        * is always '?'.
        *
        * @return   The formatted string.
        */
       public String toString()
       {
          return "?";
       }

       /**
        * Creates a string representation of the <code>unknown value</code> which
        * is always '?'.
        *
        * @param    fmt
        *           Format string. Ignored at this time.
        *
        * @return   The formatted string.
        */
       public String toString(String fmt)
       {
          return toString();
       }

       /**
        * Creates a string representation of the instance data in a form that is
        * compatible with the <code>MESSAGE</code> language statement.  If the
        * instance represents the <code>unknown value</code>, a '?' will be
        * returned.
        *
        * @return   The 'message' formatted string.
        */
       public String toStringMessage()
       {
          return toString();
       }

       /**
        * Creates a string representation of the <code>unknown value</code> which
        * is always '?'.
        *
        * @return   The 'export' formatted string.
        */
       public String toStringExport()
       {
          return toString();
       }

       /**
        * Return the default display format string for this type.
        *
        * @return   The default format string.
        */
       public String defaultFormatString()
       {
          return "?";
       }

       /**
        * Replacement for the default object reading method. The latest
        * state is read from the input source.
        *
        * @param    in
        *           The input source from which fields will be restored.
        *
        * @throws   IOException
        *           In case of I/O errors.
        * @throws   ClassNotFoundException
        *           If payload can't be instantiated.
        */
       public void readExternal(ObjectInput in)
       throws IOException,
              ClassNotFoundException
       {
          // nothing to do
       }

       /**
        * Replacement for the default object writing method. The latest
        * state is written to the output destination.
        *
        * @param    out
        *           The output destination to which fields will be saved.
        *
        * @throws   IOException
        *           In case of I/O errors.
        */
       public void writeExternal(ObjectOutput out)
       throws IOException
       {
          // nothing to do
       }
    }