[wicket] 02/02: WICKET-6886 LambdaChoiceRenderer with unit tests

2021-05-21 Thread svenmeier
This is an automated email from the ASF dual-hosted git repository.

svenmeier pushed a commit to branch wicket-8.x
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit bf24867bd61ae3fb4ecd083d74ae736a113f0f07
Author: Roland Kurucz 
AuthorDate: Fri May 21 22:04:04 2021 +0200

WICKET-6886 LambdaChoiceRenderer with unit tests
---
 .../markup/html/form/LambdaChoiceRenderer.java | 131 +
 .../markup/html/form/LambdaChoiceRendererTest.java |  90 ++
 2 files changed, 221 insertions(+)

diff --git 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/LambdaChoiceRenderer.java
 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/LambdaChoiceRenderer.java
new file mode 100644
index 000..79070fa
--- /dev/null
+++ 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/LambdaChoiceRenderer.java
@@ -0,0 +1,131 @@
+/*
+ * 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.markup.html.form;
+
+import org.danekja.java.util.function.serializable.SerializableFunction;
+
+/**
+ * Renders one choice. Separates the 'id' values used for internal 
representation from 'display
+ * values' which are the values shown to the user of components that use this 
renderer.
+ * 
+ * Usage:
+ *
+ * 
+ * new DropDownChoice("users", new 
Model(selectedUser), listOfUsers,
+ * new LambdaChoiceRenderer(User::getName))
+ * 
+ * 
+ * creates a DropDownChoice of users and the display value will be looked up 
by function
+ * (User::getName) and the id the index of the object in the ListOfUsers
+ * 
+ * 
+ *
+ * 
+ * new DropDownChoice("users", new 
Model(selectedUser), listOfUsers,
+ * new LambdaChoiceRenderer(User::getName, User::getId))
+ * 
+ * 
+ * creates a DropDownChoice of users and the display value will be looked up 
by function
+ * (User::getName) and the id will be looked up by the function (User::getId)
+ * 
+ *
+ * @param  The model object type
+ * @author
+ */
+public class LambdaChoiceRenderer implements IChoiceRenderer {
+private static final long serialVersionUID = 1L;
+
+/**
+ * function for getting the display value.
+ */
+private final SerializableFunction displayExpression;
+
+/**
+ * function for getting the id.
+ */
+private final SerializableFunction idExpression;
+
+/**
+ * Constructor.
+ * 
+ * When you use this constructor, the display value will be determined by 
calling
+ * toString() on the list object, and the id will be based on the list 
index. the id value will
+ * be the index
+ */
+public LambdaChoiceRenderer() {
+this(null);
+}
+
+/**
+ * Constructor.
+ * 
+ * When you use this constructor, the display value will be determined by 
executing
+ * the given function on the list object, and the id will be based on the 
list index.
+ * The display value will be calculated by the given function
+ *
+ * @param displayExpression A function to get the display value
+ */
+public LambdaChoiceRenderer(SerializableFunction displayExpression) {
+this(displayExpression, null);
+}
+
+/**
+ * Constructor.
+ * 
+ * When you use this constructor, both the id and the display value will be
+ * determined by executing the given functions on the list object.
+ *
+ * @param displayExpression A function to get the display value
+ * @param idExpression  A function to get the id value
+ */
+public LambdaChoiceRenderer(SerializableFunction displayExpression, 
SerializableFunction idExpression) {
+this.displayExpression = displayExpression;
+this.idExpression = idExpression;
+}
+
+@Override
+public Object getDisplayValue(T object) {
+Object returnValue = object;
+if ((displayExpression != null) && (object != null)) {
+returnValue = displayExpression.apply(object);
+}
+
+if (returnValue == null) {
+return "";
+}
+
+return returnValue;
+}
+
+@Override
+public String getIdValue(T object, int index) {
+if (idExpression == null) {
+return I

[wicket] 02/02: WICKET-6886 LambdaChoiceRenderer with unit tests

2021-05-21 Thread svenmeier
This is an automated email from the ASF dual-hosted git repository.

svenmeier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit 6a930ee1fa7e1b657a5703c11b86ee51685a9e30
Author: Roland Kurucz 
AuthorDate: Fri May 21 22:04:04 2021 +0200

WICKET-6886 LambdaChoiceRenderer with unit tests
---
 .../markup/html/form/LambdaChoiceRenderer.java | 131 +
 .../markup/html/form/LambdaChoiceRendererTest.java |  90 ++
 2 files changed, 221 insertions(+)

diff --git 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/LambdaChoiceRenderer.java
 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/LambdaChoiceRenderer.java
new file mode 100644
index 000..79070fa
--- /dev/null
+++ 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/LambdaChoiceRenderer.java
@@ -0,0 +1,131 @@
+/*
+ * 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.markup.html.form;
+
+import org.danekja.java.util.function.serializable.SerializableFunction;
+
+/**
+ * Renders one choice. Separates the 'id' values used for internal 
representation from 'display
+ * values' which are the values shown to the user of components that use this 
renderer.
+ * 
+ * Usage:
+ *
+ * 
+ * new DropDownChoice("users", new 
Model(selectedUser), listOfUsers,
+ * new LambdaChoiceRenderer(User::getName))
+ * 
+ * 
+ * creates a DropDownChoice of users and the display value will be looked up 
by function
+ * (User::getName) and the id the index of the object in the ListOfUsers
+ * 
+ * 
+ *
+ * 
+ * new DropDownChoice("users", new 
Model(selectedUser), listOfUsers,
+ * new LambdaChoiceRenderer(User::getName, User::getId))
+ * 
+ * 
+ * creates a DropDownChoice of users and the display value will be looked up 
by function
+ * (User::getName) and the id will be looked up by the function (User::getId)
+ * 
+ *
+ * @param  The model object type
+ * @author
+ */
+public class LambdaChoiceRenderer implements IChoiceRenderer {
+private static final long serialVersionUID = 1L;
+
+/**
+ * function for getting the display value.
+ */
+private final SerializableFunction displayExpression;
+
+/**
+ * function for getting the id.
+ */
+private final SerializableFunction idExpression;
+
+/**
+ * Constructor.
+ * 
+ * When you use this constructor, the display value will be determined by 
calling
+ * toString() on the list object, and the id will be based on the list 
index. the id value will
+ * be the index
+ */
+public LambdaChoiceRenderer() {
+this(null);
+}
+
+/**
+ * Constructor.
+ * 
+ * When you use this constructor, the display value will be determined by 
executing
+ * the given function on the list object, and the id will be based on the 
list index.
+ * The display value will be calculated by the given function
+ *
+ * @param displayExpression A function to get the display value
+ */
+public LambdaChoiceRenderer(SerializableFunction displayExpression) {
+this(displayExpression, null);
+}
+
+/**
+ * Constructor.
+ * 
+ * When you use this constructor, both the id and the display value will be
+ * determined by executing the given functions on the list object.
+ *
+ * @param displayExpression A function to get the display value
+ * @param idExpression  A function to get the id value
+ */
+public LambdaChoiceRenderer(SerializableFunction displayExpression, 
SerializableFunction idExpression) {
+this.displayExpression = displayExpression;
+this.idExpression = idExpression;
+}
+
+@Override
+public Object getDisplayValue(T object) {
+Object returnValue = object;
+if ((displayExpression != null) && (object != null)) {
+returnValue = displayExpression.apply(object);
+}
+
+if (returnValue == null) {
+return "";
+}
+
+return returnValue;
+}
+
+@Override
+public String getIdValue(T object, int index) {
+if (idExpression == null) {
+return Integ

[wicket] 02/02: WICKET-6886 LambdaChoiceRenderer with unit tests

2021-05-21 Thread svenmeier
This is an automated email from the ASF dual-hosted git repository.

svenmeier pushed a commit to branch wicket-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit bf4a90185fb8be2ceecfaeb3fa1003c166fe7761
Author: Roland Kurucz 
AuthorDate: Fri May 21 22:04:04 2021 +0200

WICKET-6886 LambdaChoiceRenderer with unit tests
---
 .../markup/html/form/LambdaChoiceRenderer.java | 131 +
 .../markup/html/form/LambdaChoiceRendererTest.java |  90 ++
 2 files changed, 221 insertions(+)

diff --git 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/LambdaChoiceRenderer.java
 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/LambdaChoiceRenderer.java
new file mode 100644
index 000..79070fa
--- /dev/null
+++ 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/LambdaChoiceRenderer.java
@@ -0,0 +1,131 @@
+/*
+ * 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.markup.html.form;
+
+import org.danekja.java.util.function.serializable.SerializableFunction;
+
+/**
+ * Renders one choice. Separates the 'id' values used for internal 
representation from 'display
+ * values' which are the values shown to the user of components that use this 
renderer.
+ * 
+ * Usage:
+ *
+ * 
+ * new DropDownChoice("users", new 
Model(selectedUser), listOfUsers,
+ * new LambdaChoiceRenderer(User::getName))
+ * 
+ * 
+ * creates a DropDownChoice of users and the display value will be looked up 
by function
+ * (User::getName) and the id the index of the object in the ListOfUsers
+ * 
+ * 
+ *
+ * 
+ * new DropDownChoice("users", new 
Model(selectedUser), listOfUsers,
+ * new LambdaChoiceRenderer(User::getName, User::getId))
+ * 
+ * 
+ * creates a DropDownChoice of users and the display value will be looked up 
by function
+ * (User::getName) and the id will be looked up by the function (User::getId)
+ * 
+ *
+ * @param  The model object type
+ * @author
+ */
+public class LambdaChoiceRenderer implements IChoiceRenderer {
+private static final long serialVersionUID = 1L;
+
+/**
+ * function for getting the display value.
+ */
+private final SerializableFunction displayExpression;
+
+/**
+ * function for getting the id.
+ */
+private final SerializableFunction idExpression;
+
+/**
+ * Constructor.
+ * 
+ * When you use this constructor, the display value will be determined by 
calling
+ * toString() on the list object, and the id will be based on the list 
index. the id value will
+ * be the index
+ */
+public LambdaChoiceRenderer() {
+this(null);
+}
+
+/**
+ * Constructor.
+ * 
+ * When you use this constructor, the display value will be determined by 
executing
+ * the given function on the list object, and the id will be based on the 
list index.
+ * The display value will be calculated by the given function
+ *
+ * @param displayExpression A function to get the display value
+ */
+public LambdaChoiceRenderer(SerializableFunction displayExpression) {
+this(displayExpression, null);
+}
+
+/**
+ * Constructor.
+ * 
+ * When you use this constructor, both the id and the display value will be
+ * determined by executing the given functions on the list object.
+ *
+ * @param displayExpression A function to get the display value
+ * @param idExpression  A function to get the id value
+ */
+public LambdaChoiceRenderer(SerializableFunction displayExpression, 
SerializableFunction idExpression) {
+this.displayExpression = displayExpression;
+this.idExpression = idExpression;
+}
+
+@Override
+public Object getDisplayValue(T object) {
+Object returnValue = object;
+if ((displayExpression != null) && (object != null)) {
+returnValue = displayExpression.apply(object);
+}
+
+if (returnValue == null) {
+return "";
+}
+
+return returnValue;
+}
+
+@Override
+public String getIdValue(T object, int index) {
+if (idExpression == null) {
+return I