www.pudn.com > sxg.rar > GwOID.java


/*
 * Copyright (c) 2003 Jens Mueller
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/**
 	An instance of this class represents an OBJECT IDENTIFIER
  
 	@author jens mueller
 */

public class GwOID
{
	
	private String _oid;

	/**
	 	Constructs a new GwOID 

	 	@param oid  the textual dotted representation of the OBJECT IDENTIFIER 	 */	
	public GwOID( String oid )
	{
		_oid = oid;
	}
	
	/**
	 	@return String  the textual dotted representation of the OBJECT IDENTIFIER
	 	@see java.lang.Object#toString() 	 */
	public String toString()
	{
		return _oid;
	}
	
	/**
	 	Returns a new GwOID instance representing the parent of this OBJECT IDENTIFIER.

	 	@return the parent GwOID 	 */
	public GwOID getParentOid()
	{
		String oidstring = _oid.toString();
		int i = oidstring.length() - 1;
		while ( i > -1 && oidstring.charAt( i ) != '.' )
		{
			i--;
		}
		if ( i > 0 )
			return new GwOID( oidstring.substring( 0, i ) );
		else
			return null;
	}
	
	
/*
	public String getSuffix()
	{
		String oidstring = _oid.toString();
		int i = oidstring.length() - 1;
		while ( i > -1 && oidstring.charAt( i ) != '.' )
		{
			i--;
		}
		if ( i > 0 )
			return oidstring.substring( i + 1 );
		else
			return null;
	}
	*/
	
	public boolean equals( GwOID oid )
	{
		return _oid.equals( oid.toString() );
	}
	
	/**
	 	@param paramOid  the GwOID against which the prefix relation ist checked
	 	@return if this instance is a prefix of the submitted parameter 	 */	
	public boolean isPrefixOf( GwOID paramOid )
	{
		String paramOidString = paramOid.toString();
		if ( _oid.length() > paramOidString.length() )
			return false;
		
		int i = 0;
		while ( i < _oid.length() )
		{
			if ( _oid.charAt( i ) != paramOidString.charAt( i ) )
				return false;
			i++;
		}
		return true;
	}
}