You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wayang.apache.org by rp...@apache.org on 2021/09/29 10:12:28 UTC

[incubator-wayang] 02/03: [WAYANG-28] Tagger Function templates

This is an automated email from the ASF dual-hosted git repository.

rpardomeza pushed a commit to branch WAYANG-28
in repository https://gitbox.apache.org/repos/asf/incubator-wayang.git

commit 72afabc5f9cfa7619a1903a0edf553137c5052c2
Author: rodrigopardomeza <ro...@gmail.com>
AuthorDate: Wed Sep 29 12:11:39 2021 +0200

    [WAYANG-28] Tagger Function templates
---
 .../hackit/core/tagger/wrapper/FlatmapWrapperHackit.java | 15 ++++++++-------
 .../core/tagger/wrapper/FunctionWrapperHackit.java       | 15 ++++++++-------
 .../core/tagger/wrapper/PredicateWrapperHackit.java      | 16 ++++++++--------
 .../tagger/wrapper/template/FlatMapTemplateSystem.java   |  8 ++++++++
 .../tagger/wrapper/template/FunctionTemplateSystem.java  |  6 ++++++
 5 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/FlatmapWrapperHackit.java b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/FlatmapWrapperHackit.java
index c0e612d..ab84d42 100644
--- a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/FlatmapWrapperHackit.java
+++ b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/FlatmapWrapperHackit.java
@@ -18,6 +18,7 @@
 package org.apache.wayang.plugin.hackit.core.tagger.wrapper;
 
 import org.apache.wayang.plugin.hackit.core.tagger.HackitTagger;
+import org.apache.wayang.plugin.hackit.core.tagger.wrapper.template.FlatMapTemplateSystem;
 import org.apache.wayang.plugin.hackit.core.tuple.HackitTuple;
 
 import java.util.Iterator;
@@ -34,26 +35,26 @@ import java.util.function.Function;
  */
 public class FlatmapWrapperHackit<IDType, I, O>
         extends HackitTagger
