/*
 * Copyright 2000-2012 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.util.xml;

import com.intellij.openapi.util.Comparing;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author peter
 */
public class XmlName implements Comparable<XmlName> {
  private final String myLocalName;
  private final String myNamespaceKey;

  private final int myHashCode;

  public XmlName(@NotNull @NonNls final String localName) {
    this(localName, null);
  }

  public XmlName(@NotNull @NonNls final String localName, @Nullable final String namespaceKey) {
    myLocalName = localName;
    myNamespaceKey = namespaceKey;

    myHashCode = 31 * myLocalName.hashCode() + (myNamespaceKey != null ? myNamespaceKey.hashCode() : 0);
  }

  @NotNull
  public final String getLocalName() {
    return myLocalName;
  }

  @Nullable
  public final String getNamespaceKey() {
    return myNamespaceKey;
  }

  public boolean equals(final Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    final XmlName xmlName = (XmlName)o;

    if (!myLocalName.equals(xmlName.myLocalName)) return false;
    if (Comparing.equal(myNamespaceKey, xmlName.myNamespaceKey)) return true;

    if (myNamespaceKey != null ? !myNamespaceKey.equals(xmlName.myNamespaceKey) : xmlName.myNamespaceKey != null) return false;

    return true;
  }

  public int hashCode() {
    return myHashCode;
  }


  public int compareTo(XmlName o) {
    final int i = myLocalName.compareTo(o.myLocalName);
    if (i != 0) return i;
    if (Comparing.equal(myNamespaceKey, o.myNamespaceKey)) return 0;
    if (myNamespaceKey == null) return -1;
    if (o.myNamespaceKey == null) return 1;
    return myNamespaceKey.compareTo(o.myNamespaceKey);
  }

  public String toString() {
    return myNamespaceKey + " : " + myLocalName;
  }
}

@@ -2154,84 +2154,23 @@
  0) 
-return i;%0A    if (Comparing.equal(myNamespaceKey, o.myNamespaceKey))
+%7B%0A     
  return 
 0;%0A 
@@ -2169,109 +2169,46 @@
 urn 
-0
+i
 ;%0A    
-if (myNamespaceKey == null) return -1;%0A    if (o.myNamespaceKey == null) return 1;%0A    return 
+%7D%0A    return Comparing.compare(
 myNa
@@ -2217,27 +2217,18 @@
 spaceKey
-.compareTo(
+, 
 o.myName

simplify compareTo()