View Javadoc

1   /*
2    * Copyright [2006] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package edu.internet2.middleware.shibboleth.common.attribute;
18  
19  import java.util.Collection;
20  import java.util.Comparator;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Locale;
24  import java.util.Map;
25  
26  import edu.internet2.middleware.shibboleth.common.attribute.encoding.AttributeEncoder;
27  
28  /**
29   * A resolved attribute.
30   * 
31   * @param <ValueType> the object type of the values for this attribute
32   */
33  public abstract class BaseAttribute<ValueType> implements Comparable<BaseAttribute> {
34      
35      /** Localized human intelligible attribute name. */
36      private Map<Locale, String> displayNames;
37      
38      /** Localized human readable description of attribute. */
39      private Map<Locale, String> displayDescriptions;
40      
41      /** Constructor. */
42      protected BaseAttribute(){
43          displayNames = new HashMap<Locale, String>();
44          displayDescriptions = new HashMap<Locale, String>();
45      }
46  
47      /**
48       * Gets the localized human readable description of attribute.
49       * 
50       * @return human readable description of attribute
51       */
52      public Map<Locale, String> getDisplayDescriptions() {
53          return displayDescriptions;
54      }
55  
56      /**
57       * Gets the localized human readable name of the attribute.
58       * 
59       * @return human readable name of the attribute
60       */
61      public Map<Locale, String> getDisplayNames() {
62          return displayNames;
63      }
64  
65      /**
66       * Gets the list of attribute encoders usable with this attribute.
67       * 
68       * @return attribute encoders usable with this attribute, must never be null
69       */
70      public abstract List<AttributeEncoder> getEncoders();
71  
72      /**
73       * Gets the unique ID of the attribute.
74       * 
75       * @return unique ID of the attribute
76       */
77      public abstract String getId();
78  
79      /**
80       * Gets the compartor used to sort values. If no compartor is set then the value set with be natural ordering
81       * sorted.
82       * 
83       * @return compartor used to sort values
84       */
85      public abstract Comparator<ValueType> getValueComparator();
86  
87      /**
88       * Gets the values of the attribute.
89       * 
90       * @return values of the attribute, must never be null
91       */
92      public abstract Collection<ValueType> getValues();
93  
94      /** {@inheritDoc} */
95      public int hashCode() {
96          return getId().hashCode();
97      }
98      
99      /** {@inheritDoc} */
100     public boolean equals(Object obj) {
101         if(obj == this){
102             return true;
103         }
104         
105         if(obj instanceof BaseAttribute){
106             return obj.hashCode() == hashCode();
107         }
108         
109         return false;
110     }
111     
112     /** {@inheritDoc} */
113     public int compareTo(BaseAttribute o) {
114         return getId().compareTo(o.getId());
115     }
116     
117     /** {@inheritDoc} */
118     public String toString() {
119         return getId();
120     }
121 }