You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/01/23 10:57:43 UTC
[isis] 06/10: ISIS-1841 Nullable, Closure,
IterableExtensions removed (after refactoring, no longer needed),
tests removed or adapted
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch ISIS-1846_internal_utils
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 8b19f8ab51b50f18b4e7b7c953a2a040ee1f67d1
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Jan 23 10:19:57 2018 +0100
ISIS-1841 Nullable, Closure, IterableExtensions removed
(after refactoring, no longer needed), tests removed or adapted
---
.../isis/applib/internal/base/_NullSafe.java | 18 ++++++--
.../org/apache/isis/core/commons/lang/Closure.java | 32 --------------
.../isis/core/commons/lang/IterableExtensions.java | 39 -----------------
.../apache/isis/core/commons/lang/Nullable.java | 49 ----------------------
.../core/metamodel/facets/MethodFinderUtils.java | 4 +-
.../DomainObjectAnnotationFacetFactory.java | 3 +-
.../recreatable/RecreatableObjectFacetFactory.java | 2 +-
.../commons/lang/IterableExtensionsTest_fold.java | 45 --------------------
.../metamodel/facets/MethodFinderUtilsTest.java | 4 +-
.../wicket/model/models/EntityCollectionModel.java | 44 ++++++++++---------
.../models/LowestCommonSuperclassClosureTest.java | 13 +++---
11 files changed, 48 insertions(+), 205 deletions(-)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/base/_NullSafe.java b/core/applib/src/main/java/org/apache/isis/applib/internal/base/_NullSafe.java
index 985c19b..ae9b277 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/internal/base/_NullSafe.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/base/_NullSafe.java
@@ -49,7 +49,7 @@ public final class _NullSafe {
* If {@code array} is {@code array} returns the empty stream,
* otherwise returns a stream of the array's elements.
* @param array
- * @return
+ * @return non-null stream object
*/
public static <T> Stream<T> stream(final T[] array) {
return array!=null ? Stream.of(array) : Stream.empty();
@@ -59,17 +59,27 @@ public final class _NullSafe {
* If {@code collection} is {@code null} returns the empty stream,
* otherwise returns a stream of the collection's elements.
* @param collection
- * @return
+ * @return non-null stream object
*/
public static <T> Stream<T> stream(final Collection<T> coll){
return coll!=null ? coll.stream() : Stream.empty();
}
/**
+ * If {@code iterable} is {@code null} returns the empty stream,
+ * otherwise returns a stream of the iterable's elements.
+ * @param iterable
+ * @return non-null stream object
+ */
+ public static <T> Stream<T> stream(final Iterable<T> iterable){
+ return iterable!=null ? stream(iterable.iterator()) : Stream.empty();
+ }
+
+ /**
* If {@code iterator} is {@code null} returns the empty stream,
* otherwise returns a stream of the iterator's elements.
* @param collection
- * @return
+ * @return non-null stream object
*/
public static <T> Stream<T> stream(final Iterator<T> iterator){
return iterator!=null
@@ -77,7 +87,7 @@ public final class _NullSafe {
: Stream.empty();
}
- // [ahuber] not public, since one time use only!
+ // [ahuber] not public, since one time use of iterator only!
private static <T> Iterable<T> toIterable(final Iterator<T> iterator){
return ()->iterator;
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/commons/lang/Closure.java b/core/metamodel/src/main/java/org/apache/isis/core/commons/lang/Closure.java
deleted file mode 100644
index c0d9f8e..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/commons/lang/Closure.java
+++ /dev/null
@@ -1,32 +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.isis.core.commons.lang;
-
-
-/**
- * @see http://cyrille.martraire.com/2011/03/thinking-functional-programming-with-map-and-fold-in-your-everyday-java/
- */
-public interface Closure<T> {
-
- public T execute(T value);
-
-}
-
-
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/commons/lang/IterableExtensions.java b/core/metamodel/src/main/java/org/apache/isis/core/commons/lang/IterableExtensions.java
deleted file mode 100644
index 68ec84f..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/commons/lang/IterableExtensions.java
+++ /dev/null
@@ -1,39 +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.isis.core.commons.lang;
-
-
-/**
- * @see http://cyrille.martraire.com/2011/03/thinking-functional-programming-with-map-and-fold-in-your-everyday-java/
- */
-public final class IterableExtensions {
-
- private IterableExtensions() {
- }
-
- public final static <T> T fold(Iterable<T> list, Closure<T> closure) {
- T result = null;
- for (T t : list) {
- result = closure.execute(t);
- }
- return result;
- }
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/commons/lang/Nullable.java b/core/metamodel/src/main/java/org/apache/isis/core/commons/lang/Nullable.java
deleted file mode 100644
index f06d014..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/commons/lang/Nullable.java
+++ /dev/null
@@ -1,49 +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.isis.core.commons.lang;
-
-/**
- *
- * @deprecated use {@link java.util.Optional} instead
- *
- * @param <T>
- */
-@Deprecated
-public class Nullable<T> {
-
- public static <T> Nullable<T> some(T t) {
- return new Nullable<>(t);
- }
-
- public static <T> Nullable<T> none() {
- return new Nullable<T>(null);
- }
-
- private final T t;
-
- private Nullable(final T t) {
- this.t = t;
- }
-
- public boolean isPresent() { return t != null; }
- public T value() {
- return t;
- }
-
-}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/MethodFinderUtils.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/MethodFinderUtils.java
index 2109995..cc86662 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/MethodFinderUtils.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/MethodFinderUtils.java
@@ -202,7 +202,7 @@ public final class MethodFinderUtils {
public static Method findAnnotatedMethod(
final Object pojo,
final Class<? extends Annotation> annotationClass,
- final Map<Class, Optional<Method>> methods) {
+ final Map<Class<?>, Optional<Method>> methods) {
final Class<?> clz = pojo.getClass();
Optional<Method> nullableMethod = methods.get(clz);
@@ -215,7 +215,7 @@ public final class MethodFinderUtils {
private static Optional<Method> search(
final Class<?> clz,
final Class<? extends Annotation> annotationClass,
- final Map<Class, Optional<Method>> postConstructMethods) {
+ final Map<Class<?>, Optional<Method>> postConstructMethods) {
final Method[] methods = clz.getMethods();
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java
index 3408427..e952337 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java
@@ -513,6 +513,7 @@ public class DomainObjectAnnotationFacetFactory extends FacetFactoryAbstract
@Override
public void setServicesInjector(final ServicesInjector servicesInjector) {
super.setServicesInjector(servicesInjector);
+ //TODO [ahuber] unused because of side effects ?
IsisConfiguration configuration = getConfiguration();
this.persistenceSessionServiceInternal = servicesInjector.getPersistenceSessionServiceInternal();
@@ -522,7 +523,7 @@ public class DomainObjectAnnotationFacetFactory extends FacetFactoryAbstract
// //////////////////////////////////////
- private final Map<Class, Optional<Method>> postConstructMethods = Maps.newHashMap();
+ private final Map<Class<?>, Optional<Method>> postConstructMethods = Maps.newHashMap();
public Method postConstructMethodFor(final Object pojo) {
return MethodFinderUtils.findAnnotatedMethod(pojo, PostConstruct.class, postConstructMethods);
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
index ea70a9a..867911a 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/recreatable/RecreatableObjectFacetFactory.java
@@ -125,7 +125,7 @@ public class RecreatableObjectFacetFactory extends FacetFactoryAbstract
// //////////////////////////////////////
- private final Map<Class, Optional<Method>> postConstructMethods = Maps.newHashMap();
+ private final Map<Class<?>, Optional<Method>> postConstructMethods = Maps.newHashMap();
public Method postConstructMethodFor(final Object pojo) {
return MethodFinderUtils.findAnnotatedMethod(pojo, PostConstruct.class, postConstructMethods);
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/IterableExtensionsTest_fold.java b/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/IterableExtensionsTest_fold.java
deleted file mode 100644
index b65b972..0000000
--- a/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/IterableExtensionsTest_fold.java
+++ /dev/null
@@ -1,45 +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.isis.core.commons.lang;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Arrays;
-
-import org.junit.Test;
-
-public class IterableExtensionsTest_fold {
-
- @Test
- public void happyCase() throws Exception {
-
- class SummingClosure implements Closure<Double> {
- private double sum = 0;
-
- public Double execute(Double amount) {
- sum += amount; // apply '+=' operator
- return sum; // return current accumulated value
- }
- }
-
- SummingClosure closure = new SummingClosure();
-
- Double result = IterableExtensions.fold(Arrays.asList(new Double[] { 99., 127., 35. }), closure);
- assertEquals(261.0, result, 0.000000001);
- }
-
-}
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/MethodFinderUtilsTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/MethodFinderUtilsTest.java
index 044339d..d6075d2 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/MethodFinderUtilsTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/MethodFinderUtilsTest.java
@@ -44,7 +44,7 @@ public class MethodFinderUtilsTest {
@Test
public void whenExists() throws Exception {
- final Map<Class, Optional<Method>> cache = Maps.newHashMap();
+ final Map<Class<?>, Optional<Method>> cache = Maps.newHashMap();
final Method method = MethodFinderUtils.findAnnotatedMethod(new WithPostConstruct(), PostConstruct.class, cache);
assertThat(method, is(not(nullValue())));
@@ -57,7 +57,7 @@ public class MethodFinderUtilsTest {
@Test
public void whenDoesNotExist() throws Exception {
- final Map<Class, Optional<Method>> cache = Maps.newHashMap();
+ final Map<Class<?>, Optional<Method>> cache = Maps.newHashMap();
final Method method = MethodFinderUtils.findAnnotatedMethod(new NoPostConstruct(), PostConstruct.class, cache);
assertThat(method, is(nullValue()));
diff --git a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
index 923980a..e86b7af 100644
--- a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
+++ b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
@@ -26,19 +26,10 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
-import com.google.common.base.Function;
-import com.google.common.base.Predicates;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-import org.apache.wicket.Component;
-
+import org.apache.isis.applib.internal.base._NullSafe;
import org.apache.isis.applib.layout.component.CollectionLayoutData;
import org.apache.isis.core.commons.factory.InstanceUtil;
import org.apache.isis.core.commons.lang.ClassUtil;
-import org.apache.isis.core.commons.lang.Closure;
-import org.apache.isis.core.commons.lang.IterableExtensions;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager.ConcurrencyChecking;
import org.apache.isis.core.metamodel.adapter.oid.RootOid;
@@ -57,6 +48,12 @@ import org.apache.isis.viewer.wicket.model.links.LinkAndLabel;
import org.apache.isis.viewer.wicket.model.links.LinksProvider;
import org.apache.isis.viewer.wicket.model.mementos.CollectionMemento;
import org.apache.isis.viewer.wicket.model.mementos.ObjectAdapterMemento;
+import org.apache.wicket.Component;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
/**
* Model representing a collection of entities, either {@link Type#STANDALONE
@@ -202,10 +199,10 @@ public class EntityCollectionModel extends ModelAbstract<List<ObjectAdapter>> im
public abstract int getCount(EntityCollectionModel entityCollectionModel);
}
- static class LowestCommonSuperclassClosure implements Closure<Class<?>>{
+ static class LowestCommonSuperclassFinder {
private Class<?> common;
- @Override
- public Class<?> execute(final Class<?> value) {
+
+ public void collect(final Class<?> value) {
if(common == null) {
common = value;
} else {
@@ -215,11 +212,15 @@ public class EntityCollectionModel extends ModelAbstract<List<ObjectAdapter>> im
}
common = current;
}
- return common;
}
Class<?> getLowestCommonSuperclass() {
return common;
}
+ void searchThrough(Iterable<?> list) {
+ _NullSafe.stream(list)
+ .map(Object::getClass)
+ .forEach(this::collect);
+ }
}
/**
@@ -239,15 +240,12 @@ public class EntityCollectionModel extends ModelAbstract<List<ObjectAdapter>> im
// dynamically determine the spec of the elements
// (ie so a List<Object> can be rendered according to the runtime type of its elements,
// rather than the compile-time type
- final LowestCommonSuperclassClosure closure = new LowestCommonSuperclassClosure();
- Function<Object, Class<?>> function = new Function<Object, Class<?>>(){
- @Override
- public Class<?> apply(Object obj) {
- return obj.getClass();
- }
- };
- IterableExtensions.fold(Iterables.transform(pojos, function), closure);
- elementSpec = sessionFactory.getSpecificationLoader().loadSpecification(closure.getLowestCommonSuperclass());
+ final LowestCommonSuperclassFinder finder = new LowestCommonSuperclassFinder();
+
+ finder.searchThrough(pojos);
+
+ elementSpec = sessionFactory.getSpecificationLoader()
+ .loadSpecification(finder.getLowestCommonSuperclass());
} else {
elementSpec = collectionAsAdapter.getElementSpecification();
}
diff --git a/core/viewer-wicket-model/src/test/java/org/apache/isis/viewer/wicket/model/models/LowestCommonSuperclassClosureTest.java b/core/viewer-wicket-model/src/test/java/org/apache/isis/viewer/wicket/model/models/LowestCommonSuperclassClosureTest.java
index da2cb46..523bf37 100644
--- a/core/viewer-wicket-model/src/test/java/org/apache/isis/viewer/wicket/model/models/LowestCommonSuperclassClosureTest.java
+++ b/core/viewer-wicket-model/src/test/java/org/apache/isis/viewer/wicket/model/models/LowestCommonSuperclassClosureTest.java
@@ -23,12 +23,10 @@ import static org.junit.Assert.assertThat;
import java.util.List;
-import com.google.common.collect.Lists;
-
+import org.apache.isis.core.commons.matchers.IsisMatchers;
import org.junit.Test;
-import org.apache.isis.core.commons.lang.IterableExtensions;
-import org.apache.isis.core.commons.matchers.IsisMatchers;
+import com.google.common.collect.Lists;
public class LowestCommonSuperclassClosureTest {
@@ -54,9 +52,10 @@ public class LowestCommonSuperclassClosureTest {
}
private static void assertLowestCommonOfListIs(List<Class<?>> list, Class<?> expected) {
- EntityCollectionModel.LowestCommonSuperclassClosure closure = new EntityCollectionModel.LowestCommonSuperclassClosure();
- IterableExtensions.fold(list, closure);
- assertThat(closure.getLowestCommonSuperclass(), IsisMatchers.classEqualTo(expected));
+ EntityCollectionModel.LowestCommonSuperclassFinder finder =
+ new EntityCollectionModel.LowestCommonSuperclassFinder();
+ finder.searchThrough(list);
+ assertThat(finder.getLowestCommonSuperclass(), IsisMatchers.classEqualTo(expected));
}
private static List<Class<? extends Object>> listOf(Class<?>... classes) {
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.