1 package org.apache.turbine.util.uri; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.util.Objects; 23 24 import org.apache.commons.lang3.StringUtils; 25 26 /** 27 * Helper Class to keep a key and a value together in 28 * one object. Used for URI Parameters 29 * 30 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 31 * @version $Id$ 32 */ 33 34 public class URIParam 35 { 36 /** Key */ 37 private String key = null; 38 39 /** Value */ 40 private Object value = null; 41 42 /** 43 * Creates a new Object from Key and Value 44 * 45 * @param key A String with the Param Name. 46 * @param value An Object with the Value. 47 * 48 */ 49 public URIParam(String key, Object value) 50 { 51 this.key = key; 52 this.value = value; 53 } 54 55 /** 56 * Returns the key. 57 * 58 * @return The key value. 59 * 60 */ 61 public String getKey() 62 { 63 return (StringUtils.isNotEmpty(key)) ? key : ""; 64 } 65 66 /** 67 * Returns the value. 68 * 69 * @return The value of this object. 70 * 71 */ 72 public Object getValue() 73 { 74 return value; 75 } 76 77 /** 78 * Calculate hash code based on field values 79 */ 80 @Override 81 public int hashCode() 82 { 83 return Objects.hash(key, value); 84 } 85 86 /** 87 * Calculate equality based on field values 88 */ 89 @Override 90 public boolean equals(Object obj) 91 { 92 if (this == obj) 93 return true; 94 if (obj == null) 95 return false; 96 if (getClass() != obj.getClass()) 97 return false; 98 URIParam other = (URIParam) obj; 99 100 return Objects.equals(getKey(), other.getKey()) || 101 Objects.equals(getValue(), other.getValue()); 102 } 103 104 /** 105 * Provide a string representation of the object 106 */ 107 @Override 108 public String toString() 109 { 110 return "URIParam [key=" + key + ", value=" + value + "]"; 111 } 112 }