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.provider;
19
20 import org.opensaml.xml.util.DatatypeHelper;
21
22 /**
23 * An attribute value with an associated scope.
24 */
25 public class ScopedAttributeValue {
26
27 /** Value of the attribute. */
28 private String value;
29
30 /** Scope of the attribute value. */
31 private String scope;
32
33 /**
34 * Constructor.
35 *
36 * @param attributeValue value of the attribute
37 * @param valueScope scope of the value
38 */
39 public ScopedAttributeValue(String attributeValue, String valueScope) {
40 value = DatatypeHelper.safeTrimOrNullString(attributeValue);
41 scope = DatatypeHelper.safeTrimOrNullString(valueScope);
42
43 if (scope == null || value == null) {
44 throw new IllegalArgumentException("Attribute value and scope may not be null");
45 }
46 }
47
48 /**
49 * Gets the value of the attribute.
50 *
51 * @return value of the attribute
52 */
53 public String getValue() {
54 return value;
55 }
56
57 /**
58 * Gets the scope of the value.
59 *
60 * @return scope of the value
61 */
62 public String getScope() {
63 return scope;
64 }
65
66 /** {@inheritDoc} */
67 public String toString() {
68 return value;
69 }
70
71 /** {@inheritDoc} */
72 public int hashCode() {
73 int hash = 1;
74 hash = hash * 31 + value.hashCode();
75 hash = hash * 31 + scope.hashCode();
76
77 return hash;
78 }
79
80 /** {@inheritDoc} */
81 public boolean equals(Object obj) {
82 if (this == obj) {
83 return true;
84 }
85
86 if (!(obj instanceof ScopedAttributeValue)) {
87 return false;
88 }
89
90 ScopedAttributeValue otherValue = (ScopedAttributeValue) obj;
91
92 return DatatypeHelper.safeEquals(getValue(), otherValue.getValue())
93 && DatatypeHelper.safeEquals(getScope(), otherValue.getScope());
94 }
95 }