functional: remove Iterables.map and .filter and their usage
Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/d91227a4 Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/d91227a4 Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/d91227a4 Branch: refs/heads/develop Commit: d91227a47c502aa0150c4c4b5226ad2ddf1493e4 Parents: 2d485e3 Author: Paul Merlin <[email protected]> Authored: Thu Dec 8 19:41:10 2016 +0100 Committer: Paul Merlin <[email protected]> Committed: Thu Dec 8 19:46:33 2016 +0100 ---------------------------------------------------------------------- .../apache/zest/api/query/QueryExpressions.java | 10 +- .../api/query/grammar/ContainsAllPredicate.java | 3 +- .../java/org/apache/zest/api/OperatorsTest.java | 4 +- .../org/apache/zest/functional/Iterables.java | 227 +------------------ .../apache/zest/functional/IterablesTest.java | 33 --- .../association/NamedAssociationInstance.java | 65 +----- .../runtime/bootstrap/ModuleAssemblyImpl.java | 53 +++-- .../zest/runtime/structure/ModuleInstance.java | 4 +- .../zest/test/indexing/NameableAssert.java | 6 +- .../AbstractCollectionSerializationTest.java | 22 +- .../apache/zest/index/rdf/ContainsAllTest.java | 3 +- .../support/skeletons/AbstractSQLIndexing.java | 16 +- .../shiro/domain/permissions/RoleFactory.java | 3 +- 13 files changed, 85 insertions(+), 364 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/core/api/src/main/java/org/apache/zest/api/query/QueryExpressions.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/query/QueryExpressions.java b/core/api/src/main/java/org/apache/zest/api/query/QueryExpressions.java index 0ef35c3..17137d1 100644 --- a/core/api/src/main/java/org/apache/zest/api/query/QueryExpressions.java +++ b/core/api/src/main/java/org/apache/zest/api/query/QueryExpressions.java @@ -24,9 +24,12 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; +import java.util.List; import java.util.function.Predicate; import org.apache.zest.api.association.Association; import org.apache.zest.api.association.GenericAssociationInfo; @@ -67,7 +70,6 @@ import org.apache.zest.api.query.grammar.Variable; import org.apache.zest.api.util.NullArgumentException; import static org.apache.zest.api.identity.HasIdentity.IDENTITY_METHOD; -import static org.apache.zest.functional.Iterables.prepend; /** * Static factory methods for query expressions and operators. @@ -293,7 +295,11 @@ public final class QueryExpressions Predicate<Composite>... optionalRight ) { - return new AndPredicate( prepend( left, prepend( right, Arrays.asList( optionalRight ) ) ) ); + List<Predicate<Composite>> predicates = new ArrayList<>( 2 + optionalRight.length ); + predicates.add( left ); + predicates.add( right ); + Collections.addAll( predicates, optionalRight ); + return new AndPredicate( predicates ); } /** http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/core/api/src/main/java/org/apache/zest/api/query/grammar/ContainsAllPredicate.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/query/grammar/ContainsAllPredicate.java b/core/api/src/main/java/org/apache/zest/api/query/grammar/ContainsAllPredicate.java index 429aa73..0bed02b 100644 --- a/core/api/src/main/java/org/apache/zest/api/query/grammar/ContainsAllPredicate.java +++ b/core/api/src/main/java/org/apache/zest/api/query/grammar/ContainsAllPredicate.java @@ -21,7 +21,6 @@ package org.apache.zest.api.query.grammar; import java.util.Collection; import org.apache.zest.api.composite.Composite; -import org.apache.zest.functional.Iterables; /** * Contains All Specification. @@ -74,6 +73,6 @@ public class ContainsAllPredicate<T> @Override public String toString() { - return collectionProperty + " contains " + Iterables.toList( valueCollection ); + return collectionProperty + " contains " + valueCollection; } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java b/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java index 99ccd5a..86151a0 100644 --- a/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java +++ b/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java @@ -19,6 +19,7 @@ */ package org.apache.zest.api; +import java.util.Collections; import java.util.function.Predicate; import org.apache.zest.api.activation.ActivationException; import org.apache.zest.api.composite.Composite; @@ -36,7 +37,6 @@ import org.apache.zest.bootstrap.AssemblyException; import org.apache.zest.bootstrap.ModuleAssembly; import org.apache.zest.bootstrap.SingletonAssembler; import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; -import org.apache.zest.functional.Iterables; import org.apache.zest.test.EntityTestAssembler; import org.junit.Assert; import org.junit.Test; @@ -78,7 +78,7 @@ public class OperatorsTest uow.complete(); uow = uowf.newUnitOfWork(); - Iterable<TestEntity> entities = Iterables.iterable( testEntity = uow.get( testEntity ) ); + Iterable<TestEntity> entities = Collections.singleton( testEntity = uow.get( testEntity ) ); QueryBuilder<TestEntity> builder = assembler.module().newQueryBuilder( TestEntity.class ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/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 index 46c26a3..685cf69 100644 --- a/core/functional/src/main/java/org/apache/zest/functional/Iterables.java +++ b/core/functional/src/main/java/org/apache/zest/functional/Iterables.java @@ -20,27 +20,15 @@ package org.apache.zest.functional; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.Iterator; import java.util.List; -import java.util.function.Function; -import java.util.function.Predicate; /** * Utility methods for working with Iterables. See test for examples of how to use. */ +@Deprecated public final class Iterables { - private static <T, C extends Collection<T>> C addAll( C collection, Iterable<? extends T> iterable ) - { - for( T item : iterable ) - { - collection.add( item ); - } - return collection; - } - public static long count( Iterable<?> iterable ) { long c = 0; @@ -51,223 +39,18 @@ public final class Iterables return c; } - @SuppressWarnings( "unchecked" ) - public static <X> Iterable<X> filter( Predicate<? /* super X*/> specification, Iterable<X> i ) - { - return new FilterIterable<>( i, (Predicate<? super X>) specification ); - } - - @SuppressWarnings( "unchecked" ) - public static <FROM, TO> Iterable<TO> map( Function<? /* super FROM */, TO> function, Iterable<FROM> from ) - { - return new MapIterable<>( from, (Function<FROM, TO>) function ); - } - - @SafeVarargs - public static <T> Iterable<T> iterable( T... items ) - { - return Arrays.asList( items ); - } - - public static <T> Iterable<T> prepend( final T item, final Iterable<T> iterable ) - { - return () -> new Iterator<T>() - { - private T first = item; - private Iterator<T> iterator; - - @Override - public boolean hasNext() - { - if( first != null ) - { - return true; - } - else - { - if( iterator == null ) - { - iterator = iterable.iterator(); - } - } - - return iterator.hasNext(); - } - - @Override - public T next() - { - if( first != null ) - { - try - { - return first; - } - finally - { - first = null; - } - } - else - { - return iterator.next(); - } - } - - @Override - public void remove() - { - } - }; - } - public static <T> List<T> toList( Iterable<T> iterable ) { return addAll( new ArrayList<>(), iterable ); } - private static class MapIterable<FROM, TO> - implements Iterable<TO> - { - private final Iterable<FROM> from; - private final Function<? super FROM, TO> function; - - private MapIterable( Iterable<FROM> from, Function<? super FROM, TO> function ) - { - this.from = from; - this.function = function; - } - - @Override - public Iterator<TO> iterator() - { - return new MapIterator<>( from.iterator(), function ); - } - - static class MapIterator<FROM, TO> - implements Iterator<TO> - { - private final Iterator<FROM> fromIterator; - private final Function<? super FROM, TO> function; - - private MapIterator( Iterator<FROM> fromIterator, Function<? super FROM, TO> function ) - { - this.fromIterator = fromIterator; - this.function = function; - } - - @Override - public boolean hasNext() - { - return fromIterator.hasNext(); - } - - @Override - public TO next() - { - FROM from = fromIterator.next(); - return function.apply( from ); - } - - @Override - public void remove() - { - fromIterator.remove(); - } - } - } - - private static class FilterIterable<T> - implements Iterable<T> + private static <T, C extends Collection<T>> C addAll( C collection, Iterable<? extends T> iterable ) { - private final Iterable<T> iterable; - - private final Predicate<? super T> specification; - - private FilterIterable( Iterable<T> iterable, Predicate<? super T> specification ) - { - this.iterable = iterable; - this.specification = specification; - } - - @Override - public Iterator<T> iterator() - { - return new FilterIterator<>( iterable.iterator(), specification ); - } - - private static class FilterIterator<T> - implements Iterator<T> + for( T item : iterable ) { - private final Iterator<T> iterator; - - private final Predicate<? super T> specification; - - private T currentValue; - boolean finished = false; - boolean nextConsumed = true; - - private FilterIterator( Iterator<T> iterator, Predicate<? super T> specification ) - { - this.specification = specification; - this.iterator = iterator; - } - - private boolean moveToNextValid() - { - boolean found = false; - while( !found && iterator.hasNext() ) - { - T currentValue = iterator.next(); - boolean satisfies = specification.test( currentValue ); - - if( satisfies ) - { - found = true; - this.currentValue = currentValue; - nextConsumed = false; - } - } - if( !found ) - { - finished = true; - } - return found; - } - - @Override - public T next() - { - if( !nextConsumed ) - { - nextConsumed = true; - return currentValue; - } - else - { - if( !finished ) - { - if( moveToNextValid() ) - { - nextConsumed = true; - return currentValue; - } - } - } - return null; - } - - @Override - public boolean hasNext() - { - return !finished && ( !nextConsumed || moveToNextValid() ); - } - - @Override - public void remove() - { - } + collection.add( item ); } + return collection; } private Iterables() http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/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 index ffa7d88..db307d8 100644 --- a/core/functional/src/test/java/org/apache/zest/functional/IterablesTest.java +++ b/core/functional/src/test/java/org/apache/zest/functional/IterablesTest.java @@ -20,9 +20,7 @@ package org.apache.zest.functional; import java.util.Arrays; -import java.util.Collection; import java.util.List; -import java.util.function.Function; import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; @@ -49,35 +47,4 @@ public class IterablesTest { assertThat( Iterables.count( numbers ), equalTo( 3L ) ); } - - @Test - public void testMap() - { - assertThat( Iterables.toList( Iterables.map( new Function<String, String>() - { - - public String apply( String s ) - { - return s + s; - } - }, numbers ) ).toString(), equalTo( "[11, 22, 33]" ) ); - - Iterable<List<String>> numberIterable = Iterables.iterable( numbers, numbers, numbers ); - assertThat( Iterables.toList( Iterables.map( new Function<Collection, Integer>() - { - - @Override - public Integer apply( Collection collection ) - { - return collection.size(); - } - }, numberIterable ) ).toString(), equalTo( "[3, 3, 3]" ) ); - } - - @Test - public void testIterableVarArg() - { - assertThat( Iterables.toList( Iterables.iterable( "1", "2", "3" ) ).toString(), - equalTo( "[1, 2, 3]" ) ); - } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationInstance.java index 05c4539..147fcc2 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationInstance.java @@ -20,11 +20,14 @@ package org.apache.zest.runtime.association; import java.lang.reflect.Type; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.function.BiFunction; import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import org.apache.zest.api.association.AssociationDescriptor; import org.apache.zest.api.association.NamedAssociation; import org.apache.zest.api.association.NamedAssociationWrapper; @@ -33,8 +36,6 @@ import org.apache.zest.api.identity.HasIdentity; import org.apache.zest.api.util.NullArgumentException; import org.apache.zest.spi.entity.NamedAssociationState; -import static org.apache.zest.functional.Iterables.map; - public class NamedAssociationInstance<T> extends AbstractAssociationInstance<T> implements NamedAssociation<T> @@ -112,14 +113,9 @@ public class NamedAssociationInstance<T> @Override public Iterable<EntityReference> references() { - return map( new Function<String, EntityReference>() - { - @Override - public EntityReference apply( String name ) - { - return namedAssociationState.get( name ); - } - }, namedAssociationState ); + return StreamSupport.stream( namedAssociationState.spliterator(), false ) + .map( namedAssociationState::get ) + .collect( Collectors.toList() ); } @Override @@ -130,51 +126,10 @@ public class NamedAssociationInstance<T> public Iterable<Map.Entry<String, EntityReference>> getEntityReferences() { - return map( new Function<String, Map.Entry<String, EntityReference>>() - { - @Override - public Map.Entry<String, EntityReference> apply( final String key ) - { - final EntityReference value = namedAssociationState.get( key ); - return new Map.Entry<String, EntityReference>() - { - @Override - public String getKey() - { - return key; - } - - @Override - public EntityReference getValue() - { - return value; - } - - @Override - public EntityReference setValue( EntityReference value ) - { - throw new UnsupportedOperationException( "Immutable Map" ); - } - - @Override - public boolean equals( Object o ) - { - if( o instanceof Map.Entry ) - { - Map.Entry other = (Map.Entry) o; - return key.equals( other.getKey() ); - } - return false; - } - - @Override - public int hashCode() - { - return 997 * key.hashCode() + 981813497; - } - }; - } - }, namedAssociationState ); + return Collections.unmodifiableMap( + StreamSupport.stream( namedAssociationState.spliterator(), false ) + .collect( Collectors.toMap( Function.identity(), namedAssociationState::get ) ) + ).entrySet(); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java index 1dea286..11b2f05 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java @@ -22,7 +22,6 @@ package org.apache.zest.runtime.bootstrap; import java.lang.reflect.UndeclaredThrowableException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -32,7 +31,6 @@ import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.stream.StreamSupport; import org.apache.zest.api.activation.Activator; import org.apache.zest.api.common.MetaInfo; import org.apache.zest.api.common.Visibility; @@ -43,7 +41,6 @@ import org.apache.zest.api.identity.Identity; import org.apache.zest.api.identity.IdentityGenerator; import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.service.DuplicateServiceIdentityException; -import org.apache.zest.api.service.ServiceImporter; import org.apache.zest.api.structure.Module; import org.apache.zest.api.type.HasTypes; import org.apache.zest.api.type.MatchTypeSpecification; @@ -88,8 +85,9 @@ import org.apache.zest.runtime.structure.ModuleModel; import org.apache.zest.runtime.value.ValueModel; import org.apache.zest.runtime.value.ValuesModel; +import static java.util.Arrays.asList; +import static java.util.Collections.singleton; import static java.util.stream.Collectors.toList; -import static org.apache.zest.functional.Iterables.iterable; /** * Assembly of a Module. This is where you register all objects, Composites, @@ -166,7 +164,7 @@ final class ModuleAssemblyImpl @SafeVarargs public final ModuleAssembly withActivators(Class<? extends Activator<Module>>... activators) { - this.activators.addAll(Arrays.asList(activators)); + this.activators.addAll( asList( activators ) ); return this; } @@ -458,36 +456,36 @@ final class ModuleAssemblyImpl public <ThrowableType extends Throwable> void visit(AssemblyVisitor<ThrowableType> visitor) throws ThrowableType { - visitor.visitModule(this); + visitor.visitModule( this ); - for (TransientAssemblyImpl compositeDeclaration : transientAssemblies.values()) + for( TransientAssemblyImpl compositeDeclaration : transientAssemblies.values() ) { - visitor.visitComposite(new TransientDeclarationImpl(iterable(compositeDeclaration))); + visitor.visitComposite( new TransientDeclarationImpl( singleton( compositeDeclaration ) ) ); } - for (EntityAssemblyImpl entityDeclaration : entityAssemblies.values()) + for( EntityAssemblyImpl entityDeclaration : entityAssemblies.values() ) { - visitor.visitEntity(new EntityDeclarationImpl(iterable(entityDeclaration))); + visitor.visitEntity( new EntityDeclarationImpl( singleton( entityDeclaration ) ) ); } - for (ObjectAssemblyImpl objectDeclaration : objectAssemblies.values()) + for( ObjectAssemblyImpl objectDeclaration : objectAssemblies.values() ) { - visitor.visitObject(new ObjectDeclarationImpl(iterable(objectDeclaration))); + visitor.visitObject( new ObjectDeclarationImpl( singleton( objectDeclaration ) ) ); } - for (ServiceAssemblyImpl serviceDeclaration : serviceAssemblies) + for( ServiceAssemblyImpl serviceDeclaration : serviceAssemblies ) { - visitor.visitService(new ServiceDeclarationImpl(iterable(serviceDeclaration))); + visitor.visitService( new ServiceDeclarationImpl( singleton( serviceDeclaration ) ) ); } - for (ImportedServiceAssemblyImpl importedServiceDeclaration : importedServiceAssemblies.values()) + for( ImportedServiceAssemblyImpl importedServiceDeclaration : importedServiceAssemblies.values() ) { - visitor.visitImportedService(new ImportedServiceDeclarationImpl(iterable(importedServiceDeclaration))); + visitor.visitImportedService( new ImportedServiceDeclarationImpl( singleton( importedServiceDeclaration ) ) ); } - for (ValueAssemblyImpl valueDeclaration : valueAssemblies.values()) + for( ValueAssemblyImpl valueDeclaration : valueAssemblies.values() ) { - visitor.visitValue(new ValueDeclarationImpl(iterable(valueDeclaration))); + visitor.visitValue( new ValueDeclarationImpl( singleton( valueDeclaration ) ) ); } } @@ -580,15 +578,16 @@ final class ModuleAssemblyImpl identities.add(identity); } - importedServiceModels.stream().filter(importedServiceModel -> - !StreamSupport.stream(objectModels.spliterator(), false) - .anyMatch(model -> model.types().findFirst().get().equals(importedServiceModel.serviceImporter()))) - .forEach(importedServiceModel -> - { - Class<? extends ServiceImporter> serviceFactoryType = importedServiceModel.serviceImporter(); - ObjectModel objectModel = new ObjectModel(moduleModel, serviceFactoryType, Visibility.module, new MetaInfo()); - objectModels.add(objectModel); - }); + importedServiceModels + .stream() + .filter( + importedServiceModel -> + objectModels.stream().noneMatch( model -> model.types().findFirst().get() + .equals( importedServiceModel.serviceImporter() ) ) ) + .forEach( + importedServiceModel -> + objectModels.add( new ObjectModel( moduleModel, importedServiceModel.serviceImporter(), + Visibility.module, new MetaInfo() ) ) ); return moduleModel; } http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/core/runtime/src/main/java/org/apache/zest/runtime/structure/ModuleInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/structure/ModuleInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/structure/ModuleInstance.java index d3461d0..7a8a72d 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/structure/ModuleInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/structure/ModuleInstance.java @@ -92,8 +92,8 @@ import org.apache.zest.spi.entitystore.EntityStore; import org.apache.zest.spi.metrics.MetricsProviderAdapter; import org.apache.zest.spi.module.ModuleSpi; +import static java.util.Arrays.asList; import static java.util.stream.Stream.concat; -import static org.apache.zest.functional.Iterables.iterable; /** * Instance of a Zest Module. Contains the various composites for this Module. @@ -427,7 +427,7 @@ public class ModuleInstance public void activate() throws ActivationException { - activation.activate( model.newActivatorsInstance(), iterable( services, importedServices ) ); + activation.activate( model.newActivatorsInstance(), asList( services, importedServices ) ); } @Override http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/core/testsupport/src/main/java/org/apache/zest/test/indexing/NameableAssert.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/indexing/NameableAssert.java b/core/testsupport/src/main/java/org/apache/zest/test/indexing/NameableAssert.java index 5429ab7..d1487c3 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/indexing/NameableAssert.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/indexing/NameableAssert.java @@ -26,6 +26,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import org.apache.zest.api.entity.EntityReference; import org.apache.zest.api.identity.Identity; import org.apache.zest.test.indexing.model.Nameable; @@ -34,7 +36,6 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNull.notNullValue; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.apache.zest.functional.Iterables.toList; public class NameableAssert { @@ -56,7 +57,8 @@ public class NameableAssert String... expectedNames ) { - final List<EntityReference> references = toList( identitiesIterable ); + final List<EntityReference> references = StreamSupport.stream( identitiesIterable.spliterator(), false ) + .collect( Collectors.toList() ); assertThat( expectedNames.length + " entries(" + expectedNames.length + ", got " + getNames( references ) + ")", references.size(), equalTo( expectedNames.length ) ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractCollectionSerializationTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractCollectionSerializationTest.java b/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractCollectionSerializationTest.java index 15ad941..75a6d03 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractCollectionSerializationTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractCollectionSerializationTest.java @@ -24,6 +24,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -40,7 +41,6 @@ import org.apache.zest.api.value.ValueBuilder; import org.apache.zest.api.value.ValueSerialization; import org.apache.zest.bootstrap.AssemblyException; import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.functional.Iterables; import org.apache.zest.test.AbstractZestTest; import org.junit.Test; @@ -50,7 +50,7 @@ import static org.junit.Assert.assertEquals; /** * Assert that ValueSerialization behaviour on Collections and Maps is correct. */ -// TODO How to assert that given a collection of valuecomposites when serializing and deserializing we have to OOME? +// TODO How to assert that given a collection of valuecomposites when serializing and deserializing we have no OOME? public class AbstractCollectionSerializationTest extends AbstractZestTest { @@ -96,7 +96,7 @@ public class AbstractCollectionSerializationTest public void givenIterableTypeWithByteAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { - String output = valueSerialization.serialize( Iterables.iterable( byteCollection().toArray() ) ); + String output = valueSerialization.serialize( new AdHocIterable<>( byteCollection() ) ); CollectionType collectionType = new CollectionType( List.class, new ValueType( Byte.class ) ); List<Byte> list = valueSerialization.deserialize( module, collectionType, output ); assertEquals( byteCollection(), list ); @@ -414,4 +414,20 @@ public class AbstractCollectionSerializationTest } return builder.newInstance(); } + + private static class AdHocIterable<T> implements Iterable<T> + { + private final Iterable<T> delegate; + + private AdHocIterable( Iterable<T> delegate ) + { + this.delegate = delegate; + } + + @Override + public Iterator<T> iterator() + { + return delegate.iterator(); + } + } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/extensions/indexing-rdf/src/test/java/org/apache/zest/index/rdf/ContainsAllTest.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-rdf/src/test/java/org/apache/zest/index/rdf/ContainsAllTest.java b/extensions/indexing-rdf/src/test/java/org/apache/zest/index/rdf/ContainsAllTest.java index 53dabc1..603d4a4 100644 --- a/extensions/indexing-rdf/src/test/java/org/apache/zest/index/rdf/ContainsAllTest.java +++ b/extensions/indexing-rdf/src/test/java/org/apache/zest/index/rdf/ContainsAllTest.java @@ -36,7 +36,6 @@ import org.apache.zest.api.value.ValueBuilderFactory; import org.apache.zest.api.value.ValueComposite; import org.apache.zest.bootstrap.AssemblyException; import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.functional.Iterables; import org.apache.zest.index.rdf.assembly.RdfNativeSesameStoreAssembler; import org.apache.zest.library.fileconfig.FileConfigurationAssembler; import org.apache.zest.library.fileconfig.FileConfigurationOverride; @@ -314,7 +313,7 @@ public class ContainsAllTest builder = builder.where( QueryExpressions.containsAll( QueryExpressions.templateFor( ExampleEntity.class ).strings(), - Iterables.iterable( strings ) ) ); + Arrays.asList( strings ) ) ); return this.unitOfWorkFactory.currentUnitOfWork().newQuery( builder ).find(); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/extensions/indexing-sql/src/main/java/org/apache/zest/index/sql/support/skeletons/AbstractSQLIndexing.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-sql/src/main/java/org/apache/zest/index/sql/support/skeletons/AbstractSQLIndexing.java b/extensions/indexing-sql/src/main/java/org/apache/zest/index/sql/support/skeletons/AbstractSQLIndexing.java index ed7cbfb..e42d2c5 100644 --- a/extensions/indexing-sql/src/main/java/org/apache/zest/index/sql/support/skeletons/AbstractSQLIndexing.java +++ b/extensions/indexing-sql/src/main/java/org/apache/zest/index/sql/support/skeletons/AbstractSQLIndexing.java @@ -32,7 +32,8 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import javax.sql.DataSource; import org.apache.zest.api.ZestAPI; import org.apache.zest.api.common.QualifiedName; @@ -47,7 +48,6 @@ import org.apache.zest.api.service.ServiceDescriptor; import org.apache.zest.api.structure.Application; import org.apache.zest.api.value.ValueComposite; import org.apache.zest.api.value.ValueDescriptor; -import org.apache.zest.functional.Iterables; import org.apache.zest.index.sql.support.api.SQLIndexing; import org.apache.zest.index.sql.support.common.DBNames; import org.apache.zest.index.sql.support.common.QNameInfo; @@ -172,14 +172,10 @@ public abstract class AbstractSQLIndexing Map<Long, EntityState> statesByPK = new HashMap<>(); Map<Long, Integer> qNamePKs = new HashMap<>(); - Iterable<EntityState> relatedStates = Iterables.filter( new Predicate<EntityState>() - { - @Override - public boolean test( EntityState item ) - { - return item.entityDescriptor().queryable(); - } - }, Iterables.map( SQLCompatEntityStateWrapper.WRAP, changedStates ) ); + Iterable<EntityState> relatedStates = StreamSupport.stream( changedStates.spliterator(), false ) + .filter( state -> state.entityDescriptor().queryable() ) + .map( SQLCompatEntityStateWrapper.WRAP ) + .collect( Collectors.toList() ); for( EntityState eState : relatedStates ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/d91227a4/libraries/shiro-core/src/main/java/org/apache/zest/library/shiro/domain/permissions/RoleFactory.java ---------------------------------------------------------------------- diff --git a/libraries/shiro-core/src/main/java/org/apache/zest/library/shiro/domain/permissions/RoleFactory.java b/libraries/shiro-core/src/main/java/org/apache/zest/library/shiro/domain/permissions/RoleFactory.java index 2de0b6d..9a3cc8d 100644 --- a/libraries/shiro-core/src/main/java/org/apache/zest/library/shiro/domain/permissions/RoleFactory.java +++ b/libraries/shiro-core/src/main/java/org/apache/zest/library/shiro/domain/permissions/RoleFactory.java @@ -26,7 +26,6 @@ import org.apache.zest.api.mixin.Mixins; import org.apache.zest.api.service.ServiceComposite; import org.apache.zest.api.unitofwork.UnitOfWork; import org.apache.zest.api.unitofwork.UnitOfWorkFactory; -import org.apache.zest.functional.Iterables; @Mixins( RoleFactory.Mixin.class ) public interface RoleFactory @@ -57,7 +56,7 @@ public interface RoleFactory EntityBuilder<Role> roleBuilder = uow.newEntityBuilder( Role.class ); Role role = roleBuilder.instance(); role.name().set( name ); - role.permissions().set( Iterables.toList( permissions ) ); + permissions.forEach( p -> role.permissions().get().add( p ) ); return roleBuilder.newInstance(); }
