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

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

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  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  
 package org.apache.commons.scxml;
 18  
 
 19  
 /**
 20  
  * A class representing an event. Specific event types have been
 21  
  * defined in reference to SCXML.
 22  
  *
 23  
  */
 24  
 public class TriggerEvent {
 25  
 
 26  
     /**
 27  
      * Constructor.
 28  
      *
 29  
      * @param name The event name
 30  
      * @param type The event type
 31  
      * @param payload The event payload
 32  
      */
 33  
     public TriggerEvent(final String name, final int type,
 34  
             final Object payload) {
 35  614
         super();
 36  614
         this.name = name;
 37  614
         this.type = type;
 38  614
         this.payload = payload;
 39  614
     }
 40  
 
 41  
     /**
 42  
      * Constructor.
 43  
      *
 44  
      * @param name The event name
 45  
      * @param type The event type
 46  
      */
 47  
     public TriggerEvent(final String name, final int type) {
 48  497
         this(name, type, null);
 49  497
     }
 50  
 
 51  
     /**
 52  
      * <code>CALL_EVENT</code>.
 53  
      */
 54  
     public static final int CALL_EVENT = 1;
 55  
 
 56  
     /**
 57  
      * <code>CHANGE_EVENT</code>.
 58  
      *
 59  
      */
 60  
     public static final int CHANGE_EVENT = 2;
 61  
 
 62  
     /**
 63  
      * <code>SIGNAL_EVENT</code>.
 64  
      *
 65  
      */
 66  
     public static final int SIGNAL_EVENT = 3;
 67  
 
 68  
     /**
 69  
      * <code>TIME_EVENT</code>.
 70  
      *
 71  
      */
 72  
     public static final int TIME_EVENT = 4;
 73  
 
 74  
     /**
 75  
      * <code>ERROR_EVENT</code>.
 76  
      *
 77  
      */
 78  
     public static final int ERROR_EVENT = 5;
 79  
 
 80  
     /**
 81  
      * The event name.
 82  
      *
 83  
      */
 84  
     private String name;
 85  
 
 86  
     /**
 87  
      * The event type.
 88  
      *
 89  
      */
 90  
     private int type;
 91  
 
 92  
     /**
 93  
      * The event payload.
 94  
      *
 95  
      */
 96  
     private Object payload;
 97  
 
 98  
     /**
 99  
      * @return Returns the name.
 100  
      */
 101  
     public String getName() {
 102  791
         return name;
 103  
     }
 104  
 
 105  
     /**
 106  
      * @return Returns the payload.
 107  
      */
 108  
     public Object getPayload() {
 109  203
         return payload;
 110  
     }
 111  
 
 112  
     /**
 113  
      * @return Returns the type.
 114  
      */
 115  
     public int getType() {
 116  1
         return type;
 117  
     }
 118  
 
 119  
     /**
 120  
      * Define an equals operator for TriggerEvent.
 121  
      *
 122  
      * @see java.lang.Object#equals(java.lang.Object)
 123  
      */
 124  
     public boolean equals(final Object obj) {
 125  5
         if (obj instanceof TriggerEvent) {
 126  4
             TriggerEvent te2 = (TriggerEvent) obj;
 127  4
             if (type == te2.type && name.equals(te2.name)
 128  
                 && ((payload == null && te2.payload == null)
 129  
                      || (payload != null && payload.equals(te2.payload)))) {
 130  3
                 return true;
 131  
             }
 132  
         }
 133  2
         return false;
 134  
     }
 135  
 
 136  
     /**
 137  
      * Returns a string representation of this TriggerEvent object.
 138  
      *
 139  
      * @see java.lang.Object#toString()
 140  
      */
 141  
     public String toString() {
 142  4
         StringBuffer buf = new StringBuffer("TriggerEvent{name=");
 143  4
         buf.append(name).append(",type=").append(type);
 144  4
         if (payload != null) {
 145  1
             buf.append(",payload=").append(payload.toString());
 146  
         }
 147  4
         buf.append("}");
 148  4
         return String.valueOf(buf);
 149  
     }
 150  
 
 151  
     /**
 152  
      * Returns the hash code for this TriggerEvent object.
 153  
      *
 154  
      * @see java.lang.Object#hashCode()
 155  
      */
 156  
     public int hashCode() {
 157  2
         return String.valueOf(this).hashCode();
 158  
     }
 159  
 
 160  
 }
 161