Ignore:
Timestamp:
06/21/11 11:25:45 (13 years ago)
Author:
sherbold
Message:
  • documentation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/EventBenchCore/src/de/ugoe/cs/eventbench/data/Event.java

    r23 r79  
    33import java.security.InvalidParameterException; 
    44 
    5  
    6  
     5/** 
     6 * <p> 
     7 * Base class for all events. An event is described by its {@link #type} and its 
     8 * {@link #target}. 
     9 * </p> 
     10 *  
     11 * @author Steffen Herbold 
     12 * @version 1.0 
     13 *  
     14 * @param <T> 
     15 *            Can be used to declare that events belong to a specific platform 
     16 *            without subclassing. 
     17 */ 
    718public class Event<T> { 
    8          
     19 
     20        /** 
     21         * <p> 
     22         * Global start event that can be used to indicate the start of a sequence. 
     23         * </p> 
     24         */ 
    925        public static final Event<Object> STARTEVENT = new Event<Object>("START"); 
     26 
     27        /** 
     28         * <p> 
     29         * Global end event that can be used to indicate the end of a sequence. 
     30         */ 
    1031        public static final Event<Object> ENDEVENT = new Event<Object>("END"); 
    11          
     32 
    1233        /** 
    1334         * <p> 
     
    1637         */ 
    1738        private String type; 
    18          
    19         /** 
    20          * </p> 
    21          * Target of the event. 
     39 
     40        /** 
     41         * </p> Target of the event. 
    2242         */ 
    2343        private String target = null; 
    24          
     44 
    2545        /** 
    2646         * <p> 
     
    3050        private String targetShort = null; 
    3151 
    32  
     52        /** 
     53         * Further information about the event that shall be included in its Id. 
     54         */ 
    3355        private String idInfo = ""; 
    34          
     56 
     57        /** 
     58         * <p> 
     59         * Constructor. Creates a new Event with a given type. 
     60         * </p> 
     61         *  
     62         * @param type 
     63         *            type of the event 
     64         */ 
    3565        public Event(String type) { 
    36                 if( type==null ) { 
     66                if (type == null) { 
    3767                        throw new InvalidParameterException("Event type must not be null"); 
    3868                } 
     
    4070        } 
    4171 
     72        /** 
     73         * <p> 
     74         * Two events are equal, if their {@link #type} and {@link #target} are 
     75         * equal. 
     76         * </p> 
     77         * <p> 
     78         * See {@link Object#equals(Object)} for further information. 
     79         * </p> 
     80         *  
     81         * @param other 
     82         *            Event that is compared to this 
     83         * @return true, if events are equal, false otherwise 
     84         */ 
    4285        @Override 
    4386        public boolean equals(Object other) { 
    44                 if( this==other ) { 
     87                if (this == other) { 
    4588                        return true; 
    4689                } 
    4790                if (other instanceof Event<?>) { 
    4891                        Event<?> otherEvent = (Event<?>) other; 
    49                         if( target!=null ) { 
     92                        if (target != null) { 
    5093                                return type.equals(otherEvent.type) 
    51                                         && target.equals(otherEvent.target); 
     94                                                && target.equals(otherEvent.target); 
    5295                        } else { 
    5396                                return type.equals(otherEvent.type) 
    54                                         && otherEvent.target==null; 
     97                                                && otherEvent.target == null; 
    5598                        } 
    5699                } else { 
     
    58101                } 
    59102        } 
    60          
     103 
     104        /** 
     105         * <p> 
     106         * Returns {@link #getStandardId()} as String representation of the event. 
     107         * </p> 
     108         *  
     109         * @return String represenation of the event 
     110         */ 
    61111        @Override 
    62112        public String toString() { 
     
    64114        } 
    65115 
     116        /** 
     117         * Informations about the event important for its Id that is neither target 
     118         * nor type. 
     119         *  
     120         * @return {@link #idInfo} of the event 
     121         */ 
    66122        public String getIdInfo() { 
    67123                return idInfo; 
    68124        } 
    69125 
     126        /** 
     127         * <p> 
     128         * If {@link #targetShort} is set, a shortend version of the Id is returned 
     129         * of the form {@link #targetShort}.{@link #type}.{@link #idInfo} is 
     130         * returned. Otherwise the standard Id is returned (see 
     131         * {@link #getStandardId()}). 
     132         * </p> 
     133         *  
     134         * @return if available, shortend Id string; {@link #getStandardId()} 
     135         *         otherwise 
     136         */ 
    70137        public String getShortId() { 
    71138                String shortId = null; 
    72                 if (targetShort!=null) { 
    73                         shortId = targetShort+"."+getType(); 
    74                         if ( !"".equals(idInfo)) { 
    75                                 shortId += "."+idInfo; 
     139                if (targetShort != null) { 
     140                        shortId = targetShort + "." + getType(); 
     141                        if (!"".equals(idInfo)) { 
     142                                shortId += "." + idInfo; 
    76143                        } 
    77144                } else { 
     
    81148        } 
    82149 
     150        /** 
     151         * <p> 
     152         * Returns the Id string of the event. It has the form {@link #target}. 
     153         * {@link #type}.{@link #idInfo}; 
     154         * <p> 
     155         *  
     156         * @return Id string of the event 
     157         */ 
    83158        public String getStandardId() { 
    84159                String id = ""; 
    85                 if( target!=null ) { 
     160                if (target != null) { 
    86161                        id += target + "."; 
    87162                } 
    88163                id += getType(); 
    89                 if ( !"".equals(idInfo) ) { 
     164                if (!"".equals(idInfo)) { 
    90165                        id += "." + idInfo; 
    91166                } 
     
    93168        } 
    94169 
     170        /** 
     171         * <p> 
     172         * Returns the {@link #target} of the event. 
     173         * </p> 
     174         *  
     175         * @return {@link #target} of the event 
     176         */ 
    95177        public String getTarget() { 
    96178                return target; 
    97179        } 
    98          
    99         public String getTargetShort() { 
     180 
     181        /** 
     182         * <p> 
     183         * Returns the {@link #targetShort} of the event. 
     184         * </p> 
     185         *  
     186         * @return {@link #targetShort} of the event 
     187         */ 
     188        protected String getTargetShort() { 
    100189                return targetShort; 
    101190        } 
    102191 
     192        /** 
     193         * <p> 
     194         * Returns the {@link #type} of the event. 
     195         * </p> 
     196         *  
     197         * @return {@link #type} of the event 
     198         */ 
    103199        public String getType() { 
    104200                return type; 
    105201        } 
    106202 
     203        /* 
     204         * (non-Javadoc) 
     205         *  
     206         * @see java.lang.Object#hashCode() 
     207         */ 
    107208        @Override 
    108209        public int hashCode() { 
     
    110211                int hash = 42; 
    111212                hash = multiplier * hash + type.hashCode(); 
    112                 if( target!=null ) { 
     213                if (target != null) { 
    113214                        hash = multiplier * hash + target.hashCode(); 
    114215                } 
     
    117218        } 
    118219 
     220        /** 
     221         * <p> 
     222         * Sets the {@link #idInfo} of the event. The idInfo is optional and 
     223         * contains information important for the event's Id that is neither target 
     224         * nor type. 
     225         * </p> 
     226         *  
     227         * @param info 
     228         *            {@link #idInfo} of the event 
     229         */ 
    119230        public void setIdInfo(String info) { 
    120231                idInfo = info; 
    121232        } 
    122          
     233 
    123234        /** 
    124235         * <p> 
    125236         * Sets the target of the event. Once set, the target cannot be changed. 
    126          * </p>  
    127          * @param target target of the event 
     237         * </p> 
     238         *  
     239         * @param target 
     240         *            target of the event 
    128241         * @return true, if target was changed, false otherwise 
    129242         */ 
    130243        public boolean setTarget(String target) { 
    131                 if( this.target!=null ) { 
     244                if (this.target != null) { 
    132245                        return false; 
    133246                } 
     
    135248                return true; 
    136249        } 
    137          
    138         /** 
    139          * <p> 
    140          * Sets the short description of the event target. Once set, the target cannot be changed. 
    141          * </p>  
    142          * @param targetShort short target description 
     250 
     251        /** 
     252         * <p> 
     253         * Sets the short description of the event target. Once set, the target 
     254         * cannot be changed. 
     255         * </p> 
     256         *  
     257         * @param targetShort 
     258         *            short target description 
    143259         * @return true, if target was changed, false otherwise 
    144260         */ 
    145261        public boolean setTargetShort(String targetShort) { 
    146                 if( this.targetShort!=null ) { 
     262                if (this.targetShort != null) { 
    147263                        return false; 
    148264                } 
Note: See TracChangeset for help on using the changeset viewer.