Skip to content

Commit 02c4cb8

Browse files
author
Tom Tromey
committed
* javax/xml/namespace/QName.java: Now Serializable.
(serialVersionUID): New field. (qName, hashCode): Now transient. (QName): Don't compute qName here. (equals): Now final. (hashCode): Simplified. (toString): Compute qName here.
1 parent 79cd441 commit 02c4cb8

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2005-09-20 Tom Tromey <tromey@redhat.com>
2+
3+
* javax/xml/namespace/QName.java: Now Serializable.
4+
(serialVersionUID): New field.
5+
(qName, hashCode): Now transient.
6+
(QName): Don't compute qName here.
7+
(equals): Now final.
8+
(hashCode): Simplified.
9+
(toString): Compute qName here.
10+
111
2005-09-20 Roman Kennke <kennke@aicas.com>
212

313
* javax/swing/plaf/metal/MetalBorders.java

javax/xml/namespace/QName.java

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* QName.java - An XML qualified name.
2-
Copyright (C) 2004 Free Software Foundation, Inc.
2+
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
33
44
This file is part of GNU Classpath.
55
@@ -38,6 +38,8 @@
3838

3939
package javax.xml.namespace;
4040

41+
import java.io.Serializable;
42+
4143
import javax.xml.XMLConstants;
4244

4345
/**
@@ -47,14 +49,15 @@
4749
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
4850
* @since 1.3
4951
*/
50-
public class QName
52+
public class QName implements Serializable
5153
{
54+
private static final long serialVersionUID = 4418622981026545151L;
5255

5356
private final String namespaceURI;
5457
private final String localPart;
5558
private final String prefix;
56-
private final String qName;
57-
int hashCode = -1;
59+
private transient String qName;
60+
transient int hashCode = -1;
5861

5962
public QName(String namespaceURI, String localPart)
6063
{
@@ -78,21 +81,6 @@ public QName(String namespaceURI, String localPart, String prefix)
7881
this.namespaceURI = namespaceURI;
7982
this.localPart = localPart;
8083
this.prefix = prefix;
81-
82-
StringBuffer buf = new StringBuffer();
83-
if (namespaceURI.length() > 0)
84-
{
85-
buf.append('{');
86-
buf.append(namespaceURI);
87-
buf.append('}');
88-
}
89-
if (prefix.length() > 0)
90-
{
91-
buf.append(prefix);
92-
buf.append(':');
93-
}
94-
buf.append(localPart);
95-
qName = buf.toString();
9684
}
9785

9886
public QName(String localPart)
@@ -115,7 +103,7 @@ public String getPrefix()
115103
return prefix;
116104
}
117105

118-
public boolean equals(Object obj)
106+
public final boolean equals(Object obj)
119107
{
120108
if (obj instanceof QName)
121109
{
@@ -129,19 +117,29 @@ public boolean equals(Object obj)
129117
public final int hashCode()
130118
{
131119
if (hashCode == -1)
132-
{
133-
StringBuffer buf = new StringBuffer();
134-
buf.append('{');
135-
buf.append(namespaceURI);
136-
buf.append('}');
137-
buf.append(localPart);
138-
hashCode = buf.toString().hashCode();
139-
}
120+
hashCode = localPart.hashCode() ^ namespaceURI.hashCode();
140121
return hashCode;
141122
}
142123

143-
public String toString()
124+
public synchronized String toString()
144125
{
126+
if (qName == null)
127+
{
128+
StringBuffer buf = new StringBuffer();
129+
if (namespaceURI.length() > 0)
130+
{
131+
buf.append('{');
132+
buf.append(namespaceURI);
133+
buf.append('}');
134+
}
135+
if (prefix.length() > 0)
136+
{
137+
buf.append(prefix);
138+
buf.append(':');
139+
}
140+
buf.append(localPart);
141+
qName = buf.toString();
142+
}
145143
return qName;
146144
}
147145

0 commit comments

Comments
 (0)