Skip to content
This repository was archived by the owner on Jul 12, 2021. It is now read-only.

Commit 05eb50c

Browse files
committed
Even more cleanup
1 parent 47e3d33 commit 05eb50c

9 files changed

+89
-81
lines changed

pom.xml

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77

88
<packaging>jar</packaging>
99

10-
<version>1.0.0-SNAPSHOT</version>
10+
<version>0.1.0-SNAPSHOT</version>
1111
<name>smsj</name>
1212
<url>http://maven.apache.org</url>
1313

14+
<scm>
15+
<connection>scm:git:[email protected]:marre/smsj.git</connection>
16+
<url>scm:git:[email protected]:marre/smsj.git</url>
17+
<developerConnection>scm:git:[email protected]:marre/smsj.git</developerConnection>
18+
</scm>
19+
1420
<dependencies>
1521
<dependency>
1622
<groupId>org.slf4j</groupId>
1723
<artifactId>slf4j-api</artifactId>
18-
<version>1.6.1</version>
24+
<version>1.7.2</version>
1925
</dependency>
2026

2127
<dependency>
@@ -27,7 +33,7 @@
2733
<dependency>
2834
<groupId>org.slf4j</groupId>
2935
<artifactId>slf4j-simple</artifactId>
30-
<version>1.6.1</version>
36+
<version>1.7.2</version>
3137
<scope>runtime</scope>
3238
</dependency>
3339

src/main/java/org/marre/mime/MimeBodyPart.java

+4-18
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void addHeader(MimeHeader header)
8787
}
8888

