aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject svn commit: r1808316 - in /aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional: OSGi.java internal/JustOSGiImpl.java
Date Thu, 14 Sep 2017 07:24:49 GMT
Author: csierra
Date: Thu Sep 14 07:24:49 2017
New Revision: 1808316

URL: http://svn.apache.org/viewvc?rev=1808316&view=rev
Log:
Allow just to be lazy

Modified:
    aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
    aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/JustOSGiImpl.java

Modified: aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
URL: http://svn.apache.org/viewvc/aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java?rev=1808316&r1=1808315&r2=1808316&view=diff
==============================================================================
--- aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
(original)
+++ aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
Thu Sep 14 07:24:49 2017
@@ -48,6 +48,7 @@ import java.util.Map;
 import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.function.Predicate;
+import java.util.function.Supplier;
 
 /**
  * @author Carlos Sierra Andrés
@@ -93,6 +94,10 @@ public interface OSGi<T> extends OSGiRun
 		return new JustOSGiImpl<>(s);
 	}
 
+	static <S> OSGi<S> just(Supplier<S> s) {
+		return new JustOSGiImpl<>(s);
+	}
+
 	static <S> OSGi<S> nothing() {
 		return new NothingOSGiImpl<>();
 	}

Modified: aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/JustOSGiImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/JustOSGiImpl.java?rev=1808316&r1=1808315&r2=1808316&view=diff
==============================================================================
--- aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/JustOSGiImpl.java
(original)
+++ aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/JustOSGiImpl.java
Thu Sep 14 07:24:49 2017
@@ -26,47 +26,44 @@ import java.util.IdentityHashMap;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Consumer;
 import java.util.function.Function;
+import java.util.function.Supplier;
 
 /**
  * @author Carlos Sierra Andrés
  */
 public class JustOSGiImpl<T> extends OSGiImpl<T> {
 
-	private T _t;
+	private Supplier<T> _t;
 
-	public JustOSGiImpl(T t) {
+	public JustOSGiImpl(Supplier<T> t) {
 		super(((bundleContext) -> {
 
 			Pipe<Tuple<T>, Tuple<T>> added = Pipe.create();
 
-			Consumer<Tuple<T>> source = added.getSource();
-
 			Pipe<Tuple<T>, Tuple<T>> removed = Pipe.create();
 
-			Consumer<Tuple<T>> removedSource = removed.getSource();
-
-			Tuple<T> tuple = Tuple.create(t);
+			Tuple<T> tuple = Tuple.create(t.get());
 
 			return new OSGiResultImpl<>(
 				added, removed,
-				() -> source.accept(tuple),
-				() -> removedSource.accept(tuple));
+				() -> added.getSource().accept(tuple),
+				() -> removed.getSource().accept(tuple));
 		}));
 
 		_t = t;
 	}
 
+	public JustOSGiImpl(T t) {
+		this(() -> t);
+	}
+
 	@Override
 	public <S> OSGiImpl<S> flatMap(Function<? super T, OSGi<? extends S>>
fun) {
 		return new OSGiImpl<>(bundleContext -> {
 			Pipe<Tuple<S>, Tuple<S>> added = Pipe.create();
 
-			Consumer<Tuple<S>> addedSource = added.getSource();
-
 			Pipe<Tuple<S>, Tuple<S>> removed = Pipe.create();
 
-			Consumer<Tuple<S>> removedSource = removed.getSource();
-
 			AtomicReference<OSGiResult<? extends S>> atomicReference =
 				new AtomicReference<>(null);
 			AtomicReference<Tuple<S>> tupleReference =
@@ -75,7 +72,7 @@ public class JustOSGiImpl<T> extends OSG
 			return new OSGiResultImpl<>(
 				added, removed,
 				() -> {
-					OSGi<? extends S> next = fun.apply(_t);
+					OSGi<? extends S> next = fun.apply(_t.get());
 
 					atomicReference.set(
 						next.run(
@@ -85,7 +82,7 @@ public class JustOSGiImpl<T> extends OSG
 
 								tupleReference.set(tuple);
 
-								addedSource.accept(tuple);
+								added.getSource().accept(tuple);
 							}));
 
 				},
@@ -93,7 +90,7 @@ public class JustOSGiImpl<T> extends OSG
 					Tuple<S> s = tupleReference.get();
 
 					if (s != null) {
-						removedSource.accept(s);
+						removed.getSource().accept(s);
 					}
 
 					OSGiResult<? extends S> osGiResult = atomicReference.get();



Mime
View raw message