Repository: wicket
Updated Branches:
  refs/heads/master 075d8371e -> 22a421a05


WICKET-6396 added default isPresent to IModel


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

Branch: refs/heads/master
Commit: 22a421a05afa53e3311ae05b0c1076047e43e344
Parents: 075d837
Author: Sven Meier <svenme...@apache.org>
Authored: Fri Aug 18 23:44:38 2017 +0200
Committer: Sven Meier <svenme...@apache.org>
Committed: Fri Aug 18 23:44:38 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/wicket/model/IModel.java    | 21 ++++++++++++++++++++
 .../org/apache/wicket/model/IModelTest.java     | 12 +++++++++++
 2 files changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/22a421a0/wicket-core/src/main/java/org/apache/wicket/model/IModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/IModel.java 
b/wicket-core/src/main/java/org/apache/wicket/model/IModel.java
index d33d061..c9db790 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/IModel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/IModel.java
@@ -348,6 +348,27 @@ public interface IModel<T> extends IDetachable
                        }
                };
        }
+       
+       /**
+        * Returns a IModel, returning whether the contained object is non-null.
+        *
+        * @return a new IModel
+        */
+       default IModel<Boolean> isPresent() {
+               return new IModel<Boolean>() {
+                       @Override
+                       public Boolean getObject()
+                       {
+                               return IModel.this.getObject() != null;
+                       }
+
+                       @Override
+                       public void detach()
+                       {
+                               IModel.this.detach();
+                       }
+               };
+       }
 
        /**
         * Suppresses generics warning when casting model types.

http://git-wip-us.apache.org/repos/asf/wicket/blob/22a421a0/wicket-core/src/test/java/org/apache/wicket/model/IModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/IModelTest.java 
b/wicket-core/src/test/java/org/apache/wicket/model/IModelTest.java
index c2efe29..8f7b585 100644
--- a/wicket-core/src/test/java/org/apache/wicket/model/IModelTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/model/IModelTest.java
@@ -176,6 +176,18 @@ public class IModelTest extends Assert
        }
 
        @Test
+       public void isPresent()
+       {
+               assertThat(Model.of(person).isPresent().getObject(), 
is(equalTo(true)));
+       }
+
+       @Test
+       public void isPresentNot()
+       {
+               assertThat(Model.of((Person)null).isPresent().getObject(), 
is(equalTo(false)));
+       }
+
+       @Test
        public void serializableMethodReference()
        {
                Person p = new Person();

Reply via email to