Changeset 375


Ignore:
Timestamp:
01/31/12 11:56:10 (13 years ago)
Author:
sherbold
Message:
  • added methods targetEquals and targetHashCode to de.ugoe.cs.eventbench.data.Event. These methods are used by equals/hashCode to compare target strings/generate the hashCode for the target string. Subclasses can override these methods to customize target comparisons, e.g., to allow that not all parts of a target string need to be equal
File:
1 edited

Legend:

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

    r373 r375  
    227227                        hash = multiplier * hash + type.hashCode(); 
    228228                } 
    229                 if (target != null) { 
    230                         hash = multiplier * hash + target.hashCode(); 
    231                 } 
     229                hash = multiplier * hash + targetHashCode(); 
    232230 
    233231                return hash; 
     
    296294         *  
    297295         * @param otherTarget 
    298          * @return 
     296         *            other target string to which the target if this event is 
     297         *            compared to 
     298         * @return true if the targets are equals; false otherwise 
    299299         */ 
    300300        protected boolean targetEquals(String otherTarget) { 
     
    307307                return retVal; 
    308308        } 
     309 
     310        /** 
     311         * <p> 
     312         * This function is used by {@link #hashCode()} to determine how the hash of 
     313         * the {@link #target}. It has to be overridden by subclasses that implement 
     314         * {@link #targetEquals(String)}, to ensure that the equals/hashCode 
     315         * contract remains valid. 
     316         * </p> 
     317         *  
     318         * @return hash of the target 
     319         */ 
     320        protected int targetHashCode() { 
     321                if (target != null) { 
     322                        return target.hashCode(); 
     323                } else { 
     324                        return 0; 
     325                } 
     326        } 
    309327} 
Note: See TracChangeset for help on using the changeset viewer.