Coverage Report - org.apache.commons.scxml.TriggerEvent

Classes in this File Line Coverage Branch Coverage Complexity
TriggerEvent
100% 
100% 
1.5

 1  
 /*
 2  
  *
 3  
  *   Copyright 2005-2006 The Apache Software Foundation.
 4  
  *
 5  
  *  Licensed under the Apache License, Version 2.0 (the "License");
 6  
  *  you may not use this file except in compliance with the License.
 7  
  *  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  *  Unless required by applicable law or agreed to in writing, software
 12  
  *  distributed under the License is distributed on an "AS IS" BASIS,
 13  
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  *  See the License for the specific language governing permissions and
 15  
  *  limitations under the License.
 16  
  *
 17  
  */
 18  
 package org.apache.commons.scxml;
 19  
 
 20  
 /**
 21  
  * A class representing an event. Specific event types have been
 22  
  * defined in reference to SCXML.
 23  
  *
 24  
  */
 25  
 public class TriggerEvent {
 26  
 
 27  
     /**
 28  
      * Constructor.
 29  
      *
 30  
      * @param name The event name
 31  
      * @param type The event type
 32  
      * @param payload The event payload
 33  
      */
 34  
     public TriggerEvent(final String name, final int type,
 35  
             final Object payload) {
 36  495
         super();
 37  495
         this.name = name;
 38  495
         this.type = type;
 39  495
         this.payload = payload;
 40  495
     }
 41  
 
 42  
     /**
 43  
      * Constructor.
 44  
      *
 45  
      * @param name The event name
 46  
      * @param type The event type
 47  
      */
 48  
     public TriggerEvent(final String name, final int type) {
 49  402
         this(name, type, null);
 50  402
     }
 51  
 
 52  
     /**
 53  
      * <code>CALL_EVENT</code>.
 54  
      */
 55  
     public static final int CALL_EVENT = 1;
 56  
 
 57  
     /**
 58  
      * <code>CHANGE_EVENT</code>.
 59  
      *
 60  
      */
 61  
     public static final int CHANGE_EVENT = 2;
 62  
 
 63  
     /**
 64  
      * <code>SIGNAL_EVENT</code>.
 65  
      *
 66  
      */
 67  
     public static final int SIGNAL_EVENT = 3;
 68  
 
 69  
     /**
 70  
      * <code>TIME_EVENT</code>.
 71  
      *
 72  
      */
 73  
     public static final int TIME_EVENT = 4;
 74  
 
 75  
     /**
 76  
      * <code>ERROR_EVENT</code>.
 77  
      *
 78  
      */
 79  
     public static final int ERROR_EVENT = 5;
 80  
 
 81  
     /**
 82  
      * The event name.
 83  
      *
 84  
      */
 85  
     private String name;
 86  
 
 87  
     /**
 88  
      * The event type.
 89  
      *
 90  
      */
 91  
     private int type;
 92  
 
 93  
     /**
 94  
      * The event payload.
 95  
      *
 96  
      */
 97  
     private Object payload;
 98  
 
 99  
     /**
 100  
      * @return Returns the name.
 101  
      */
 102  
     public String getName() {
 103  624
         return name;
 104  
     }
 105  
 
 106  
     /**
 107  
      * @return Returns the payload.
 108  
      */
 109  
     public Object getPayload() {
 110  155
         return payload;
 111  
     }
 112  
 
 113  
     /**
 114  
      * @return Returns the type.
 115  
      */
 116  
     public int getType() {
 117  1
         return type;
 118  
     }
 119  
 
 120  
     /**
 121  
      * Define an equals operator for TriggerEvent.
 122  
      *
 123  
      * @see java.lang.Object#equals(java.lang.Object)
 124  
      */
 125  
     public boolean equals(final Object obj) {
 126  5
         if (obj instanceof TriggerEvent) {
 127  4
             TriggerEvent te2 = (TriggerEvent) obj;
 128  4
             if (type == te2.type && name.equals(te2.name)
 129  
                 && ((payload == null && te2.payload == null)
 130  
                      || (payload != null && payload.equals(te2.payload)))) {
 131  3
                 return true;
 132  
             }
 133  
         }
 134  2
         return false;
 135  
     }
 136  
 
 137  
     /**
 138  
      * Returns a string representation of this TriggerEvent object.
 139  
      *
 140  
      * @see java.lang.Object#toString()
 141  
      */
 142  
     public String toString() {
 143  4
         StringBuffer buf = new StringBuffer("TriggerEvent{name=");
 144  4
         buf.append(name).append(",type=").append(type);
 145  4
         if (payload != null) {
 146  1
             buf.append(",payload=").append(payload.toString());
 147  
         }
 148  4
         buf.append("}");
 149  4
         return String.valueOf(buf);
 150  
     }
 151  
 
 152  
     /**
 153  
      * Returns the hash code for this TriggerEvent object.
 154  
      *
 155  
      * @see java.lang.Object#hashCode()
 156  
      */
 157  
     public int hashCode() {
 158  2
         return String.valueOf(this).hashCode();
 159  
     }
 160  
 
 161  
 }
 162