[6785] | 1 | /**************************************************************** |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one * |
---|
| 3 | * or more contributor license agreements. See the NOTICE file * |
---|
| 4 | * distributed with this work for additional information * |
---|
| 5 | * regarding copyright ownership. The ASF licenses this file * |
---|
| 6 | * to you under the Apache License, Version 2.0 (the * |
---|
| 7 | * "License"); you may not use this file except in compliance * |
---|
| 8 | * with the License. You may obtain a copy of the License at * |
---|
| 9 | * * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 * |
---|
| 11 | * * |
---|
| 12 | * Unless required by applicable law or agreed to in writing, * |
---|
| 13 | * software distributed under the License is distributed on an * |
---|
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * |
---|
| 15 | * KIND, either express or implied. See the License for the * |
---|
| 16 | * specific language governing permissions and limitations * |
---|
| 17 | * under the License. * |
---|
| 18 | ****************************************************************/ |
---|
| 19 | |
---|
| 20 | package org.apache.james.mime4j.stream; |
---|
| 21 | |
---|
| 22 | import org.apache.james.mime4j.util.LangUtils; |
---|
| 23 | |
---|
| 24 | public final class NameValuePair { |
---|
| 25 | |
---|
| 26 | private final String name; |
---|
| 27 | private final String value; |
---|
| 28 | |
---|
| 29 | public NameValuePair(final String name, final String value) { |
---|
| 30 | super(); |
---|
| 31 | if (name == null) { |
---|
| 32 | throw new IllegalArgumentException("Name may not be null"); |
---|
| 33 | } |
---|
| 34 | this.name = name; |
---|
| 35 | this.value = value; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | public String getName() { |
---|
| 39 | return this.name; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | public String getValue() { |
---|
| 43 | return this.value; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | public String toString() { |
---|
| 47 | if (this.value == null) { |
---|
| 48 | return name; |
---|
| 49 | } else { |
---|
| 50 | StringBuilder buffer = new StringBuilder(); |
---|
| 51 | buffer.append(this.name); |
---|
| 52 | buffer.append("="); |
---|
| 53 | buffer.append("\""); |
---|
| 54 | buffer.append(this.value); |
---|
| 55 | buffer.append("\""); |
---|
| 56 | return buffer.toString(); |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | public boolean equals(final Object object) { |
---|
| 61 | if (this == object) return true; |
---|
| 62 | if (object instanceof NameValuePair) { |
---|
| 63 | NameValuePair that = (NameValuePair) object; |
---|
| 64 | return this.name.equals(that.name) |
---|
| 65 | && LangUtils.equals(this.value, that.value); |
---|
| 66 | } else { |
---|
| 67 | return false; |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | public int hashCode() { |
---|
| 72 | int hash = LangUtils.HASH_SEED; |
---|
| 73 | hash = LangUtils.hashCode(hash, this.name); |
---|
| 74 | hash = LangUtils.hashCode(hash, this.value); |
---|
| 75 | return hash; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | } |
---|