This implements the missing TextLayout.hashCode() method to be in sync
with the equals() method.
2006-11-22 Roman Kennke <[EMAIL PROTECTED]>
* java/awt/font/TextLayout.java
(hash): New field. Caches the hash code.
(hashCode): Implemented.
/Roman
Index: java/awt/font/TextLayout.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/font/TextLayout.java,v
retrieving revision 1.18
diff -u -1 -5 -r1.18 TextLayout.java
--- java/awt/font/TextLayout.java 22 Nov 2006 14:39:36 -0000 1.18
+++ java/awt/font/TextLayout.java 22 Nov 2006 16:05:05 -0000
@@ -152,30 +152,35 @@
private Bidi bidi;
/**
* Mpas the logical position of each individual character in the original
* string to its visual position.
*/
private int[] logicalToVisual;
/**
* Maps visual positions of a character to its logical position
* in the original string.
*/
private int[] visualToLogical;
/**
+ * The cached hashCode.
+ */
+ private int hash;
+
+ /**
* The default caret policy.
*/
public static final TextLayout.CaretPolicy DEFAULT_CARET_POLICY =
new CaretPolicy();
/**
* Constructs a TextLayout.
*/
public TextLayout (String str, Font font, FontRenderContext frc)
{
this.font = font;
this.frc = frc;
string = str.toCharArray();
offset = 0;
length = this.string.length;
@@ -1079,33 +1084,39 @@
}
return hitInfo;
}
public boolean isLeftToRight ()
{
return leftToRight;
}
public boolean isVertical ()
{
return false; // FIXME: How do you create a vertical layout?
}
public int hashCode ()
- throws NotImplementedException
{
- throw new Error ("not implemented");
+ // This is implemented in sync to equals().
+ if (hash == 0 && runs.length > 0)
+ {
+ hash = runs.length;
+ for (int i = 0; i < runs.length; i++)
+ hash ^= runs[i].glyphVector.hashCode();
+ }
+ return hash;
}
public String toString ()
{
return "TextLayout [string:"+ new String(string, offset, length)
+", Font:"+font+" Rendercontext:"+
frc+"]";
}
/**
* Returns the natural bounds of that text layout. This is made up
* of the ascent plus descent and the text advance.
*
* @return the natural bounds of that text layout
*/