asn1enum.java

来自「CmisJavaApi」· Java 代码 · 共 151 行

JAVA
151
字号
/* * The contents of this file are subject to the Dyade Public License,  * as defined by the file DYADE_PUBLIC_LICENSE.TXT * * You may not use this file except in compliance with the License. You may * obtain a copy of the License on the Dyade web site (www.dyade.fr). * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific terms governing rights and limitations under the License. * * The Original Code is CmisJava API, including the java package  * fr.dyade.cmis, released September 5, 2000. * * The Initial Developer of the Original Code is Dyade. The Original Code and * portions created by Dyade are Copyright Bull and Copyright INRIA.  * All Rights Reserved. *//*      Copyright 1996-2000 by Institut National de Recherche en Informatique  *                             et en Automatique (INRIA) *          All rights reserved.  See COPYRIGHT in top-level directory. * *      Authors: Laurent Andrey, Eric Dillon, Olivier Festor *///---------------------------------------------------------------------------////  CVS Info//---------------------------------------------------------------------------//////  $Id: ASN1Enum.java,v 1.2 2000/09/05 13:30:23 festor Exp $////---------------------------------------------------------------------------////  Todo//---------------------------------------------------------------------------//package fr.dyade.cmis.api.types;import fr.dyade.cmis.api.ASN1BadlyFormedValueException;/** Java representation of the ASN.1 Enum type.  * This representation of ASN1 Enumerate type is more than simple: only the  * actual value is kept. No label is avaible (no extra data). On "sender" this  * this class can be derived to a class than validate (restriction) the actual value,  * but on sender side this type will be lost and only ANS1Enum occurrences would be   * built.  * <p>  * A poor mecanism is provided for "sender side": the {@link #validateValue(int) validateValue} method can be   * overriden in sub classes to filter value at construction time or in {@link #setValue(int) setValue} method.  * When an out of range value tries to be used an {@link fr.dyade.cmis.api.ASN1BadlyFormedValue   * ANS1BadlyFormedValueException} is thrown. <b>Default</b><code>validateMethod()</code>   * returns an never throws any exception (indeed default accepts any integer). An overriden method would throw a   * <code>ASN1BadlyFormedValue</code> may be with some message when a value is <b>not</b> in the enumerate type.  * <p>  * <b>Note</b>: If you are deriving this class you will probably need to override the   * {@link #validateValue(int) validateValue} and {@link #equals(Object) equals} methods. The   * {@link #compareTo(Object) compareTo} and {@link hashCode() hashCode} methods  * would probably be kept untouched.  *  * @version cvs $Id: ASN1Enum.java,v 1.2 2000/09/05 13:30:23 festor Exp $  */public class ASN1Enum  extends Valueimplements Comparable {      /**	* Creates a new instance of ASN1Enum class.	* @param pValue the initial value for this <code>ASN1Enum</code>	* @exception ASN1BadlyFormedValueException if the value parameter is out of range for this enumerate	*/      public ASN1Enum(int pValue) throws ASN1BadlyFormedValueException {	  super(VALUE_ENUM);	  setValue(pValue);      }            /**	*  Returns a <code>String</code> representation of the ASN1Enum.	*  @return A String conversion of the Enum Value.	*/      public String toString() {	 return (Integer.toString(fValue));      }        /**	*  Returns the <code>int</code> value of the ASN1Enum object.	*  @return The <code>int</code> value of the ASN1Enum object.	*/      public int getValue() {	 return fValue;      }      /** Set the value for this enum.        * @param pValue the integer value to set for this enumerate	* @ASN1BadlyFormedValueException if the value parameter is out of range for this enumerate        */      public void setValue(int pValue) throws ASN1BadlyFormedValueException {	  validateValue(pValue);	  this.fValue=pValue;      }      /** Validate a value to be set for this enumerate.        * @param pValue the integer value to be set	* @exception ASN1BadlyFormedValue if the value parameter is not in the range of this enumerate	* <br><b>Note</b>: This method is dedicated to be overriden in sub classes to filter value	* used in constructeur or {@ling #setValue(int) setValue} method.s        */      public void validateValue(int pValue) throws ASN1BadlyFormedValueException {	  return;      }      /**	*  Returns the <code>int</code> value of the ASN1Enum object.	*  @return The <code>int</code> value of the ASN1Enum object.	*/      public int toInteger() {	 return fValue;      }            /**	* To compare equality of ASN1Enum	* Mandatory to use ObjectIdentifier in hastable. 	* @return true, if both internal native int have the same value.	*/      public boolean equals( Object other ){	 return (other instanceof ASN1Enum ? (fValue==((ASN1Enum)other).fValue) : false);      }      /**	* To compare this ASN1Enum versus any object.	* Mandatory to use ASN1Enum in ordered container.	* @return a negative integer, zero, or a positive integer 	* as this Object is less than, equal to, or greater than the given Object	* Mandatory by Comparable interface.	*/      public int compareTo(Object other) {	 int otherValue=((ASN1Enum)other).fValue;	 if (fValue<otherValue) return -1;	 if (fValue==otherValue) return 0;	 return 1;      }            /** Hash function to allow use as index.	* Mandatory to use ASN1Enum in hastable.	* TODO: PROFIL this function.	* @see java.lang.Object#hashCode	*	* NOTE: currently this function return the internal native java int value.	*/      public int hashCode(){	 return fValue;      }      private int fValue;  } // ASN1Enum

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?