8989
/**
90-
* Adds a eader to this body part.
90+
* Adds a header to this body part.
9191
*
9292
* @param headerName The name of the header
9393
* @param headerValue The value
@@ -103,14 +103,10 @@ public void addHeader(String headerName, String headerValue)
103103
}
104104

105105
/**
106-
* Retrieves a header with the given index.
107-
*
108-
* @param index Index of header to retrieve
109-
* @return The header, or null if not found
106+
* Retrieves all headers.
110107
*/
111-
public MimeHeader getHeader(int index)
112-
{
113-
return headers_.get(index);
108+
public Collection<MimeHeader> getHeaders() {
109+
return Collections.unmodifiableCollection(headers_);
114110
}
115111

116112
/**
@@ -130,16 +126,6 @@ public MimeHeader getHeader(String headerName)
130126
return null;
131127
}
132128

133-
/**
134-
* Returns the number of headers.
135-
*
136-
* @return The number of headers
137-
*/
138-
public int getHeaderCount()
139-
{
140-
return headers_.size();
141-
}
142-
143129
/**
144130
* Sets the main content of this body part.
145131
*

src/main/java/org/marre/mime/MimeUtil.java src/main/java/org/marre/mime/MimeFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
import java.io.UnsupportedEncodingException;
3838

39-
public final class MimeUtil
39+
public final class MimeFactory
4040
{
41-
private MimeUtil()
41+
private MimeFactory()
4242
{
4343
// Utility function
4444
}

src/main/java/org/marre/mime/MimeHeader.java

+33-20
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* ***** END LICENSE BLOCK ***** */
3535
package org.marre.mime;
3636

37+
import java.util.Collection;
3738
import java.util.Collections;
3839
import java.util.List;
3940
import java.util.LinkedList;
@@ -43,7 +44,7 @@ public class MimeHeader
4344
protected final String headerName_;
4445
protected String headerValue_;
4546

46-
protected final List<MimeHeaderParam> params_ = new LinkedList<MimeHeaderParam>();
47+
protected final List<MimeHeaderParameter> params_ = new LinkedList<MimeHeaderParameter>();
4748

4849
public MimeHeader(String name, String value)
4950
{
@@ -69,15 +70,15 @@ public String getValue()
6970
public void setParam(String theName, String theValue)
7071
{
7172
// Remove parameter if it already exists...
72-
removeParam(theName);
73+
removeParameter(theName);
7374

7475
// Add new...
75-
params_.add(new MimeHeaderParam(theName, theValue));
76+
params_.add(new MimeHeaderParameter(theName, theValue));
7677
}
7778

78-
public MimeHeaderParam getParam(String theName)
79+
public MimeHeaderParameter getParameter(String theName)
7980
{
80-
for (MimeHeaderParam param : params_) {
81+
for (MimeHeaderParameter param : params_) {
8182
if (param.getName().equalsIgnoreCase(theName)) {
8283
return param;
8384
}
@@ -87,28 +88,18 @@ public MimeHeaderParam getParam(String theName)
8788
return null;
8889
}
8990

90-
public void removeParam(String theName)
91+
public void removeParameter(String theName)
9192
{
92-
MimeHeaderParam param = getParam(theName);
93+
MimeHeaderParameter param = getParameter(theName);
9394
if (param != null)
9495
{
9596
params_.remove(param);
9697
}
9798
}
9899

99-
public List getAllParams()
100+
public Collection<MimeHeaderParameter> getParameters()
100101
{
101-
return Collections.unmodifiableList(params_);
102-
}
103-
104-
public int getParamCount()
105-
{
106-
return params_.size();
107-
}
108-
109-
public MimeHeaderParam getParam(int theIndex)
110-
{
111-
return params_.get(theIndex);
102+
return Collections.unmodifiableCollection(params_);
112103
}
113104

114105
public String toString()
@@ -117,10 +108,32 @@ public String toString()
117108

118109
sb.append(headerName_).append("=").append(headerValue_);
119110

120-
for (MimeHeaderParam param : params_) {
111+
for (MimeHeaderParameter param : params_) {
121112
sb.append("; ").append(param.getName()).append("=").append(param.getValue());
122113
}
123114

124115
return sb.toString();
125116
}
117+
118+
@Override
119+
public boolean equals(Object o) {
120+
if (this == o) return true;
121+
if (!(o instanceof MimeHeader)) return false;
122+
123+
MimeHeader that = (MimeHeader) o;
124+
125+
if (!headerName_.equals(that.headerName_)) return false;
126+
if (!headerValue_.equals(that.headerValue_)) return false;
127+
if (!params_.equals(that.params_)) return false;
128+
129+
return true;
130+
}
131+
132+
@Override
133+
public int hashCode() {
134+
int result = headerName_.hashCode();
135+
result = 31 * result + headerValue_.hashCode();
136+
result = 31 * result + params_.hashCode();
137+
return result;
138+
}
126139
}

src/main/java/org/marre/mime/MimeHeaderParam.java src/main/java/org/marre/mime/MimeHeaderParameter.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
* ***** END LICENSE BLOCK ***** */
3535
package org.marre.mime;
3636

37-
public final class MimeHeaderParam
37+
public final class MimeHeaderParameter
3838
{
3939
private final String name_;
4040
private final String value_;
4141

42-
public MimeHeaderParam(String name, String value)
42+
public MimeHeaderParameter(String name, String value)
4343
{
4444
name_ = name;
4545
value_ = value;
@@ -54,4 +54,24 @@ public String getValue()
5454
{
5555
return value_;
5656
}
57+
58+
@Override
59+
public boolean equals(Object o) {
60+
if (this == o) return true;
61+
if (!(o instanceof MimeHeaderParameter)) return false;
62+
63+
MimeHeaderParameter that = (MimeHeaderParameter) o;
64+
65+
if (!name_.equals(that.name_)) return false;
66+
if (!value_.equals(that.value_)) return false;
67+
68+
return true;
69+
}
70+
71+
@Override
72+
public int hashCode() {
73+
int result = name_.hashCode();
74+
result = 31 * result + value_.hashCode();
75+
return result;
76+
}
5777
}

src/main/java/org/marre/mime/MimeMultipart.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* ***** END LICENSE BLOCK ***** */
3535
package org.marre.mime;
3636

37+
import java.util.Collection;
38+
import java.util.Collections;
3739
import java.util.LinkedList;
3840
import java.util.List;
3941

@@ -56,14 +58,8 @@ public void removeBodyPart(MimeBodyPart bodyPart)
5658
bodyParts_.remove(bodyPart);
5759
}
5860

59-
public MimeBodyPart getBodyPart(int index)
60-
{
61-
return bodyParts_.get(index);
62-
}
63-
64-
public int getBodyPartCount()
65-
{
66-
return bodyParts_.size();
61+
public Collection<MimeBodyPart> getBodyParts() {
62+
return Collections.unmodifiableCollection(bodyParts_);
6763
}
6864

6965
public String toString()

src/main/java/org/marre/mime/encoder/TextMimeEncoder.java

+6-16
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@
3737
import java.io.IOException;
3838
import java.io.OutputStream;
3939

40-
import org.marre.mime.MimeBodyPart;
41-
import org.marre.mime.MimeContentType;
42-
import org.marre.mime.MimeHeader;
43-
import org.marre.mime.MimeHeaderParam;
44-
import org.marre.mime.MimeMultipart;
40+
import org.marre.mime.*;
41+
import org.marre.mime.MimeHeaderParameter;
4542
import org.marre.util.StringUtil;
4643

4744
/**
@@ -100,9 +97,7 @@ public void writeContentType(OutputStream os, MimeBodyPart msg) throws IOExcepti
10097
*/
10198
public void writeHeaders(OutputStream os, MimeBodyPart msg) throws IOException
10299
{
103-
for (int i = 0; i < msg.getHeaderCount(); i++)
104-
{
105-
MimeHeader header = msg.getHeader(i);
100+
for (MimeHeader header : msg.getHeaders()) {
106101
writeHeader(os, header);
107102
}
108103
os.write("\r\n".getBytes());
@@ -159,9 +154,7 @@ protected void writeHeader(OutputStream os, MimeHeader header) throws IOExceptio
159154

160155
strBuff.append(name).append(": ").append(value);
161156

162-
for (int i = 0; i < header.getParamCount(); i++)
163-
{
164-
MimeHeaderParam headerParam = header.getParam(i);
157+
for (MimeHeaderParameter headerParam : header.getParameters()) {
165158
// + "; charset=adsfasdf; param=value"
166159
strBuff.append("; ").append(headerParam.getName()).append("=").append(headerParam.getValue());
167160
}
@@ -185,13 +178,10 @@ protected void writeHeader(OutputStream os, MimeHeader header) throws IOExceptio
185178
private void writeMultipart(OutputStream os, MimeMultipart multipart) throws IOException
186179
{
187180
MimeContentType ct = multipart.getContentType();
188-
MimeHeaderParam boundaryParam = ct.getParam("boundary");
181+
MimeHeaderParameter boundaryParam = ct.getParameter("boundary");
189182
String boundary = "--" + boundaryParam.getValue();
190183

191-
for (int i = 0; i < multipart.getBodyPartCount(); i++)
192-
{
193-
MimeBodyPart part = multipart.getBodyPart(i);
194-
184+
for (MimeBodyPart part : multipart.getBodyParts()) {
195185
// Write boundary string
196186
os.write(boundary.getBytes());
197187
os.write("\r\n".getBytes());

src/main/java/org/marre/wap/WapMimeEncoder.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.io.ByteArrayOutputStream;
3838
import java.io.IOException;
3939
import java.io.OutputStream;
40+
import java.util.Collection;
4041

4142
import org.marre.mime.MimeBodyPart;
4243
import org.marre.mime.MimeHeader;
@@ -103,9 +104,7 @@ public void writeContentType(OutputStream os, MimeBodyPart msg) throws IOExcepti
103104
*/
104105
public void writeHeaders(OutputStream os, MimeBodyPart msg) throws IOException
105106
{
106-
for (int i = 0; i < msg.getHeaderCount(); i++)
107-
{
108-
MimeHeader header = msg.getHeader(i);
107+
for (MimeHeader header : msg.getHeaders()) {
109108
WspHeaderEncoder.writeHeader(wspEncodingVersion_, os, header);
110109
}
111110
}
@@ -151,12 +150,12 @@ public void writeBody(OutputStream os, MimeBodyPart msg) throws IOException
151150
// Section 8.5.2 in WAP-230-WSP-20010705
152151
private void writeMultipart(OutputStream os, MimeMultipart multipart) throws IOException
153152
{
153+
Collection<MimeBodyPart> bodyParts = multipart.getBodyParts();
154+
154155
// nEntries
155-
WspUtil.writeUintvar(os, multipart.getBodyPartCount());
156+
WspUtil.writeUintvar(os, bodyParts.size());
156157

157-
for (int i = 0; i < multipart.getBodyPartCount(); i++)
158-
{
159-
MimeBodyPart part = multipart.getBodyPart(i);
158+
for (MimeBodyPart part : bodyParts) {
160159
ByteArrayOutputStream headers = new ByteArrayOutputStream();
161160
ByteArrayOutputStream content = new ByteArrayOutputStream();
162161

src/main/java/org/marre/wap/WspUtil.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import java.util.Map;
4242

4343
import org.marre.mime.MimeHeader;
44-
import org.marre.mime.MimeHeaderParam;
44+
import org.marre.mime.MimeHeaderParameter;
4545

4646
/**
4747
*
@@ -772,7 +772,7 @@ public static void writeContentType(WspEncodingVersion wspEncodingVersion, Outpu
772772
*/
773773
public static void writeContentType(WspEncodingVersion wspEncodingVersion, OutputStream theOs, MimeHeader theContentType) throws IOException
774774
{
775-
if (theContentType.getParamCount() == 0)
775+
if (theContentType.getParameters().isEmpty())
776776
{
777777
// Simple content type, use "constrained-media" format
778778
writeContentType(wspEncodingVersion, theOs, theContentType.getValue());
@@ -798,9 +798,7 @@ public static void writeContentType(WspEncodingVersion wspEncodingVersion, Outpu
798798
}
799799

800800
// Add Parameters
801-
for (int i = 0; i < theContentType.getParamCount(); i++)
802-
{
803-
MimeHeaderParam headerParam = theContentType.getParam(i);
801+
for (MimeHeaderParameter headerParam : theContentType.getParameters()) {
804802
writeParameter(wspEncodingVersion, baos, headerParam.getName(), headerParam.getValue());
805803
}
806804
baos.close();

0 commit comments

Comments
 (0)