Changeset 336


Ignore:
Timestamp:
12/20/11 13:37:14 (12 years ago)
Author:
sherbold
Message:
  • made de.ugoe.cs.eventbench.data.Event and ReplayableEvent? more robust against incorrect usage, with focus on incorrect subclassing. Especially unexpected null values are now handled more reliably.
Location:
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/data
Files:
2 edited

Legend:

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

    r335 r336  
    9696                if (other instanceof Event<?>) { 
    9797                        Event<?> otherEvent = (Event<?>) other; 
    98                         if (target != null) { 
    99                                 return type.equals(otherEvent.type) 
    100                                                 && target.equals(otherEvent.target); 
     98                        if (otherEvent.canEqual(this)) { 
     99                                if (type != null && target != null) { 
     100                                        return type.equals(otherEvent.type) 
     101                                                        && target.equals(otherEvent.target); 
     102                                } else if (type != null && target == null) { 
     103                                        return type.equals(otherEvent.type) 
     104                                                        && otherEvent.target == null; 
     105                                } else if (type == null && target != null) { 
     106                                        return otherEvent.type == null 
     107                                                        && target.equals(otherEvent.target); 
     108                                } else { 
     109                                        return otherEvent.type == null && otherEvent.target == null; 
     110                                } 
    101111                        } else { 
    102                                 return type.equals(otherEvent.type) 
    103                                                 && otherEvent.target == null; 
     112                                return false; 
    104113                        } 
    105114                } else { 
    106115                        return false; 
    107116                } 
     117        } 
     118 
     119        public boolean canEqual(Object other) { 
     120                return (other instanceof Event<?>); 
    108121        } 
    109122 
     
    216229                int multiplier = 17; 
    217230                int hash = 42; 
    218                 hash = multiplier * hash + type.hashCode(); 
     231                if (type != null) { 
     232                        hash = multiplier * hash + type.hashCode(); 
     233                } 
    219234                if (target != null) { 
    220235                        hash = multiplier * hash + target.hashCode(); 
  • trunk/EventBenchCore/src/de/ugoe/cs/eventbench/data/ReplayableEvent.java

    r335 r336  
    11package de.ugoe.cs.eventbench.data; 
    22 
     3import java.security.InvalidParameterException; 
    34import java.util.LinkedList; 
    45import java.util.List; 
     
    7374         * @param replayable 
    7475         *            element that is added to the sequence 
     76         * @throws InvalidParameterException 
     77         *             thrown is replayable is null 
    7578         */ 
    7679        public void addReplayEvent(T replayable) { 
     80                if (replayable == null) { 
     81                        throw new InvalidParameterException("replayble must not be null"); 
     82                } 
    7783                replayEvents.add(replayable); 
    7884        } 
     
    8591         * @param generatedReplaySeq 
    8692         *            {@link List} that is added to the sequence 
     93         * @throws InvalidParameterException 
     94         *             thrown if generatedReplaySeq is null 
    8795         */ 
    8896        public void addReplaySequence(List<T> generatedReplaySeq) { 
     97                if (generatedReplaySeq == null) { 
     98                        throw new InvalidParameterException( 
     99                                        "generatedReplaySeq must not be null"); 
     100                } 
    89101                replayEvents.addAll(generatedReplaySeq); 
    90102        } 
     
    149161        } 
    150162 
    151         /* (non-Javadoc) 
     163        /* 
     164         * (non-Javadoc) 
     165         *  
    152166         * @see de.ugoe.cs.eventbench.data.Event#equals(java.lang.Object) 
    153167         */ 
     
    159173                if (other instanceof ReplayableEvent<?>) { 
    160174                        ReplayableEvent<?> otherEvent = (ReplayableEvent<?>) other; 
    161                         return super.equals(otherEvent) 
    162                                         && replayEvents.equals(otherEvent.replayEvents) 
    163                                         && replayValid == otherEvent.replayValid; 
     175                        if (replayEvents != null) { 
     176                                return super.equals(otherEvent) 
     177                                                && replayEvents.equals(otherEvent.replayEvents) 
     178                                                && replayValid == otherEvent.replayValid; 
     179                        } else { 
     180                                return super.equals(otherEvent) 
     181                                                && otherEvent.replayEvents == null 
     182                                                && replayValid == otherEvent.replayValid; 
     183                        } 
    164184 
    165185                } else { 
     
    168188        } 
    169189         
    170         /* (non-Javadoc) 
     190        @Override 
     191        public boolean canEqual(Object other) { 
     192                return (other instanceof ReplayableEvent<?>); 
     193        } 
     194 
     195        /* 
     196         * (non-Javadoc) 
     197         *  
    171198         * @see de.ugoe.cs.eventbench.data.Event#hashCode() 
    172199         */ 
     
    175202                int multiplier = 17; 
    176203                int hash = super.hashCode(); 
    177                 hash = multiplier * hash + replayEvents.hashCode(); 
     204                if (replayEvents != null) { 
     205                        hash = multiplier * hash + replayEvents.hashCode(); 
     206                } 
    178207                hash = multiplier * hash + (replayValid ? 1 : 0); 
    179208 
Note: See TracChangeset for help on using the changeset viewer.