Java Code Examples for java.awt.Paint#hashCode()

The following examples show how to use java.awt.Paint#hashCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HashUtilities.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a hash code for a <code>Paint</code> instance.  If 
 * <code>p</code> is <code>null</code>, this method returns zero.
 * 
 * @param p  the paint (<code>null</code> permitted).
 * 
 * @return The hash code.
 */
public static int hashCodeForPaint(Paint p) {
    if (p == null) {
        return 0;
    }
    int result;
    // handle GradientPaint as a special case
    if (p instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) p;
        result = 193;
        result = 37 * result + gp.getColor1().hashCode();
        result = 37 * result + gp.getPoint1().hashCode();
        result = 37 * result + gp.getColor2().hashCode();
        result = 37 * result + gp.getPoint2().hashCode();
    }
    else {
        // we assume that all other Paint instances implement equals() and
        // hashCode()...of course that might not be true, but what can we
        // do about it?
        result = p.hashCode();
    }
    return result;
}
 
Example 2
Source File: HashUtilities.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a hash code for a <code>Paint</code> instance.  If 
 * <code>p</code> is <code>null</code>, this method returns zero.
 * 
 * @param p  the paint (<code>null</code> permitted).
 * 
 * @return The hash code.
 */
public static int hashCodeForPaint(Paint p) {
    if (p == null) {
        return 0;
    }
    int result;
    // handle GradientPaint as a special case
    if (p instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) p;
        result = 193;
        result = 37 * result + gp.getColor1().hashCode();
        result = 37 * result + gp.getPoint1().hashCode();
        result = 37 * result + gp.getColor2().hashCode();
        result = 37 * result + gp.getPoint2().hashCode();
    }
    else {
        // we assume that all other Paint instances implement equals() and
        // hashCode()...of course that might not be true, but what can we
        // do about it?
        result = p.hashCode();
    }
    return result;
}
 
Example 3
Source File: HashUtilities.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a hash code for a <code>Paint</code> instance.  If 
 * <code>p</code> is <code>null</code>, this method returns zero.
 * 
 * @param p  the paint (<code>null</code> permitted).
 * 
 * @return The hash code.
 */
public static int hashCodeForPaint(Paint p) {
    if (p == null) {
        return 0;
    }
    int result;
    // handle GradientPaint as a special case
    if (p instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) p;
        result = 193;
        result = 37 * result + gp.getColor1().hashCode();
        result = 37 * result + gp.getPoint1().hashCode();
        result = 37 * result + gp.getColor2().hashCode();
        result = 37 * result + gp.getPoint2().hashCode();
    }
    else {
        // we assume that all other Paint instances implement equals() and
        // hashCode()...of course that might not be true, but what can we
        // do about it?
        result = p.hashCode();
    }
    return result;
}
 
Example 4
Source File: HashUtilities.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a hash code for a <code>Paint</code> instance.  If 
 * <code>p</code> is <code>null</code>, this method returns zero.
 * 
 * @param p  the paint (<code>null</code> permitted).
 * 
 * @return The hash code.
 */
public static int hashCodeForPaint(Paint p) {
    if (p == null) {
        return 0;
    }
    int result;
    // handle GradientPaint as a special case
    if (p instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) p;
        result = 193;
        result = 37 * result + gp.getColor1().hashCode();
        result = 37 * result + gp.getPoint1().hashCode();
        result = 37 * result + gp.getColor2().hashCode();
        result = 37 * result + gp.getPoint2().hashCode();
    }
    else {
        // we assume that all other Paint instances implement equals() and
        // hashCode()...of course that might not be true, but what can we
        // do about it?
        result = p.hashCode();
    }
    return result;
}
 
Example 5
Source File: HashUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a hash code for a <code>Paint</code> instance.  If
 * <code>p</code> is <code>null</code>, this method returns zero.
 *
 * @param p  the paint (<code>null</code> permitted).
 *
 * @return The hash code.
 */
public static int hashCodeForPaint(Paint p) {
    if (p == null) {
        return 0;
    }
    int result = 0;
    // handle GradientPaint as a special case
    if (p instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) p;
        result = 193;
        result = 37 * result + gp.getColor1().hashCode();
        result = 37 * result + gp.getPoint1().hashCode();
        result = 37 * result + gp.getColor2().hashCode();
        result = 37 * result + gp.getPoint2().hashCode();
    }
    else {
        // we assume that all other Paint instances implement equals() and
        // hashCode()...of course that might not be true, but what can we
        // do about it?
        result = p.hashCode();
    }
    return result;
}
 
