/[classpath]/classpath/javax/xml/namespace/QName.java
ViewVC logotype

Diff of /classpath/javax/xml/namespace/QName.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by dog, Mon Sep 5 12:37:38 2005 UTC revision 1.8 by tromey, Tue Sep 20 14:25:35 2005 UTC
# Line 1  Line 1 
1  /* QName.java - An XML qualified name.  /* QName.java - An XML qualified name.
2     Copyright (C) 2004 Free Software Foundation, Inc.     Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 38  exception statement from your version. * Line 38  exception statement from your version. *
38    
39  package javax.xml.namespace;  package javax.xml.namespace;
40    
41    import java.io.Serializable;
42    
43  import javax.xml.XMLConstants;  import javax.xml.XMLConstants;
44    
45  /**  /**
# Line 47  import javax.xml.XMLConstants; Line 49  import javax.xml.XMLConstants;
49   * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>   * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
50   * @since 1.3   * @since 1.3
51   */   */
52  public class QName  public class QName implements Serializable
53  {  {
54      private static final long serialVersionUID = 4418622981026545151L;
55    
56    private final String namespaceURI;    private final String namespaceURI;
57    private final String localPart;    private final String localPart;
58    private final String prefix;    private final String prefix;
59    private final String qName;    private transient String qName;
60    int hashCode = -1;    transient int hashCode = -1;
61    
62    public QName(String namespaceURI, String localPart)    public QName(String namespaceURI, String localPart)
63    {    {
# Line 78  public class QName Line 81  public class QName
81      this.namespaceURI = namespaceURI;      this.namespaceURI = namespaceURI;
82      this.localPart = localPart;      this.localPart = localPart;
83      this.prefix = prefix;      this.prefix = prefix;
       
     StringBuffer buf = new StringBuffer();  
     if (namespaceURI.length() > 0)  
       {  
         buf.append('{');  
         buf.append(namespaceURI);  
         buf.append('}');  
       }  
     if (prefix.length() > 0)  
       {  
         buf.append(prefix);  
         buf.append(':');  
       }  
     buf.append(localPart);  
     qName = buf.toString();  
84    }    }
85    
86    public QName(String localPart)    public QName(String localPart)
# Line 115  public class QName Line 103  public class QName
103      return prefix;      return prefix;
104    }    }
105    
106    public boolean equals(Object obj)    public final boolean equals(Object obj)
107    {    {
108      if (obj instanceof QName)      if (obj instanceof QName)
109        {        {
# Line 129  public class QName Line 117  public class QName
117    public final int hashCode()    public final int hashCode()
118    {    {
119      if (hashCode == -1)      if (hashCode == -1)
120        {        hashCode = localPart.hashCode() ^ namespaceURI.hashCode();
         StringBuffer buf = new StringBuffer();  
         buf.append('{');  
         buf.append(namespaceURI);  
         buf.append('}');  
         buf.append(localPart);  
         hashCode = buf.toString().hashCode();  
       }  
121      return hashCode;      return hashCode;
122    }    }
123    
124    public String toString()    public synchronized String toString()
125    {    {
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          }
143      return qName;      return qName;
144    }    }
145    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26