Repository: wicket
Updated Branches:
  refs/heads/static-factories-for-lambdas 547ed161d -> 733d0abe0


Remove SupplierCachingModel.

Model.loadableDetachable(Supplier) is the replacement


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

Branch: refs/heads/static-factories-for-lambdas
Commit: 733d0abe0a67c4637d77480d09e813d9f6fdc691
Parents: 547ed16
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Mon Mar 14 14:18:10 2016 +0100
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Mon Mar 14 14:18:10 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/wicket/model/Model.java     | 29 +++---
 .../model/lambda/SupplierCachingModel.java      | 80 -----------------
 .../model/lambda/SupplierCachingModelTest.java  | 93 --------------------
 3 files changed, 11 insertions(+), 191 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/733d0abe/wicket-core/src/main/java/org/apache/wicket/model/Model.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/Model.java 
b/wicket-core/src/main/java/org/apache/wicket/model/Model.java
index 97c4882..4658c3c 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/Model.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/Model.java
@@ -27,8 +27,6 @@ import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.lambda.WicketConsumer;
 import org.apache.wicket.lambda.WicketSupplier;
 import org.apache.wicket.model.lambda.LambdaModel;
-import org.apache.wicket.model.lambda.SupplierCachingModel;
-import org.apache.wicket.model.lambda.SupplierModel;
 import org.apache.wicket.model.util.CollectionModel;
 import org.apache.wicket.model.util.ListModel;
 import org.apache.wicket.model.util.MapModel;
@@ -181,33 +179,28 @@ public class Model<T extends Serializable> implements 
IObjectClassAwareModel<T>
         * @param <T>
         * @return Model that contains <code>object</code>
         */
-       public static <T> IModel<T> ofLambdas(WicketSupplier<T> getter, 
WicketConsumer<T> setter)
+       public static <T> IModel<T> of(WicketSupplier<T> getter, 
WicketConsumer<T> setter)
        {
                return new LambdaModel<>(getter, setter);
        }
 
        /**
         * Factory methods for Model which uses type inference to make code 
shorter. Equivalent to
-        * <code>new SupplierModel<TypeOfObject>(getter)</code>.
+        * <code>new LoadableDetachableModel<TypeOfObject>(getter)</code>.
         *
         * @param <T>
         * @return Model that contains <code>object</code>
         */
-       public static <T> IModel<T> readOnly(WicketSupplier<T> getter)
+       public static <T> IModel<T> loadableDetachable(WicketSupplier<T> getter)
        {
-               return new SupplierModel<>(getter);
-       }
-
-       /**
-        * Factory methods for Model which uses type inference to make code 
shorter. Equivalent to
-        * <code>new SupplierCachingModel<TypeOfObject>(getter)</code>.
-        *
-        * @param <T>
-        * @return Model that contains <code>object</code>
-        */
-       public static <T> IModel<T> cachingReadOnly(WicketSupplier<T> getter)
-       {
-               return new SupplierCachingModel<>(getter);
+               return new LoadableDetachableModel<T>()
+               {
+                       @Override
+                       protected T load()
+                       {
+                               return getter.get();
+                       }
+               };
        }
 
        /**

http://git-wip-us.apache.org/repos/asf/wicket/blob/733d0abe/wicket-core/src/main/java/org/apache/wicket/model/lambda/SupplierCachingModel.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/model/lambda/SupplierCachingModel.java
 
b/wicket-core/src/main/java/org/apache/wicket/model/lambda/SupplierCachingModel.java
deleted file mode 100644
index 9e16832..0000000
--- 
a/wicket-core/src/main/java/org/apache/wicket/model/lambda/SupplierCachingModel.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.util.Objects;
-
-import org.apache.wicket.lambda.WicketSupplier;
-import org.apache.wicket.model.LoadableDetachableModel;
-import org.apache.wicket.util.lang.Args;
-
-/**
- * A {@link LoadableDetachableModel caching} model that gets its value from a 
{@link java.util.function.Supplier}.
- *
- * @param <T>
- *            - type of the model object
- */
-public class SupplierCachingModel<T> extends LoadableDetachableModel<T>
-{
-       /**
-        * Supplies the model object.
-        */
-       private final WicketSupplier<T> getter;
-
-       /**
-        * Constructor.
-        *
-        * @param getter
-        *              The getter of the model object
-        */
-       public SupplierCachingModel(WicketSupplier<T> getter)
-       {
-               this.getter = Args.notNull(getter, "getter");
-       }
-
-       @Override
-       protected final T load()
-       {
-               return getter.get();
-       }
-
-
-       @Override
-       public int hashCode()
-       {
-               return org.apache.wicket.util.lang.Objects.hashCode(getter);
-       }
-
-       @Override
-       public boolean equals(Object obj)
-       {
-               if (obj == null)
-               {
-                       return false;
-               }
-               if (getClass() != obj.getClass())
-               {
-                       return false;
-               }
-               final SupplierCachingModel<?> other = (SupplierCachingModel<?>) 
obj;
-               if (!Objects.equals(this.getter, other.getter))
-               {
-                       return false;
-               }
-               return true;
-       }
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/733d0abe/wicket-core/src/test/java/org/apache/wicket/model/lambda/SupplierCachingModelTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/model/lambda/SupplierCachingModelTest.java
 
b/wicket-core/src/test/java/org/apache/wicket/model/lambda/SupplierCachingModelTest.java
deleted file mode 100644
index 88bfadf..0000000
--- 
a/wicket-core/src/test/java/org/apache/wicket/model/lambda/SupplierCachingModelTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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 static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import org.apache.wicket.core.util.lang.WicketObjects;
-import org.apache.wicket.lambda.WicketSupplier;
-import org.apache.wicket.model.IModel;
-import org.junit.Test;
-
-/**
- * Tests for {@link SupplierCachingModel}
- */
-public class SupplierCachingModelTest
-{
-       @Test
-       public void caching()
-       {
-               // given
-               Person person = mock(Person.class);
-               when(person.getName()).thenReturn("The person's name");
-               IModel<String> personNameModel = new 
SupplierCachingModel<>(person::getName);
-
-               // when
-
-               // once
-               personNameModel.getObject();
-               personNameModel.getObject();
-
-               personNameModel.detach();
-               // twice
-               personNameModel.getObject();
-               personNameModel.getObject();
-               personNameModel.getObject();
-
-               // then
-               verify(person, times(2)).getName();
-       }
-
-       @Test
-       public void serialize()
-       {
-               Person person = new Person();
-               final String personName = "The person's name";
-               person.setName(personName);
-               final WicketSupplier<String> getName = person::getName;
-               IModel<String> personNameModel = new 
SupplierCachingModel<>(getName);
-
-               final IModel<String> clone = 
WicketObjects.cloneObject(personNameModel);
-               assertThat(clone.getObject(), is(personName));
-       }
-
-       @Test
-       public void equality()
-       {
-               Person person = new Person();
-               final WicketSupplier<String> getName = person::getName;
-               IModel<String> personNameModel1 = new 
SupplierCachingModel<>(getName);
-               IModel<String> personNameModel2 = new 
SupplierCachingModel<>(getName);
-               assertEquals(personNameModel1, personNameModel2);
-       }
-
-       @Test
-       public void hashcode()
-       {
-               Person person = new Person();
-               final WicketSupplier<String> getName = person::getName;
-               IModel<String> personNameModel1 = new 
SupplierCachingModel<>(getName);
-               IModel<String> personNameModel2 = new 
SupplierCachingModel<>(getName);
-               assertEquals(personNameModel1.hashCode(), 
personNameModel2.hashCode());
-       }
-}

Reply via email to