Example 6
Source File: HashUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a hash code for a <code>Paint</code> instance.  If 
 * <code>p</code> is <code>null</code>, this method returns zero.
 * 
 * @param p  the paint (<code>null</code> permitted).
 * 
 * @return The hash code.
 */
public static int hashCodeForPaint(Paint p) {
    if (p == null) {
        return 0;
    }
    int result = 0;
    // handle GradientPaint as a special case
    if (p instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) p;
        result = 193;
        result = 37 * result + gp.getColor1().hashCode();
        result = 37 * result + gp.getPoint1().hashCode();
        result = 37 * result + gp.getColor2().hashCode();
        result = 37 * result + gp.getPoint2().hashCode();
    }
    else {
        // we assume that all other Paint instances implement equals() and
        // hashCode()...of course that might not be true, but what can we
        // do about it?
        result = p.hashCode();
    }
    return result;
}
 
Example 7
Source File: HashUtilities.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a hash code for a <code>Paint</code> instance.  If 
 * <code>p</code> is <code>null</code>, this method returns zero.
 * 
 * @param p  the paint (<code>null</code> permitted).
 * 
 * @return The hash code.
 */
public static int hashCodeForPaint(Paint p) {
    if (p == null) 
        return 0;
    int result = 0;
    // handle GradientPaint as a special case
    if (p instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) p;
        result = 193;
        result = 37 * result + gp.getColor1().hashCode();
        result = 37 * result + gp.getPoint1().hashCode();
        result = 37 * result + gp.getColor2().hashCode();
        result = 37 * result + gp.getPoint2().hashCode();
    }
    else {
        // we assume that all other Paint instances implement equals() and
        // hashCode()...of course that might not be true, but what can we
        // do about it?
        result = p.hashCode();
    }
    return result;
}
 
Example 8
Source File: HashUtilities.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a hash code for a <code>Paint</code> instance.  If 
 * <code>p</code> is <code>null</code>, this method returns zero.
 * 
 * @param p  the paint (<code>null</code> permitted).
 * 
 * @return The hash code.
 */
public static int hashCodeForPaint(Paint p) {
    if (p == null) {
        return 0;
    }
    int result;
    // handle GradientPaint as a special case
    if (p instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) p;
        result = 193;
        result = 37 * result + gp.getColor1().hashCode();
        result = 37 * result + gp.getPoint1().hashCode();
        result = 37 * result + gp.getColor2().hashCode();
        result = 37 * result + gp.getPoint2().hashCode();
    }
    else {
        // we assume that all other Paint instances implement equals() and
        // hashCode()...of course that might not be true, but what can we
        // do about it?
        result = p.hashCode();
    }
    return result;
}
 
Example 9
Source File: HashUtilities.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a hash code for a <code>Paint</code> instance.  If 
 * <code>p</code> is <code>null</code>, this method returns zero.
 * 
 * @param p  the paint (<code>null</code> permitted).
 * 
 * @return The hash code.
 */
public static int hashCodeForPaint(Paint p) {
    if (p == null) {
        return 0;
    }
    int result;
    // handle GradientPaint as a special case
    if (p instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) p;
        result = 193;
        result = 37 * result + gp.getColor1().hashCode();
        result = 37 * result + gp.getPoint1().hashCode();
        result = 37 * result + gp.getColor2().hashCode();
        result = 37 * result + gp.getPoint2().hashCode();
    }
    else {
        // we assume that all other Paint instances implement equals() and
        // hashCode()...of course that might not be true, but what can we
        // do about it?
        result = p.hashCode();
    }
    return result;
}
 
Example 10
Source File: PaintTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testColorHashcode() {
    Paint p1 = new Color(0xFF, 0xEE, 0xDD);
    Paint p2 = new Color(0xFF, 0xEE, 0xDD);
    assertTrue(p1.equals(p2));
    int h1 = p1.hashCode();
    int h2 = p2.hashCode();
    assertEquals(h1, h2);
}