View Javadoc
1   // NAME
2   //      $RCSfile: AsnPrimitive.java,v $
3   // DESCRIPTION
4   //      [given below in javadoc format]
5   // DELTA
6   //      $Revision: 3.10 $
7   // CREATED
8   //      $Date: 2006/01/17 17:43:54 $
9   // COPYRIGHT
10  //      Westhawk Ltd
11  // TO DO
12  //
13  
14  /*
15   * Copyright (C) 2000 - 2006 by Westhawk Ltd
16   * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a>
17   *
18   * Permission to use, copy, modify, and distribute this software
19   * for any purpose and without fee is hereby granted, provided
20   * that the above copyright notices appear in all copies and that
21   * both the copyright notice and this permission notice appear in
22   * supporting documentation.
23   * This software is provided "as is" without express or implied
24   * warranty.
25   * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
26   */
27  
28  package uk.co.westhawk.snmp.stack;
29  
30  /*-
31   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
32   * SNMP Java Client
33   * ჻჻჻჻჻჻
34   * Copyright 2023 MetricsHub, Westhawk
35   * ჻჻჻჻჻჻
36   * This program is free software: you can redistribute it and/or modify
37   * it under the terms of the GNU Lesser General Public License as
38   * published by the Free Software Foundation, either version 3 of the
39   * License, or (at your option) any later version.
40   *
41   * This program is distributed in the hope that it will be useful,
42   * but WITHOUT ANY WARRANTY; without even the implied warranty of
43   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44   * GNU General Lesser Public License for more details.
45   *
46   * You should have received a copy of the GNU General Lesser Public
47   * License along with this program.  If not, see
48   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
49   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
50   */
51  
52  import java.io.*;
53  import java.util.*;
54  
55  /**
56   * This class represents the Exception values for SNMP v2c, v3:
57   * SNMP_VAR_NOSUCHOBJECT, SNMP_VAR_NOSUCHINSTANCE, SNMP_VAR_ENDOFMIBVIEW
58   *
59   * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
60   * @version $Revision: 3.10 $ $Date: 2006/01/17 17:43:54 $
61   * @see #SNMP_VAR_NOSUCHOBJECT
62   * @see #SNMP_VAR_NOSUCHINSTANCE
63   * @see #SNMP_VAR_ENDOFMIBVIEW
64   */
65  public class AsnPrimitive extends AsnObject {
66      private static final String version_id = "@(#)$Id: AsnPrimitive.java,v 3.10 2006/01/17 17:43:54 birgit Exp $ Copyright Westhawk Ltd";
67  
68      private byte type;
69  
70      /**
71       * Default Constructor.
72       *
73       * @param t The primitive type
74       * @see #SNMP_VAR_NOSUCHOBJECT
75       * @see #SNMP_VAR_NOSUCHINSTANCE
76       * @see #SNMP_VAR_ENDOFMIBVIEW
77       */
78      public AsnPrimitive(byte t) {
79          type = t;
80      }
81  
82      /**
83       * Returns the string representation of the AsnPrimitive.
84       *
85       * @return The string of the AsnPrimitive
86       */
87      public String toString() {
88          String str = "AsnPrimitive ";
89          if (type == SNMP_VAR_NOSUCHOBJECT) {
90              str = "No such object";
91          } else if (type == SNMP_VAR_NOSUCHINSTANCE) {
92              str = "No such instance";
93          } else if (type == SNMP_VAR_ENDOFMIBVIEW) {
94              str = "End of MIB view";
95          }
96          return str;
97      }
98  
99      void write(OutputStream out, int pos) throws IOException {
100         AsnBuildHeader(out, type, 0);
101     }
102 
103     /**
104      * Compares this object to the specified object. The result is
105      * <code>true</code> if and only if the argument is not
106      * <code>null</code> and is an <code>AsnPrimitive</code> object that
107      * contains the same <code>type</code> as this object.
108      *
109      * @param obj the object to compare with.
110      * @return <code>true</code> if the objects are the same;
111      *         <code>false</code> otherwise.
112      */
113     public boolean equals(Object obj) {
114         if (obj instanceof AsnPrimitive) {
115             return type == ((AsnPrimitive) obj).type;
116         }
117         return false;
118     }
119 
120     /**
121      * Returns a hash code for this <code>AsnPrimitive</code>.
122      *
123      * @return a hash code value for this object, equal to the
124      *         type represented by this
125      *         <code>AsnPrimitive</code> object.
126      */
127     public int hashCode() {
128         return (int) type;
129     }
130 }