001 /****************************************************************
002 * Licensed to the Apache Software Foundation (ASF) under one *
003 * or more contributor license agreements. See the NOTICE file *
004 * distributed with this work for additional information *
005 * regarding copyright ownership. The ASF licenses this file *
006 * to you under the Apache License, Version 2.0 (the *
007 * "License"); you may not use this file except in compliance *
008 * with the License. You may obtain a copy of the License at *
009 * *
010 * http://www.apache.org/licenses/LICENSE-2.0 *
011 * *
012 * Unless required by applicable law or agreed to in writing, *
013 * software distributed under the License is distributed on an *
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015 * KIND, either express or implied. See the License for the *
016 * specific language governing permissions and limitations *
017 * under the License. *
018 ****************************************************************/
019
020 package org.apache.james.mime4j.stream;
021
022 import org.apache.james.mime4j.util.LangUtils;
023
024 /**
025 * A name / value tuple
026 */
027 public final class NameValuePair {
028
029 private final String name;
030 private final String value;
031
032 public NameValuePair(final String name, final String value) {
033 super();
034 if (name == null) {
035 throw new IllegalArgumentException("Name may not be null");
036 }
037 this.name = name;
038 this.value = value;
039 }
040
041 public String getName() {
042 return this.name;
043 }
044
045 public String getValue() {
046 return this.value;
047 }
048
049 public String toString() {
050 if (this.value == null) {
051 return name;
052 } else {
053 StringBuilder buffer = new StringBuilder();
054 buffer.append(this.name);
055 buffer.append("=");
056 buffer.append("\"");
057 buffer.append(this.value);
058 buffer.append("\"");
059 return buffer.toString();
060 }
061 }
062
063 public boolean equals(final Object object) {
064 if (this == object) return true;
065 if (object instanceof NameValuePair) {
066 NameValuePair that = (NameValuePair) object;
067 return this.name.equals(that.name)
068 && LangUtils.equals(this.value, that.value);
069 } else {
070 return false;
071 }
072 }
073
074 public int hashCode() {
075 int hash = LangUtils.HASH_SEED;
076 hash = LangUtils.hashCode(hash, this.name);
077 hash = LangUtils.hashCode(hash, this.value);
078 return hash;
079 }
080
081 }