Coverage Report - net.sf.snmpadaptor4j.object.GenericSnmpTrap
 
Classes in this File Line Coverage Branch Coverage Complexity
GenericSnmpTrap
100 %
23/23
100 %
10/10
1,667
 
 1  
 package net.sf.snmpadaptor4j.object;
 2  
 
 3  
 import java.util.Map;
 4  
 import java.util.Map.Entry;
 5  
 import org.apache.log4j.Logger;
 6  
 
 7  
 /**
 8  
  * Object representing a generic SNMP trap.
 9  
  * @author <a href="http://fr.linkedin.com/in/jpminetti/">Jean-Philippe MINETTI</a>
 10  
  */
 11  
 public final class GenericSnmpTrap
 12  
                 extends SnmpTrap {
 13  
 
 14  
         /**
 15  
          * Serial number.
 16  
          */
 17  
         private static final long serialVersionUID = -6485304599608042063L;
 18  
 
 19  
         /**
 20  
          * Trap type.
 21  
          */
 22  
         private final GenericSnmpTrapType type;
 23  
 
 24  
         /**
 25  
          * Hidden constructor.
 26  
          * @param timeStamp Elapsed time in <b>100th of second</b> since the application launch.
 27  
          * @param source OID indexing the source of the trap.
 28  
          * @param type Trap type.
 29  
          * @param dataMap Map of "interesting" information.
 30  
          * @see SnmpTrap#newInstance(long, SnmpOid, GenericSnmpTrapType, Map)
 31  
          */
 32  
         protected GenericSnmpTrap (final long timeStamp, final SnmpOid source, final GenericSnmpTrapType type, final Map<SnmpOid, SnmpTrapData> dataMap) {
 33  71
                 super(timeStamp, source, dataMap);
 34  71
                 this.type = type;
 35  71
         }
 36  
 
 37  
         /**
 38  
          * Returns the trap type.
 39  
          * @return Trap type.
 40  
          */
 41  
         public GenericSnmpTrapType getType () {
 42  55
                 return this.type;
 43  
         }
 44  
 
 45  
         /*
 46  
          * {@inheritDoc}
 47  
          * @see net.sf.snmpadaptor4j.object.SnmpTrap#traceTo(org.apache.log4j.Logger)
 48  
          */
 49  
         @Override
 50  
         public void traceTo (final Logger logger) {
 51  4
                 logger.trace("enterprise         = " + getSource());
 52  4
                 logger.trace("generic-trap       = " + this.type);
 53  4
                 logger.trace("specific-trap      = 0");
 54  4
                 logger.trace("time-stamp         = " + getTimeStamp());
 55  4
                 for (final Entry<SnmpOid, SnmpTrapData> data : getDataMap().entrySet()) {
 56  2
                         logger.trace("variable-bindings: " + data.getKey() + " = " + data.getValue());
 57  
                 }
 58  4
         }
 59  
 
 60  
         /*
 61  
          * {@inheritDoc}
 62  
          * @see java.lang.Object#hashCode()
 63  
          */
 64  
         @Override
 65  
         public int hashCode () {
 66  
                 final int prime = 31;
 67  30
                 int result = super.hashCode();
 68  30
                 result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
 69  30
                 return result;
 70  
         }
 71  
 
 72  
         /*
 73  
          * {@inheritDoc}
 74  
          * @see java.lang.Object#equals(java.lang.Object)
 75  
          */
 76  
         @Override
 77  
         public boolean equals (final Object obj) {
 78  44
                 boolean result = false;
 79  44
                 if (obj == this) {
 80  15
                         result = true;
 81  
                 }
 82  
                 else {
 83  29
                         result = super.equals(obj);
 84  29
                         if (result) {
 85  19
                                 final GenericSnmpTrap other = (GenericSnmpTrap) obj;
 86  19
                                 result = (this.type == other.type);
 87  
                         }
 88  
                 }
 89  44
                 return result;
 90  
         }
 91  
 
 92  
         /*
 93  
          * {@inheritDoc}
 94  
          * @see java.lang.Object#toString()
 95  
          */
 96  
         @Override
 97  
         public String toString () {
 98  6
                 return "SNMP trap " + getSource() + " - Type " + this.type + "/0";
 99  
         }
 100  
 
 101  
 }