From 750550e6df3cf8c9013f7fa455218b8d3847e181 Mon Sep 17 00:00:00 2001 From: "pabs@pablotron.org" Date: Thu, 18 Dec 2014 15:10:23 -0500 Subject: add java implementation --- java/pablotron/luigi/actions/Action.java | 12 ++++++++ java/pablotron/luigi/actions/FilterAction.java | 41 ++++++++++++++++++++++++++ java/pablotron/luigi/actions/TextAction.java | 22 ++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 java/pablotron/luigi/actions/Action.java create mode 100644 java/pablotron/luigi/actions/FilterAction.java create mode 100644 java/pablotron/luigi/actions/TextAction.java (limited to 'java/pablotron/luigi/actions') diff --git a/java/pablotron/luigi/actions/Action.java b/java/pablotron/luigi/actions/Action.java new file mode 100644 index 0000000..010622a --- /dev/null +++ b/java/pablotron/luigi/actions/Action.java @@ -0,0 +1,12 @@ +package pablotron.luigi.actions; + +import java.util.Map; +import pablotron.luigi.Filter; +import pablotron.luigi.LuigiError; + +public interface Action { + public String run( + Map filters, + Map args + ) throws LuigiError; +}; diff --git a/java/pablotron/luigi/actions/FilterAction.java b/java/pablotron/luigi/actions/FilterAction.java new file mode 100644 index 0000000..b69923b --- /dev/null +++ b/java/pablotron/luigi/actions/FilterAction.java @@ -0,0 +1,41 @@ +package pablotron.luigi.actions; + +import java.util.Map; +import pablotron.luigi.actions.Action; +import pablotron.luigi.FilterReference; +import pablotron.luigi.Filter; +import pablotron.luigi.LuigiError; + +public final class FilterAction implements Action { + private final String key; + private final FilterReference filters[]; + + public FilterAction(final String key, final FilterReference filters[]) { + this.key = key; + this.filters = filters; + } + + public String run( + Map filters, + Map args + ) throws LuigiError { + // check for key + if (!args.containsKey(key)) + throw new LuigiError("unknown key: " + key); + + // reduce value to result + String r = args.get(key); + for (int i = 0, l = this.filters.length; i < l; i++) { + // get/check filter + Filter.Handler f = filters.get(this.filters[i].name); + if (f == null) + throw new LuigiError("unknown filter: " + this.filters[i].name); + + // run filter + r = f.filter(r, this.filters[i].args, args); + } + + // return result + return r; + } +}; diff --git a/java/pablotron/luigi/actions/TextAction.java b/java/pablotron/luigi/actions/TextAction.java new file mode 100644 index 0000000..3024f23 --- /dev/null +++ b/java/pablotron/luigi/actions/TextAction.java @@ -0,0 +1,22 @@ +package pablotron.luigi.actions; + +import java.util.Map; +import pablotron.luigi.actions.Action; +import pablotron.luigi.Filter; +import pablotron.luigi.LuigiError; + +public final class TextAction implements Action { + private final String text; + + public TextAction(final String text) { + this.text = text; + } + + public String run( + Map filters, + Map args + ) throws LuigiError { + return this.text; + } +}; + -- cgit v1.2.3