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