You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2016/03/14 22:43:13 UTC
[04/13] wicket git commit: Move LambdaModel to o.a.w.model package.
Move LambdaModel to o.a.w.model package.
There is no need of o.a.w.model.lambda package just for one class
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/dc189168
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/dc189168
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/dc189168
Branch: refs/heads/master
Commit: dc189168f73284cff69054b7d84b8128329ebf71
Parents: f004dd4
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Mar 14 20:49:40 2016 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Mar 14 22:42:55 2016 +0100
----------------------------------------------------------------------
.../org/apache/wicket/model/LambdaModel.java | 94 +++++++++++++++++++
.../apache/wicket/model/lambda/LambdaModel.java | 95 --------------------
.../apache/wicket/model/LambdaModelTest.java | 94 +++++++++++++++++++
.../wicket/model/lambda/LambdaModelTest.java | 93 -------------------
4 files changed, 188 insertions(+), 188 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/dc189168/wicket-core/src/main/java/org/apache/wicket/model/LambdaModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/LambdaModel.java b/wicket-core/src/main/java/org/apache/wicket/model/LambdaModel.java
new file mode 100644
index 0000000..1dbabec
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/model/LambdaModel.java
@@ -0,0 +1,94 @@
+/*
+ * 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;
+
+import java.util.Objects;
+
+import org.apache.wicket.lambda.WicketConsumer;
+import org.apache.wicket.lambda.WicketSupplier;
+import org.apache.wicket.util.lang.Args;
+
+/**
+ * <code>LambdaModel</code> is a basic implementation of an <code>IModel</code>
+ * that uses a serializable {@link java.util.function.Supplier} to get the object
+ * and {@link java.util.function.Consumer} to set it.
+ *
+ * The detach method defaults does nothing.
+ *
+ * @param <T> The type of the Model Object
+ */
+public class LambdaModel<T> implements IModel<T>
+{
+ private static final long serialVersionUID = 1L;
+
+ private final WicketSupplier<T> getter;
+ private final WicketConsumer<T> setter;
+
+ /**
+ * Construct the model, using the given supplier and consumer as
+ * implementation for getObject and setObject.
+ *
+ * @param getter Used for the getObject() method.
+ * @param setter Used for the setObject(T object) method.
+ */
+ public LambdaModel(WicketSupplier<T> getter, WicketConsumer<T> setter)
+ {
+ this.getter = Args.notNull(getter, "getter");
+ this.setter = Args.notNull(setter, "setter");
+ }
+
+ @Override
+ public T getObject()
+ {
+ return getter.get();
+ }
+
+ @Override
+ public void setObject(T t)
+ {
+ setter.accept(t);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return org.apache.wicket.util.lang.Objects.hashCode(getter, setter);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ final LambdaModel<?> other = (LambdaModel<?>) obj;
+ if (!Objects.equals(this.getter, other.getter))
+ {
+ return false;
+ }
+ if (!Objects.equals(this.setter, other.setter))
+ {
+ return false;
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/dc189168/wicket-core/src/main/java/org/apache/wicket/model/lambda/LambdaModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/lambda/LambdaModel.java b/wicket-core/src/main/java/org/apache/wicket/model/lambda/LambdaModel.java
deleted file mode 100644
index a925278..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/model/lambda/LambdaModel.java
+++ /dev/null
@@ -1,95 +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.WicketConsumer;
-import org.apache.wicket.lambda.WicketSupplier;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.util.lang.Args;
-
-/**
- * <code>LambdaModel</code> is a basic implementation of an <code>IModel</code>
- * that uses a serializable {@link java.util.function.Supplier} to get the object
- * and {@link java.util.function.Consumer} to set it.
- *
- * The detach method defaults does nothing.
- *
- * @param <T> The type of the Model Object
- */
-public class LambdaModel<T> implements IModel<T>
-{
- private static final long serialVersionUID = 1L;
-
- private final WicketSupplier<T> getter;
- private final WicketConsumer<T> setter;
-
- /**
- * Construct the model, using the given supplier and consumer as
- * implementation for getObject and setObject.
- *
- * @param getter Used for the getObject() method.
- * @param setter Used for the setObject(T object) method.
- */
- public LambdaModel(WicketSupplier<T> getter, WicketConsumer<T> setter)
- {
- this.getter = Args.notNull(getter, "getter");
- this.setter = Args.notNull(setter, "setter");
- }
-
- @Override
- public T getObject()
- {
- return getter.get();
- }
-
- @Override
- public void setObject(T t)
- {
- setter.accept(t);
- }
-
- @Override
- public int hashCode()
- {
- return org.apache.wicket.util.lang.Objects.hashCode(getter, setter);
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- final LambdaModel<?> other = (LambdaModel<?>) obj;
- if (!Objects.equals(this.getter, other.getter))
- {
- return false;
- }
- if (!Objects.equals(this.setter, other.setter))
- {
- return false;
- }
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/dc189168/wicket-core/src/test/java/org/apache/wicket/model/LambdaModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/LambdaModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/LambdaModelTest.java
new file mode 100644
index 0000000..85b096e
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/model/LambdaModelTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.*;
+
+import org.apache.wicket.core.util.lang.WicketObjects;
+import org.apache.wicket.lambda.WicketConsumer;
+import org.apache.wicket.lambda.WicketSupplier;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LambdaModel;
+import org.junit.Test;
+
+/**
+ * Tests for {@link LambdaModel}
+ */
+public class LambdaModelTest
+{
+ @Test
+ public void methodReference()
+ {
+ Person person = new Person();
+ IModel<String> personNameModel = new LambdaModel<>(person::getName, person::setName);
+ check(personNameModel);
+ }
+
+ @Test
+ public void explicitLambdas()
+ {
+ Person person = new Person();
+ IModel<String> personNameModel = new LambdaModel<>(
+ () -> person.getName(),
+ (name) -> person.setName(name));
+ check(personNameModel);
+ }
+
+ @Test
+ public void equality()
+ {
+ Person person = new Person();
+ final WicketSupplier<String> getName = person::getName;
+ final WicketConsumer<String> setName = person::setName;
+ IModel<String> personNameModel1 = new LambdaModel<>(getName, setName);
+ IModel<String> personNameModel2 = new LambdaModel<>(getName, setName);
+ assertEquals(personNameModel1, personNameModel2);
+ }
+
+ @Test
+ public void hashcode()
+ {
+ Person person = new Person();
+ final WicketSupplier<String> getName = person::getName;
+ final WicketConsumer<String> setName = person::setName;
+ IModel<String> personNameModel1 = new LambdaModel<>(getName, setName);
+ IModel<String> personNameModel2 = new LambdaModel<>(getName, setName);
+ assertEquals(personNameModel1.hashCode(), personNameModel2.hashCode());
+ }
+
+ private void check(IModel<String> personNameModel)
+ {
+ assertThat(personNameModel.getObject(), is(nullValue()));
+
+ final String personName = "new name";
+ personNameModel.setObject(personName);
+ assertThat(personNameModel.getObject(), is(personName));
+
+ serialize(personNameModel, personName);
+ }
+
+ private void serialize(IModel<String> personNameModel, String personName)
+ {
+ final IModel<String> clone = WicketObjects.cloneObject(personNameModel);
+ assertThat(clone, is(instanceOf(LambdaModel.class)));
+ assertThat(clone.getObject(), is(personName));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/dc189168/wicket-core/src/test/java/org/apache/wicket/model/lambda/LambdaModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/lambda/LambdaModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/lambda/LambdaModelTest.java
deleted file mode 100644
index a823095..0000000
--- a/wicket-core/src/test/java/org/apache/wicket/model/lambda/LambdaModelTest.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.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.*;
-
-import org.apache.wicket.core.util.lang.WicketObjects;
-import org.apache.wicket.lambda.WicketConsumer;
-import org.apache.wicket.lambda.WicketSupplier;
-import org.apache.wicket.model.IModel;
-import org.junit.Test;
-
-/**
- * Tests for {@link LambdaModel}
- */
-public class LambdaModelTest
-{
- @Test
- public void methodReference()
- {
- Person person = new Person();
- IModel<String> personNameModel = new LambdaModel<>(person::getName, person::setName);
- check(personNameModel);
- }
-
- @Test
- public void explicitLambdas()
- {
- Person person = new Person();
- IModel<String> personNameModel = new LambdaModel<>(
- () -> person.getName(),
- (name) -> person.setName(name));
- check(personNameModel);
- }
-
- @Test
- public void equality()
- {
- Person person = new Person();
- final WicketSupplier<String> getName = person::getName;
- final WicketConsumer<String> setName = person::setName;
- IModel<String> personNameModel1 = new LambdaModel<>(getName, setName);
- IModel<String> personNameModel2 = new LambdaModel<>(getName, setName);
- assertEquals(personNameModel1, personNameModel2);
- }
-
- @Test
- public void hashcode()
- {
- Person person = new Person();
- final WicketSupplier<String> getName = person::getName;
- final WicketConsumer<String> setName = person::setName;
- IModel<String> personNameModel1 = new LambdaModel<>(getName, setName);
- IModel<String> personNameModel2 = new LambdaModel<>(getName, setName);
- assertEquals(personNameModel1.hashCode(), personNameModel2.hashCode());
- }
-
- private void check(IModel<String> personNameModel)
- {
- assertThat(personNameModel.getObject(), is(nullValue()));
-
- final String personName = "new name";
- personNameModel.setObject(personName);
- assertThat(personNameModel.getObject(), is(personName));
-
- serialize(personNameModel, personName);
- }
-
- private void serialize(IModel<String> personNameModel, String personName)
- {
- final IModel<String> clone = WicketObjects.cloneObject(personNameModel);
- assertThat(clone, is(instanceOf(LambdaModel.class)));
- assertThat(clone.getObject(), is(personName));
- }
-
-}