Skip to content

Solution #1 - Java6 compatible introducing an enum for response type #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ java/build
java/.classpath
java/.project
java/.settings
*.class
*.class
java/.gradle
3 changes: 2 additions & 1 deletion java/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = 1.7
sourceCompatibility = 1.6
group = 'it.tug'
version = '0.1'

Expand Down
6 changes: 3 additions & 3 deletions java/src/main/java/it/tug/Main/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public Formatter(Service service) {

public String doTheJob(String theInput) {
String response = service.askForPermission();
switch (response) {
case "FAIL":
switch (ResponseType.getType(response)) {
case FAIL:
return "error";
case "OK":
case OK:
return String.format("%s%s", theInput, theInput);
default:
return null;
Expand Down
13 changes: 13 additions & 0 deletions java/src/main/java/it/tug/Main/ResponseType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package it.tug.Main;

public enum ResponseType {
FAIL, OK, OTHER;

static ResponseType getType(String type) {
try {
return valueOf(type);
} catch (IllegalArgumentException e) {
return OTHER;
}
}
}