-        implements Function<HackitTuple<IDType, I>, Iterator<HackitTuple<IDType, O>>> {
+        implements FlatMapTemplateSystem<HackitTuple<IDType, I>, HackitTuple<IDType, O>> {
 
     /**
      * Original function that will transform the data
      */
-    private Function<I, Iterator<O>> function;
+    private FlatMapTemplateSystem<I, O> function;
 
     /**
      * Default Construct
      *
      * @param function is the function that will be Wrapped by the {@link FlatmapWrapperHackit}
      */
-    public FlatmapWrapperHackit(Function<I, Iterator<O>> function ) {
+    public FlatmapWrapperHackit(FlatMapTemplateSystem<I, O> function) {
         this.function = function;
     }
 
     @Override
-    public Iterator<HackitTuple<IDType, O>> apply(HackitTuple<IDType, I> idTypeIHackitTuple) {
-        this.preTaggingTuple(idTypeIHackitTuple);
-        Iterator<O> result = this.function.apply(idTypeIHackitTuple.getValue());
-        return this.postTaggingTuple(idTypeIHackitTuple, result);
+    public Iterator<HackitTuple<IDType, O>> execute(HackitTuple<IDType, I> input) {
+        this.preTaggingTuple(input);
+        Iterator<O> result = this.function.execute(input.getValue());
+        return this.postTaggingTuple(input, result);
     }
 }
diff --git a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/FunctionWrapperHackit.java b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/FunctionWrapperHackit.java
index beae3b5..8fa681f 100644
--- a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/FunctionWrapperHackit.java
+++ b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/FunctionWrapperHackit.java
@@ -18,6 +18,7 @@
 package org.apache.wayang.plugin.hackit.core.tagger.wrapper;
 
 import org.apache.wayang.plugin.hackit.core.tagger.HackitTagger;
+import org.apache.wayang.plugin.hackit.core.tagger.wrapper.template.FunctionTemplateSystem;
 import org.apache.wayang.plugin.hackit.core.tuple.HackitTuple;
 
 import java.util.function.Function;
@@ -33,26 +34,26 @@ import java.util.function.Function;
  */
 public class FunctionWrapperHackit<IDType, I, O>
         extends HackitTagger
-        implements Function<HackitTuple<IDType, I>, HackitTuple<IDType, O>> {
+        implements FunctionTemplateSystem<HackitTuple<IDType, I>, HackitTuple<IDType, O>> {
 
     /**
      * Original function that will transform the data
      */
-    private Function<I, O> function;
+    private FunctionTemplateSystem<I, O> function;
 
     /**
      * Default Constructor
      *
      * @param function is the function that will be Wrapped by the {@link FunctionWrapperHackit}
      */
-    public FunctionWrapperHackit(Function<I, O> function) {
+    public FunctionWrapperHackit(FunctionTemplateSystem<I, O> function) {
         this.function = function;
     }
 
     @Override
-    public HackitTuple<IDType, O> apply(HackitTuple<IDType, I> idTypeIHackitTuple) {
-        this.preTaggingTuple(idTypeIHackitTuple);
-        O result = this.function.apply(idTypeIHackitTuple.getValue());
-        return this.postTaggingTuple(idTypeIHackitTuple, result);
+    public HackitTuple<IDType, O> execute(HackitTuple<IDType, I> input) {
+        this.preTaggingTuple(input);
+        O result = this.function.execute(input.getValue());
+        return this.postTaggingTuple(input, result);
     }
 }
diff --git a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/PredicateWrapperHackit.java b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/PredicateWrapperHackit.java
index c7d0728..840644c 100644
--- a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/PredicateWrapperHackit.java
+++ b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/PredicateWrapperHackit.java
@@ -18,6 +18,7 @@
 package org.apache.wayang.plugin.hackit.core.tagger.wrapper;
 
 import org.apache.wayang.plugin.hackit.core.tagger.HackitTagger;
+import org.apache.wayang.plugin.hackit.core.tagger.wrapper.template.FunctionTemplateSystem;
 import org.apache.wayang.plugin.hackit.core.tuple.HackitTuple;
 
 import java.util.function.Predicate;
@@ -32,28 +33,27 @@ import java.util.function.Predicate;
  */
 public class PredicateWrapperHackit<IDType, I>
         extends HackitTagger
-        implements Predicate<HackitTuple<IDType, I>> {
+        implements FunctionTemplateSystem<HackitTuple<IDType, I>, Boolean> {
 
     /**
      * Original predicate that will evaluate the data to give a True or False value
      */
-    private Predicate<I> function;
+    private FunctionTemplateSystem<I, Boolean> function;
 
     /**
      * Default Construct
      *
      * @param function is the predicate that will be Wrapped by the {@link PredicateWrapperHackit}
      */
-    public PredicateWrapperHackit(Predicate<I> function) {
+    public PredicateWrapperHackit(FunctionTemplateSystem<I, Boolean> function) {
         this.function = function;
     }
 
-
     @Override
-    public boolean test(HackitTuple<IDType, I> idTypeIHackitTuple) {
-        this.preTaggingTuple(idTypeIHackitTuple);
-        Boolean result = this.function.test(idTypeIHackitTuple.getValue());
-        this.postTaggingTuple(idTypeIHackitTuple);
+    public Boolean execute(HackitTuple<IDType, I> input) {
+        this.preTaggingTuple(input);
+        Boolean result = this.function.execute(input.getValue());
+        this.postTaggingTuple(input);
         return result;
     }
 }
diff --git a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/template/FlatMapTemplateSystem.java b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/template/FlatMapTemplateSystem.java
new file mode 100644
index 0000000..8f3b6fc
--- /dev/null
+++ b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/template/FlatMapTemplateSystem.java
@@ -0,0 +1,8 @@
+package org.apache.wayang.plugin.hackit.core.tagger.wrapper.template;
+
+import java.util.Iterator;
+
+public interface FlatMapTemplateSystem<I, O> {
+
+    public Iterator<O> execute(I input);
+}
diff --git a/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/template/FunctionTemplateSystem.java b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/template/FunctionTemplateSystem.java
new file mode 100644
index 0000000..f19f8cc
--- /dev/null
+++ b/wayang-plugins/wayang-hackit/wayang-hackit-core/src/main/java/org/apache/wayang/plugin/hackit/core/tagger/wrapper/template/FunctionTemplateSystem.java
@@ -0,0 +1,6 @@
+package org.apache.wayang.plugin.hackit.core.tagger.wrapper.template;
+
+public interface FunctionTemplateSystem<I, O> {
+
+    public O execute(I input);
+}