001    package edu.rice.cs.cunit.instrumentors.threadCheck;
002    
003    import edu.rice.cs.cunit.instrumentors.util.IScannerStrategy;
004    
005    /**
006         * Storage class for class not found warnings.
007     */
008    public class ClassNotFoundWarning extends RuntimeException
009        implements IScannerStrategy.IScanResult, Comparable<ClassNotFoundWarning> {
010        /**
011         * Name of the class that was not found.
012         */
013        public final String className;
014    
015        /**
016         * Message.
017         */
018        public final String msg;
019    
020        /**
021         * Create a new class not found warning.
022         * @param className name of the class that was not found
023         * @param msg message
024         */
025        public ClassNotFoundWarning(String className, String msg) {
026            super(className);
027            this.className = className;
028            this.msg = msg;
029        }
030    
031        /**
032         * Return true if this object is equal to the other object.
033         * @param o other object
034         * @return true if equal
035         */
036        public boolean equals(Object o) {
037            if (this == o) {
038                return true;
039            }
040            if (o == null || getClass() != o.getClass()) {
041                return false;
042            }
043    
044            ClassNotFoundWarning that = (ClassNotFoundWarning)o;
045    
046            if (className != null ? !className.equals(that.className) : that.className != null) {
047                return false;
048            }
049            if (msg != null ? !msg.equals(that.msg) : that.msg != null) {
050                return false;
051            }
052    
053            return true;
054        }
055    
056        /**
057         * Return a hash code for this object.
058         * @return hash code
059         */
060        public int hashCode() {
061            int result;
062            result = (className != null ? className.hashCode() : 0);
063            result = 31 * result + (msg != null ? msg.hashCode() : 0);
064            return result;
065        }
066    
067        /**
068         * Compares this object with the specified object for order.
069         * @param o the Object to be compared.
070         *
071         * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than
072         *         the specified object.
073         *
074         * @throws ClassCastException if the specified object's type prevents it from being compared to this Object.
075         */
076        public int compareTo(ClassNotFoundWarning o) {
077            return className.compareTo(o.className);
078        }
079    
080        /**
081         * Returns a string representation of the object.
082         * @return a string representation of the object
083         */
084        public String toString() {
085            return "Could not find class "+className+" ("+msg+")";
086        }
087    
088        /**
089         * Return the name of the property that was scanned for.
090         * @return property name
091         */
092        public String getPropertyName() {
093            return "ThreadChecker Class Not Found Warning";
094        }
095    }