runtime: remove Iterables and its last usages
Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/516f0056 Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/516f0056 Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/516f0056 Branch: refs/heads/develop Commit: 516f0056cca650f91e987aa8c60d190eaaf27266 Parents: df8636b Author: Paul Merlin <[email protected]> Authored: Fri Dec 9 00:21:23 2016 +0100 Committer: Paul Merlin <[email protected]> Committed: Fri Dec 9 00:21:23 2016 +0100 ---------------------------------------------------------------------- .../org/apache/zest/functional/Iterables.java | 59 -------------------- .../apache/zest/functional/IterablesTest.java | 50 ----------------- .../association/ManyAssociationInstance.java | 5 +- .../composite/FunctionStateResolver.java | 10 ++-- 4 files changed, 9 insertions(+), 115 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-java/blob/516f0056/core/functional/src/main/java/org/apache/zest/functional/Iterables.java ---------------------------------------------------------------------- diff --git a/core/functional/src/main/java/org/apache/zest/functional/Iterables.java b/core/functional/src/main/java/org/apache/zest/functional/Iterables.java deleted file mode 100644 index 685cf69..0000000 --- a/core/functional/src/main/java/org/apache/zest/functional/Iterables.java +++ /dev/null @@ -1,59 +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.zest.functional; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * Utility methods for working with Iterables. See test for examples of how to use. - */ -@Deprecated -public final class Iterables -{ - public static long count( Iterable<?> iterable ) - { - long c = 0; - for( Object anIterable : iterable ) - { - c++; - } - return c; - } - - public static <T> List<T> toList( Iterable<T> iterable ) - { - return addAll( new ArrayList<>(), iterable ); - } - - private static <T, C extends Collection<T>> C addAll( C collection, Iterable<? extends T> iterable ) - { - for( T item : iterable ) - { - collection.add( item ); - } - return collection; - } - - private Iterables() - { - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/516f0056/core/functional/src/test/java/org/apache/zest/functional/IterablesTest.java ---------------------------------------------------------------------- diff --git a/core/functional/src/test/java/org/apache/zest/functional/IterablesTest.java b/core/functional/src/test/java/org/apache/zest/functional/IterablesTest.java deleted file mode 100644 index db307d8..0000000 --- a/core/functional/src/test/java/org/apache/zest/functional/IterablesTest.java +++ /dev/null @@ -1,50 +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.zest.functional; - -import java.util.Arrays; -import java.util.List; -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -/** - * Test of Iterables utility methods - */ -public class IterablesTest -{ - private List<String> numbers = Arrays.asList( "1", "2", "3" ); - private Iterable<Long> numberLongs = Arrays.asList( 1L, 2L, 3L ); - - @Test - public void testAddAll() - { - List<String> strings = Iterables.toList( numbers ); - assertThat( strings.toString(), equalTo( "[1, 2, 3]" ) ); - assertThat( Iterables.toList( numberLongs ).toString(), equalTo( "[1, 2, 3]" ) ); - } - - @Test - public void testCount() - { - assertThat( Iterables.count( numbers ), equalTo( 3L ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/516f0056/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationInstance.java index 848f7b8..1d21029 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationInstance.java @@ -26,13 +26,14 @@ import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.function.BiFunction; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import org.apache.zest.api.association.AssociationDescriptor; import org.apache.zest.api.association.ManyAssociation; import org.apache.zest.api.association.ManyAssociationWrapper; import org.apache.zest.api.entity.EntityReference; import org.apache.zest.api.identity.HasIdentity; import org.apache.zest.api.util.NullArgumentException; -import org.apache.zest.functional.Iterables; import org.apache.zest.spi.entity.ManyAssociationState; /** @@ -124,7 +125,7 @@ public class ManyAssociationInstance<T> @Override public Iterable<EntityReference> references() { - return Iterables.toList( manyAssociationState ); + return StreamSupport.stream( manyAssociationState.spliterator(), false ).collect( Collectors.toList() ); } @Override http://git-wip-us.apache.org/repos/asf/zest-java/blob/516f0056/core/runtime/src/main/java/org/apache/zest/runtime/composite/FunctionStateResolver.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/FunctionStateResolver.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/FunctionStateResolver.java index a2b35c1..73bc4a8 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/FunctionStateResolver.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/FunctionStateResolver.java @@ -25,14 +25,14 @@ import java.util.function.Function; import org.apache.zest.api.association.AssociationDescriptor; import org.apache.zest.api.entity.EntityReference; import org.apache.zest.api.property.PropertyDescriptor; -import org.apache.zest.functional.Iterables; -import org.apache.zest.runtime.association.ManyAssociationModel; -import org.apache.zest.runtime.association.NamedAssociationModel; import org.apache.zest.runtime.entity.EntityModel; import org.apache.zest.spi.entity.EntityState; import org.apache.zest.spi.entity.ManyAssociationState; import org.apache.zest.spi.entity.NamedAssociationState; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; + /** * Function based StateResolver. */ @@ -70,7 +70,9 @@ public class FunctionStateResolver @Override public List<EntityReference> getManyAssociationState( AssociationDescriptor associationDescriptor ) { - return Iterables.toList( manyAssociationFunction.apply( associationDescriptor ) ); + // FIXME Do not shallow copy here + return stream( manyAssociationFunction.apply( associationDescriptor ).spliterator(), false ) + .collect( toList() ); } @Override
