objectidentifier.java

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

JAVA
184
字号
/* * 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 *///  $Id: ObjectIdentifier.java,v 1.2 2000/09/05 13:30:55 festor Exp $//  $Source: /local/resedas/CVS-Repository/CmisJavaApi/src/fr/dyade/cmis/api/types/ObjectIdentifier.java,v $////  Todopackage fr.dyade.cmis.api.types;import java.lang.*;/**  *  Java representation for ASN.1 ObjectIdentifier datatype.  *  <p>  *  The implementation uses an array of <code>int</code> values. However, it can be instanciated by two ways:  *  <menu>  *     <li> giving a <code>int</code> array as parameter to the constructor,  *     <li> giving a <code>String</code> form of the ObjectIdentifier, where all <code>int</code> values are separated by "." (eg. "102.2176.21.1.1")  *  </menu>  *   * @version cvs $Id: ObjectIdentifier.java,v 1.2 2000/09/05 13:30:55 festor Exp $  */public class ObjectIdentifier extends Value implements Comparable {      /**	* Creates a new instance of ObjectIdentifier from its array representation.	* @param pValues The <code>int</code> array of values to build the <code>ObjectIdentifier</code>	*/      public ObjectIdentifier(int pValues[]) {	 super(VALUE_OBJECT_IDENTIFIER);	 fValues = pValues;      }      /**	* Creates a new instance of ObjectIdentifier form its string representation (eg. "102.2176.21.1.1")	* @param pStringValues The <code>String</code> representation of the <code>ObjectIdentifier</code>. 	* Integer values must be separated by '.'.	* Note: if a java.lang.NumberFormatException is thrown when calling this constructor that 	* probably means that the parameter has a bad dotted notation format.	*/      public ObjectIdentifier(String pStringValues) {	 super(VALUE_OBJECT_IDENTIFIER);	 // Extract values from String parameter	 int lgth, i, j, lastI;	 lgth = pStringValues.length();	 i=0;	 	 // First count the number of Long...	 j = 1;	 for(i=0;i<lgth;i++){	    if (pStringValues.charAt(i) == '.')	       j++;	 }	 fValues = new int[j];	 	 lastI = 0; 	 i=0;	 j=0;	 while (i<lgth){	    if (pStringValues.charAt(i) == '.'){	       fValues[j] = Integer.parseInt(pStringValues.substring(lastI, i));	       lastI = i+1; 	       j++;	    }	    i++;	 }	 fValues[j] = Integer.parseInt(pStringValues.substring(lastI, lgth));      }            /**	*  Returns a String representation of the ObjectIdentifier (eg. "102.2176.21.1.1")	*  @return The <code>String</code> representation of the <code>ObjectIdentifier</code>.	*/      public String toString() {	 String result;	 int i;	 	 if (fValues.length == 0)	    return "";	 	 result = Integer.toString(fValues[0]);	 	 for(i=1; i< fValues.length; i++)	    result = result + "." + Integer.toString(fValues[i]);	 	 return result;      }            /**	*    Returns the <code>int</code> array of form the ObjectIdentifier.	* @return The <code>int</code> array representation of the <code>ObjectIdentifier</code>.	*/      public int[] getID() {	 return fValues;      }            /**	* To compare equality of ObjectIdentifiers	* Mandatory to use ObjectIdentifier in hastable. 	* @return true, if both <code>ObjectIdentifiers</code> have the same value.	* <p> This method is a true "deep" equal: test goes through OID integer elements.	*/      public boolean equals( Object other ){	 int otherValues[] = ((ObjectIdentifier)other).getID();      	 if (otherValues.length == fValues.length) {	    for (int i=0; i<fValues.length; i++)	       if (fValues[i] != otherValues[i])		  return false;	    return true;	 }	 	 return false;      }      /**	* To compare 2 Objectifier	* Mandatory to use ObjectIdentifier 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	*/      public int compareTo(Object other) {	  int otherValues[] = ((ObjectIdentifier)other).getID();	  int lgThis=fValues.length;	  int lgOther=otherValues.length;	  int min=(lgThis<lgOther)?lgThis:lgOther;	  for (int i=0; i<min; i++) {	     int vThis=fValues[i];	     int vOther=otherValues[i];	     if (vThis<vOther) return -1;	     if (vThis>vOther) return 1;	  }	  // the shorter is a prefix of the longer...	  if (lgThis<lgOther) return -1;	  if (lgThis>lgOther) return 1;	  return 0;      }      /** Hash function to allow use as index.	* Mandatory to use ObjectIdentifier in hastable.	* The idea is that the last numbers of an oid is have problably	* a better dispertion than the beginning where many enterprises prefix	* occur.	* TODO: PROFIL this function.	* @see java.lang.Object#hashCode	*/      public int hashCode(){	 switch(fValues.length) {	    case 0: return 0; 	    case 1: return fValues[0]; 	    default: return fValues[fValues.length-1]*10+fValues[fValues.length-2];	 }      }      // the array of integers      private int fValues[];      } // ObjectIdentifier

⌨️ 快捷键说明

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