[SNMP4J] Newbie... typesafe enumerations

Beton, Richard richard.beton at roke.co.uk
Mon May 10 10:04:29 CEST 2004


Here's that SnmpVersion.java:


package org.snmp4j;

/**
 * This typesafe enumeration provides the version numbering for different SNMP
 * variants.
 * 
 * @author Rick Beton
 */
public final class SnmpVersion
{
    // note that the numeric version numbers are NOT arbitrary:
    // they must correspond to the values used in SNMP

    /** Supported versions of SNMP. */
    public static final SnmpVersion SNMP_V1  = new SnmpVersion( 0 );
    public static final SnmpVersion SNMP_V2c = new SnmpVersion( 1 );
    public static final SnmpVersion SNMP_V3  = new SnmpVersion( 3 );

    private static final SnmpVersion[] ALL = new SnmpVersion[]
    { SNMP_V1, SNMP_V2c, SNMP_V3 };                                                         


    /**
     * Gets the SnmpVersion instance indicated by the corresponding integer.
     * @param snmpVersion the version number, as used in the SNMP message header
     * @return the SnmpVersion instance, or null if not found.
     */
    public static SnmpVersion lookup (int snmpVersion)
    {
        for (int i = 0; i < ALL.length; i++)
        {
            if (ALL[i].version == snmpVersion)
            {
                return ALL[i];
            }
        }
        return null;
    }


    private final int version;


    /**
     * Typesafe private constructor.
     */
    private SnmpVersion (int version)
    {
        this.version = version;
    }


    /**
     * Gets the numeric version indicator.
     * 
     * @return Returns the version.
     */
    public int getVersion ()
    {
        return version;
    }
}




-- 

Visit our website at www.roke.co.uk

Registered Office: Roke Manor Research Ltd, Siemens House, Oldbury, Bracknell,
Berkshire. RG12 8FZ

The information contained in this e-mail and any attachments is confidential to
Roke Manor Research Ltd and must not be passed to any third party without
permission. This communication is for information only and shall not create or
change any contractual relationship.




More information about the SNMP4J mailing list