You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mo...@apache.org on 2015/12/02 09:50:06 UTC

wicket git commit: simplified model constructor

Repository: wicket
Updated Branches:
  refs/heads/lambdas 73ac8c7e6 -> 0c636cf1f


simplified model constructor


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/0c636cf1
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/0c636cf1
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/0c636cf1

Branch: refs/heads/lambdas
Commit: 0c636cf1f210a78abbcb20cc2ff752d86544c46c
Parents: 73ac8c7
Author: Michael Mosmann <mo...@apache.org>
Authored: Wed Dec 2 09:46:57 2015 +0100
Committer: Michael Mosmann <mo...@apache.org>
Committed: Wed Dec 2 09:47:21 2015 +0100

----------------------------------------------------------------------
 .../org/apache/wicket/model/lambda/Models.java  |  6 ++--
 .../wicket/model/lambda/WicketBiConsumer.java   | 31 ++++++++++++++++++++
 .../apache/wicket/model/lambda/ModelsTest.java  |  5 +++-
 3 files changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/0c636cf1/wicket-core/src/main/java/org/apache/wicket/model/lambda/Models.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/lambda/Models.java b/wicket-core/src/main/java/org/apache/wicket/model/lambda/Models.java
index 3f457a5..1114b54 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/lambda/Models.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/lambda/Models.java
@@ -21,7 +21,7 @@ import org.apache.wicket.model.IReadOnlyModel;
 
 public class Models
 {
-	public static <S, T> IModel<T> of(IModel<S> source, WicketFunction<S, WicketConsumer<T>> setter, WicketFunction<S, WicketSupplier<T>> getter) {
+	public static <S, T> IModel<T> of(IModel<S> source, WicketBiConsumer<S, T> setter, WicketFunction<S, T> getter) {
 		return new IModel<T>()	{
 			@Override
 			public void detach()
@@ -32,13 +32,13 @@ public class Models
 			@Override
 			public T getObject()
 			{
-				return getter.apply(source.getObject()).get();
+				return getter.apply(source.getObject());
 			}
 
 			@Override
 			public void setObject(T object)
 			{
-				setter.apply(source.getObject()).accept(object);
+				setter.accept(source.getObject(), object);
 			}
 		};
 	}

http://git-wip-us.apache.org/repos/asf/wicket/blob/0c636cf1/wicket-core/src/main/java/org/apache/wicket/model/lambda/WicketBiConsumer.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/lambda/WicketBiConsumer.java b/wicket-core/src/main/java/org/apache/wicket/model/lambda/WicketBiConsumer.java
new file mode 100644
index 0000000..f7c7b1f
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/model/lambda/WicketBiConsumer.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.model.lambda;
+
+import java.io.Serializable;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+/**
+ * A {@link Serializable} {@link Consumer}.
+ *
+ * @param <T>
+ *            - the type of the input to consume
+ */
+public interface WicketBiConsumer<T,V> extends BiConsumer<T,V>, Serializable
+{
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/0c636cf1/wicket-core/src/test/java/org/apache/wicket/model/lambda/ModelsTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/lambda/ModelsTest.java b/wicket-core/src/test/java/org/apache/wicket/model/lambda/ModelsTest.java
index b77b8c7..241d486 100644
--- a/wicket-core/src/test/java/org/apache/wicket/model/lambda/ModelsTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/model/lambda/ModelsTest.java
@@ -19,6 +19,9 @@ package org.apache.wicket.model.lambda;
 import static org.junit.Assert.*;
 
 import java.io.Serializable;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Function;
 
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;
@@ -30,7 +33,7 @@ public class ModelsTest
 	public void propertyModel() {
 		Foo instance = new Foo();
 		Model<Foo> fooModel = Model.of(instance);
-		IModel<String> nameModel = Models.of(fooModel, (x) -> x::setName, (x) -> x::getName);
+		IModel<String> nameModel = Models.of(fooModel, Foo::setName, Foo::getName);
 		instance.setName("blub");
 		assertEquals("blub", nameModel.getObject());
 		nameModel.setObject("bar");