Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better builders syntax.

  • Loading branch information...
commit 93e1a196995bcee411d1881fd821f83ec04ef51d 1 parent b85d470
Andrew Kirilenko iced authored
4 README.md
View
@@ -53,8 +53,8 @@ import io.iron.ironworker.client.builders.TaskOptions;
// specififying some options
TaskEntity t = client.createTask("MyWorker",
- (new Params()).add("param", 13).add("another", "value"),
- (new TaskOptions()).priority(1).delay(60));
+ Params.add("param", 13).add("another", "value"),
+ TaskOptions.priority(1).delay(60));
// alternate params syntax
client.createTask("MyWorker", Params.create("param", 13, "another", "value"));
21 client/src/main/java/io/iron/ironworker/client/Client.java
View
@@ -3,10 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import io.iron.ironworker.client.builders.PaginationOptions;
-import io.iron.ironworker.client.builders.Params;
-import io.iron.ironworker.client.builders.TaskOptions;
-import io.iron.ironworker.client.builders.TaskProgressOptions;
+import io.iron.ironworker.client.builders.*;
import io.iron.ironworker.client.codes.BaseCode;
import io.iron.ironworker.client.entities.CodeEntity;
import io.iron.ironworker.client.entities.CodeRevisionEntity;
@@ -40,7 +37,7 @@ public APIClient getAPI() {
return codesList;
}
- public List<CodeEntity> getCodes(PaginationOptions options) throws APIException {
+ public List<CodeEntity> getCodes(PaginationOptionsObject options) throws APIException {
return getCodes(options.create());
}
@@ -72,7 +69,7 @@ public void deleteCode(String codeId) throws APIException {
return codeRevisionsList;
}
- public List<CodeRevisionEntity> getCodeRevisions(String codeId, PaginationOptions options) throws APIException {
+ public List<CodeRevisionEntity> getCodeRevisions(String codeId, PaginationOptionsObject options) throws APIException {
return getCodeRevisions(codeId, options.create());
}
@@ -104,7 +101,7 @@ public void deleteCode(String codeId) throws APIException {
return tasksList;
}
- public List<TaskEntity> getTasks(PaginationOptions options) throws APIException {
+ public List<TaskEntity> getTasks(PaginationOptionsObject options) throws APIException {
return getTasks(options.create());
}
@@ -127,15 +124,15 @@ public TaskEntity createTask(String codeName, Map<String, Object> params, Map<St
return TaskEntity.fromJsonObject(task);
}
- public TaskEntity createTask(String codeName, Map<String, Object> params, TaskOptions options) throws APIException {
+ public TaskEntity createTask(String codeName, Map<String, Object> params, TaskOptionsObject options) throws APIException {
return createTask(codeName, params, options.create());
}
- public TaskEntity createTask(String codeName, Params params, Map<String, Object> options) throws APIException {
+ public TaskEntity createTask(String codeName, ParamsObject params, Map<String, Object> options) throws APIException {
return createTask(codeName, params.create(), options);
}
- public TaskEntity createTask(String codeName, Params params, TaskOptions options) throws APIException {
+ public TaskEntity createTask(String codeName, ParamsObject params, TaskOptionsObject options) throws APIException {
return createTask(codeName, params.create(), options.create());
}
@@ -143,7 +140,7 @@ public TaskEntity createTask(String codeName, Map<String, Object> params) throws
return createTask(codeName, params, (Map<String, Object>) null);
}
- public TaskEntity createTask(String codeName, Params params) throws APIException {
+ public TaskEntity createTask(String codeName, ParamsObject params) throws APIException {
return createTask(codeName, params.create(), (Map<String, Object>) null);
}
@@ -167,7 +164,7 @@ public void setTaskProgress(String taskId, Map<String, Object> options) throws A
api.tasksSetProgress(taskId, options);
}
- public void setTaskProgress(String taskId, TaskProgressOptions options) throws APIException {
+ public void setTaskProgress(String taskId, TaskProgressOptionsObject options) throws APIException {
api.tasksSetProgress(taskId, options.create());
}
21 client/src/main/java/io/iron/ironworker/client/builders/PaginationOptions.java
View
@@ -4,25 +4,14 @@
import java.util.Map;
public class PaginationOptions {
- private Map<String, Object> options;
-
- public PaginationOptions() {
- options = new HashMap<String, Object>();
+ public static PaginationOptionsObject page(int page) {
+ return (new PaginationOptionsObject()).page(page);
}
- public PaginationOptions page(int page) {
- options.put("page", page);
-
- return this;
- }
-
- public PaginationOptions perPage(int perPage) {
- options.put("perPage", perPage);
-
- return this;
+ public static PaginationOptionsObject perPage(int perPage) {
+ return (new PaginationOptionsObject()).perPage(perPage);
}
- public Map<String, Object> create() {
- return options;
+ protected PaginationOptions() {
}
}
28 client/src/main/java/io/iron/ironworker/client/builders/PaginationOptionsObject.java
View
@@ -0,0 +1,28 @@
+package io.iron.ironworker.client.builders;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class PaginationOptionsObject {
+ private Map<String, Object> options;
+
+ public PaginationOptionsObject() {
+ options = new HashMap<String, Object>();
+ }
+
+ public PaginationOptionsObject page(int page) {
+ options.put("page", page);
+
+ return this;
+ }
+
+ public PaginationOptionsObject perPage(int perPage) {
+ options.put("per_page", perPage);
+
+ return this;
+ }
+
+ public Map<String, Object> create() {
+ return options;
+ }
+}
15 client/src/main/java/io/iron/ironworker/client/builders/Params.java
View
@@ -6,8 +6,6 @@
import java.util.Map;
public class Params {
- private Map<String, Object> params;
-
public static Map<String, Object> create(Object... os) throws APIException {
if (os.length % 2 != 0) {
throw new APIException("Odd params number", null);
@@ -22,17 +20,10 @@
return params;
}
- public Params() {
- params = new HashMap<String, Object>();
+ public static ParamsObject add(String key, Object value) {
+ return (new ParamsObject()).add(key, value);
}
-
- public Params add(String key, Object value) {
- params.put(key, value);
- return this;
- }
-
- public Map<String, Object> create() {
- return params;
+ protected Params() {
}
}
24 client/src/main/java/io/iron/ironworker/client/builders/ParamsObject.java
View
@@ -0,0 +1,24 @@
+package io.iron.ironworker.client.builders;
+
+import io.iron.ironworker.client.APIException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ParamsObject {
+ private Map<String, Object> params;
+
+ public ParamsObject() {
+ params = new HashMap<String, Object>();
+ }
+
+ public ParamsObject add(String key, Object value) {
+ params.put(key, value);
+
+ return this;
+ }
+
+ public Map<String, Object> create() {
+ return params;
+ }
+}
30 client/src/main/java/io/iron/ironworker/client/builders/TaskOptions.java
View
@@ -1,34 +1,18 @@
package io.iron.ironworker.client.builders;
-import java.util.HashMap;
-import java.util.Map;
-
public class TaskOptions {
- private Map<String, Object> options;
-
- public TaskOptions() {
- options = new HashMap<String, Object>();
+ public static TaskOptionsObject priority(int priority) {
+ return (new TaskOptionsObject()).priority(priority);
}
- public TaskOptions priority(int priority) {
- options.put("priority", priority);
-
- return this;
+ public static TaskOptionsObject timeout(int timeout) {
+ return (new TaskOptionsObject()).timeout(timeout);
}
- public TaskOptions timeout(int timeout) {
- options.put("timeout", timeout);
-
- return this;
- }
-
- public TaskOptions delay(int delay) {
- options.put("delay", delay);
-
- return this;
+ public static TaskOptionsObject delay(int delay) {
+ return (new TaskOptionsObject()).delay(delay);
}
- public Map<String, Object> create() {
- return options;
+ protected TaskOptions() {
}
}
34 client/src/main/java/io/iron/ironworker/client/builders/TaskOptionsObject.java
View
@@ -0,0 +1,34 @@
+package io.iron.ironworker.client.builders;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TaskOptionsObject {
+ private Map<String, Object> options;
+
+ public TaskOptionsObject() {
+ options = new HashMap<String, Object>();
+ }
+
+ public TaskOptionsObject priority(int priority) {
+ options.put("priority", priority);
+
+ return this;
+ }
+
+ public TaskOptionsObject timeout(int timeout) {
+ options.put("timeout", timeout);
+
+ return this;
+ }
+
+ public TaskOptionsObject delay(int delay) {
+ options.put("delay", delay);
+
+ return this;
+ }
+
+ public Map<String, Object> create() {
+ return options;
+ }
+}
24 client/src/main/java/io/iron/ironworker/client/builders/TaskProgressOptions.java
View
@@ -1,28 +1,14 @@
package io.iron.ironworker.client.builders;
-import java.util.HashMap;
-import java.util.Map;
-
public class TaskProgressOptions {
- private Map<String, Object> options;
-
- public TaskProgressOptions() {
- options = new HashMap<String, Object>();
- }
-
- public TaskProgressOptions percent(int percent) {
- options.put("percent", percent);
-
- return this;
+ public static TaskProgressOptionsObject percent(int percent) {
+ return (new TaskProgressOptionsObject()).percent(percent);
}
- public TaskProgressOptions msg(String msg) {
- options.put("msg", msg);
-
- return this;
+ public static TaskProgressOptionsObject msg(String msg) {
+ return (new TaskProgressOptionsObject()).msg(msg);
}
- public Map<String, Object> create() {
- return options;
+ protected TaskProgressOptions() {
}
}
28 client/src/main/java/io/iron/ironworker/client/builders/TaskProgressOptionsObject.java
View
@@ -0,0 +1,28 @@
+package io.iron.ironworker.client.builders;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TaskProgressOptionsObject {
+ private Map<String, Object> options;
+
+ public TaskProgressOptionsObject() {
+ options = new HashMap<String, Object>();
+ }
+
+ public TaskProgressOptionsObject percent(int percent) {
+ options.put("percent", percent);
+
+ return this;
+ }
+
+ public TaskProgressOptionsObject msg(String msg) {
+ options.put("msg", msg);
+
+ return this;
+ }
+
+ public Map<String, Object> create() {
+ return options;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.