1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.report.pentaho.styles;
24 
25 /**
26  * A hash key for the stylemapper.
27  *
28  * @author Thomas Morgner
29  * @since 12.03.2007
30  */
31 public final class StyleMapperKey
32 {
33 
34     private final String elementNamespace;
35     private final String elementName;
36     private final String attributeNamespace;
37     private final String attributeName;
38     private final int hashCode;
39 
StyleMapperKey(final String elementNamespace, final String elementName, final String attributeNamespace, final String attributeName)40     public StyleMapperKey(final String elementNamespace,
41             final String elementName,
42             final String attributeNamespace,
43             final String attributeName)
44     {
45         if (elementNamespace == null)
46         {
47             throw new NullPointerException();
48         }
49         if (elementName == null)
50         {
51             throw new NullPointerException();
52         }
53 
54         this.elementNamespace = elementNamespace;
55         this.elementName = elementName;
56         this.attributeNamespace = attributeNamespace;
57         this.attributeName = attributeName;
58         this.hashCode = computeHashCode();
59     }
60 
getElementNamespace()61     public String getElementNamespace()
62     {
63         return elementNamespace;
64     }
65 
getElementName()66     public String getElementName()
67     {
68         return elementName;
69     }
70 
getAttributeNamespace()71     public String getAttributeNamespace()
72     {
73         return attributeNamespace;
74     }
75 
getAttributeName()76     public String getAttributeName()
77     {
78         return attributeName;
79     }
80 
equals(final Object o)81     public boolean equals(final Object o)
82     {
83         if (this != o)
84         {
85             if (o == null || getClass() != o.getClass())
86             {
87                 return false;
88             }
89 
90             final StyleMapperKey that = (StyleMapperKey) o;
91 
92             if ((attributeName != null ? !attributeName.equals(that.attributeName) : that.attributeName != null) || (attributeNamespace != null ? !attributeNamespace.equals(that.attributeNamespace) : that.attributeNamespace != null) || !elementName.equals(that.elementName) || !elementNamespace.equals(that.elementNamespace))
93             {
94                 return false;
95             }
96         }
97 
98         return true;
99     }
100 
computeHashCode()101     private int computeHashCode()
102     {
103         int result = elementNamespace.hashCode();
104         result = 31 * result + elementName.hashCode();
105         result = 31 * result + (attributeNamespace != null ? attributeNamespace.hashCode() : 0);
106         result = 31 * result + (attributeName != null ? attributeName.hashCode() : 0);
107         return result;
108     }
109 
hashCode()110     public int hashCode()
111     {
112         return hashCode;
113     }
114 }
115