Source code: com/sonalb/net/http/HeaderEntry.java
1 /*
2 * -*- mode: java; c-basic-indent: 4; indent-tabs-mode: nil -*-
3 * :indentSize=4:noTabs=true:tabSize=4:indentOnTab=true:indentOnEnter=true:mode=java:
4 * ex: set tabstop=4 expandtab:
5 *
6 * MrPostman - webmail <-> email gateway
7 * Copyright (C) 2002-2003 MrPostman Development Group
8 * Projectpage: http://mrbook.org/mrpostman/
9 *
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 * In particular, this implies that users are responsible for
21 * using MrPostman after reading the terms and conditions given
22 * by their web-mail provider.
23 *
24 * You should have received a copy of the GNU General Public License
25 * Named LICENSE in the base directory of this distribution,
26 * if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 */
29
30 package com.sonalb.net.http;
31
32
33 /**
34
35 * Represents a single name-value pair of an HTTP Header.
36
37 * @author Sonal Bansal
38
39 */
40 public class HeaderEntry implements Cloneable {
41 public static final String CVSID = "$Id: HeaderEntry.java,v 1.5 2003/02/09 23:38:10 lbruand Exp $";
42 private String key;
43 private String value;
44
45 private HeaderEntry() {
46 }
47
48 /**
49
50 * Creates a HeaderEntry with specified key and value.
51
52 * @param key the name; must be non-null
53
54 * @param value the value
55
56 */
57 public HeaderEntry(String key, String value) {
58 if (key == null) {
59 throw new IllegalArgumentException("The Key can't be null");
60 }
61
62 this.key = key;
63
64 this.value = value;
65 }
66
67 /**
68
69 * Gets the Key/Name.
70
71 */
72 public String getKey() {
73 return (key);
74 }
75
76 /**
77
78 * Gets the Value.
79
80 */
81 public String getValue() {
82 return (value);
83 }
84
85 public boolean equals(Object o) {
86 int i = 0;
87
88 if (o instanceof HeaderEntry) {
89 HeaderEntry x = (HeaderEntry) o;
90
91 if (key.equalsIgnoreCase(x.getKey())) {
92 i++;
93 }
94
95 if (value != null) {
96 if (value.equals(x.getValue())) {
97 i++;
98 }
99 } else if (x.getValue() == null) {
100 i++;
101 }
102 }
103
104 if (i != 2) {
105 return (false);
106 }
107
108 return (true);
109 }
110
111 public String toString() {
112 return (key + ":" + value);
113 }
114
115 public Object clone() throws CloneNotSupportedException {
116 return (super.clone());
117 }
118 }