Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 017f2b219491991da16e40c89ee4ced8fdd3b450 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package org.eclipse.jst.jsf.common.dom;

/**
 * Uniquely identifies a named attribute on a tag usint TagIdentifier as a way
 * to uniquely identify the host tag.  All instances should be considered 
 * immutable and idempotent.  Factories may cache copies as transparent 
 * singletons for unique TagIdentifier/attribute.
 * 
 * THIS CLASS IS NOT API AND SHOULD NOT BE USED
 * 
 * @author cbateman
 *
 */
public abstract class AttributeIdentifier
{
    /**
     * @return the attribute name (local name, namespace prefix is currently ignored)
     */
    public abstract String getName();
    
    /**
     * @return the tag identifier
     */
    public abstract TagIdentifier getTagIdentifier();
    
    public final boolean equals(Object compareTo)
    {
        if (compareTo instanceof AttributeIdentifier)
        {
            return isSameAttributeType((AttributeIdentifier) compareTo);
        }
        return false;
    }
    
    public final int hashCode()
    {
        // use toLowerCase to ensure equals matches
        int hashCode = getName().toLowerCase().hashCode();
        
        int tagCode = getTagIdentifier().hashCode();
       
        hashCode = hashCode ^ tagCode;
        
        return hashCode;
    }

    /**
     * @param attributeId
     * @return true if attributeId represents the same attribute as this.
     */
    public final boolean isSameAttributeType(AttributeIdentifier attributeId)
    {
        // if same object, always true
        if (attributeId == this)
        {
            return true;
        }
        

        // if tag identifiers not same, then always false.
        if (!getTagIdentifier().isSameTagType(attributeId.getTagIdentifier()))
        {
            return false;
        }

        // if tag id is the same, the tag name must be too.
        return getName().toLowerCase().equals(attributeId.getName().toLowerCase());
    }

}

Back to the top