Skip to content

Commit b41d291

Browse files
authored
Redesigned mime classes and interfaces (#23)
For #22 - redesigned main interfaces and primary implementations, fixed tests and matchers.
1 parent d095b35 commit b41d291

File tree

11 files changed

+280
-306
lines changed

11 files changed

+280
-306
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<dependency>
5858
<groupId>org.hamcrest</groupId>
5959
<artifactId>hamcrest</artifactId>
60+
<scope>provided</scope>
6061
</dependency>
6162
</dependencies>
6263
<build>

src/main/java/wtf/g4s8/mime/MimeType.java

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,91 @@
44
*/
55
package wtf.g4s8.mime;
66

7-
import java.io.IOException;
8-
import java.util.Map;
7+
import java.util.Optional;
8+
import java.util.Set;
99

1010
/**
1111
* Media type (or MIME type).
1212
*
13-
* @since 0.1
13+
* @since 2.0
1414
*/
1515
public interface MimeType {
1616

1717
/**
1818
* Type name.
19-
* @return Type name string
20-
* @throws IOException If failed to read
19+
* @return Name string
2120
*/
22-
String type() throws IOException;
21+
String type();
2322

2423
/**
2524
* Subtype name.
26-
* @return Subtype name string
27-
* @throws IOException If failed to read
25+
* @return Subtype string
2826
*/
29-
String subtype() throws IOException;
27+
String subtype();
3028

3129
/**
32-
* Optional parameters.
33-
* @return Parameter map
34-
* @throws IOException If failed to read
30+
* Optional parameters names.
31+
* @return unordered case-insentetive set of strings
3532
*/
36-
Map<String, String> params() throws IOException;
33+
Set<String> params();
34+
35+
/**
36+
* Parameter value for name.
37+
* @param name Parameter name, case-insentetive
38+
* @return Optional parameter value if present for the name
39+
*/
40+
Optional<String> param(String name);
41+
42+
/**
43+
* Mime type of string source.
44+
* @return Mime type implementation for string provided
45+
*/
46+
static MimeType of(final CharSequence src) {
47+
return new MimeTypeOfString(src);
48+
}
49+
50+
/**
51+
* Default decorator for mime type.
52+
* @since 2.0
53+
*/
54+
abstract class Wrap implements MimeType {
55+
56+
/**
57+
* Delegate.
58+
*/
59+
private final MimeType origin;
60+
61+
/**
62+
* Wraps origin.
63+
* @param origin Delegate
64+
*/
65+
protected Wrap(final MimeType origin) {
66+
this.origin = origin;
67+
}
68+
69+
@Override
70+
public final String type() {
71+
return this.origin.type();
72+
}
73+
74+
@Override
75+
public String subtype() {
76+
return this.origin.subtype();
77+
}
78+
79+
@Override
80+
public Set<String> params() {
81+
return this.origin.params();
82+
}
83+
84+
@Override
85+
public Optional<String> param(final String name) {
86+
return this.origin.param(name);
87+
}
88+
89+
@Override
90+
public String toString() {
91+
return this.origin.toString();
92+
}
93+
}
3794
}

src/main/java/wtf/g4s8/mime/MimeTypeOf.java

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)