Skip to content

Commit

Permalink
Redesigned mime classes and interfaces (#23)
Browse files Browse the repository at this point in the history
For #22 - redesigned main interfaces and primary implementations,
fixed tests and matchers.
  • Loading branch information
g4s8 committed May 19, 2021
1 parent d095b35 commit b41d291
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 306 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
Expand Down
83 changes: 70 additions & 13 deletions src/main/java/wtf/g4s8/mime/MimeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,91 @@
*/
package wtf.g4s8.mime;

import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
* Media type (or MIME type).
*
* @since 0.1
* @since 2.0
*/
public interface MimeType {

/**
* Type name.
* @return Type name string
* @throws IOException If failed to read
* @return Name string
*/
String type() throws IOException;
String type();

/**
* Subtype name.
* @return Subtype name string
* @throws IOException If failed to read
* @return Subtype string
*/
String subtype() throws IOException;
String subtype();

/**
* Optional parameters.
* @return Parameter map
* @throws IOException If failed to read
* Optional parameters names.
* @return unordered case-insentetive set of strings
*/
Map<String, String> params() throws IOException;
Set<String> params();

/**
* Parameter value for name.
* @param name Parameter name, case-insentetive
* @return Optional parameter value if present for the name
*/
Optional<String> param(String name);

/**
* Mime type of string source.
* @return Mime type implementation for string provided
*/
static MimeType of(final CharSequence src) {
return new MimeTypeOfString(src);
}

/**
* Default decorator for mime type.
* @since 2.0
*/
abstract class Wrap implements MimeType {

/**
* Delegate.
*/
private final MimeType origin;

/**
* Wraps origin.
* @param origin Delegate
*/
protected Wrap(final MimeType origin) {
this.origin = origin;
}

@Override
public final String type() {
return this.origin.type();
}

@Override
public String subtype() {
return this.origin.subtype();
}

@Override
public Set<String> params() {
return this.origin.params();
}

@Override
public Optional<String> param(final String name) {
return this.origin.param(name);
}

@Override
public String toString() {
return this.origin.toString();
}
}
}
135 changes: 0 additions & 135 deletions src/main/java/wtf/g4s8/mime/MimeTypeOf.java

This file was deleted.

0 comments on commit b41d291

Please sign in to comment.