http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java ---------------------------------------------------------------------- diff --git a/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java b/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java index 77b290d..7a098f1 100644 --- a/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java +++ b/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java @@ -38,13 +38,13 @@ import org.apache.zest.library.logging.trace.records.EntityTraceRecordEntity; import org.apache.zest.library.logging.trace.records.ServiceTraceRecordEntity; import org.apache.zest.library.logging.trace.records.TraceRecord; -import static org.apache.zest.functional.Iterables.first; - public class TraceServiceMixin implements TraceService { - @Structure private UnitOfWorkFactory uowf; - @This private Configuration<TraceServiceConfiguration> configuration; + @Structure + private UnitOfWorkFactory uowf; + @This + private Configuration<TraceServiceConfiguration> configuration; private int counter; private Integer traceLevel; @@ -60,7 +60,14 @@ public class TraceServiceMixin } @Override - public void traceSuccess( Class compositeType, Composite object, Method method, Object[] args, Object result, long entryTime, long durationNano ) + public void traceSuccess( Class compositeType, + Composite object, + Method method, + Object[] args, + Object result, + long entryTime, + long durationNano + ) { UnitOfWork uow = uowf.newUnitOfWork(); try @@ -79,7 +86,14 @@ public class TraceServiceMixin } @Override - public void traceException( Class compositeType, Composite object, Method method, Object[] args, Throwable t, long entryTime, long durationNano ) + public void traceException( Class compositeType, + Composite object, + Method method, + Object[] args, + Throwable t, + long entryTime, + long durationNano + ) { UnitOfWork uow = uowf.newUnitOfWork(); try @@ -97,14 +111,25 @@ public class TraceServiceMixin } } - private void createTraceRecord( UnitOfWork uow, Class compositeType, Composite object, Method method, Object[] args, long entryTime, long durationNano, Throwable exception ) + private void createTraceRecord( UnitOfWork uow, + Class compositeType, + Composite object, + Method method, + Object[] args, + long entryTime, + long durationNano, + Throwable exception + ) { if( object instanceof EntityComposite ) { EntityComposite entity = (EntityComposite) object; String identity = entity.identity().get(); - EntityComposite source = (EntityComposite) uow.get( (Class<?>) first( - ZestAPI.FUNCTION_DESCRIPTOR_FOR.apply( entity ).types() ), identity ); + EntityComposite source = (EntityComposite) uow.get( + ZestAPI.FUNCTION_DESCRIPTOR_FOR.apply( entity ) + .types() + .findFirst() + .orElse( null ), identity ); EntityBuilder<EntityTraceRecordEntity> builder = uow.newEntityBuilder( EntityTraceRecordEntity.class ); EntityTraceRecordEntity state = builder.instance(); setStandardStuff( compositeType, method, args, entryTime, durationNano, state, exception ); @@ -130,7 +155,14 @@ public class TraceServiceMixin } } - private void setStandardStuff( Class compositeType, Method method, Object[] args, long entryTime, long durationNano, TraceRecord state, Throwable exception ) + private void setStandardStuff( Class compositeType, + Method method, + Object[] args, + long entryTime, + long durationNano, + TraceRecord state, + Throwable exception + ) { state.duration().set( durationNano ); state.entryTime().set( entryTime ); @@ -145,9 +177,9 @@ public class TraceServiceMixin { if( args == null ) { - return new ArrayList<String>( 0 ); + return new ArrayList<>( 0 ); } - List<String> result = new ArrayList<String>( args.length ); + List<String> result = new ArrayList<>( args.length ); for( Object arg : args ) { if( arg == null )
http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/logging/src/test/java/org/apache/zest/library/logging/DebuggingTest.java ---------------------------------------------------------------------- diff --git a/libraries/logging/src/test/java/org/apache/zest/library/logging/DebuggingTest.java b/libraries/logging/src/test/java/org/apache/zest/library/logging/DebuggingTest.java index 052de1e..a424aba 100644 --- a/libraries/logging/src/test/java/org/apache/zest/library/logging/DebuggingTest.java +++ b/libraries/logging/src/test/java/org/apache/zest/library/logging/DebuggingTest.java @@ -42,7 +42,6 @@ import org.apache.zest.test.AbstractZestTest; import org.apache.zest.test.EntityTestAssembler; import static org.junit.Assert.assertEquals; -import static org.apache.zest.functional.Iterables.first; public class DebuggingTest extends AbstractZestTest @@ -81,7 +80,7 @@ public class DebuggingTest public EntityState apply( EntityState entityState ) { if( ServiceDebugRecordEntity.class.getName() - .equals( first(entityState.entityDescriptor().types()).getName() ) ) + .equals( entityState.entityDescriptor().types().findFirst().get().getName() ) ) { result[0] = entityState.identity().identity(); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiEnabledService.java ---------------------------------------------------------------------- diff --git a/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiEnabledService.java b/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiEnabledService.java index 3c94799..d648186 100644 --- a/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiEnabledService.java +++ b/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiEnabledService.java @@ -20,8 +20,7 @@ package org.apache.zest.library.osgi; import java.lang.reflect.Type; import java.util.Dictionary; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; +import java.util.stream.Stream; import org.apache.zest.api.activation.ActivatorAdapter; import org.apache.zest.api.activation.Activators; import org.apache.zest.api.injection.scope.Structure; @@ -31,13 +30,11 @@ import org.apache.zest.api.service.ServiceComposite; import org.apache.zest.api.service.ServiceDescriptor; import org.apache.zest.api.service.ServiceReference; import org.apache.zest.api.structure.Module; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; import static org.apache.zest.api.util.Classes.toClassName; import static org.apache.zest.api.util.Classes.typesOf; -import static org.apache.zest.functional.Iterables.cast; -import static org.apache.zest.functional.Iterables.first; -import static org.apache.zest.functional.Iterables.map; -import static org.apache.zest.functional.Iterables.toArray; /** * Service Fragment providing OSGi support. @@ -48,32 +45,30 @@ public interface OSGiEnabledService extends ServiceComposite { void registerServices() - throws Exception; + throws Exception; void unregisterServices() - throws Exception; + throws Exception; class Activator - extends ActivatorAdapter<ServiceReference<OSGiEnabledService>> + extends ActivatorAdapter<ServiceReference<OSGiEnabledService>> { @Override public void afterActivation( ServiceReference<OSGiEnabledService> activated ) - throws Exception + throws Exception { activated.get().registerServices(); } @Override public void beforePassivation( ServiceReference<OSGiEnabledService> passivating ) - throws Exception + throws Exception { passivating.get().unregisterServices(); } - } - public abstract class OSGiEnabledServiceMixin implements OSGiEnabledService { @@ -94,11 +89,11 @@ public interface OSGiEnabledService extends ServiceComposite { return; } - for( ServiceReference ref : module.findServices( first( descriptor.types() ) ) ) + for( ServiceReference ref : module.findServices( descriptor.types().findFirst().orElse( null ) ) ) { if( ref.identity().equals( identity().get() ) ) { - Iterable<Type> classesSet = cast(descriptor.types()); + Stream<? extends Type> classesSet = descriptor.types(); Dictionary properties = descriptor.metaInfo( Dictionary.class ); String[] clazzes = fetchInterfacesImplemented( classesSet ); registration = context.registerService( clazzes, ref.get(), properties ); @@ -106,9 +101,9 @@ public interface OSGiEnabledService extends ServiceComposite } } - private String[] fetchInterfacesImplemented( Iterable<Type> classesSet ) + private String[] fetchInterfacesImplemented( Stream<? extends Type> classesSet ) { - return toArray( String.class, map( toClassName(), typesOf( classesSet ) ) ); + return typesOf( classesSet ).map( toClassName() ).toArray( String[]::new ); } @Override http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiServiceExporter.java ---------------------------------------------------------------------- diff --git a/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiServiceExporter.java b/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiServiceExporter.java index c530234..6017644 100644 --- a/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiServiceExporter.java +++ b/libraries/osgi/src/main/java/org/apache/zest/library/osgi/OSGiServiceExporter.java @@ -20,6 +20,7 @@ package org.apache.zest.library.osgi; import java.util.ArrayList; import java.util.Properties; +import java.util.stream.Stream; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.apache.zest.api.activation.ActivatorAdapter; @@ -30,7 +31,6 @@ import org.apache.zest.api.service.ServiceComposite; import org.apache.zest.api.service.ServiceReference; import org.apache.zest.api.service.qualifier.HasMetaInfo; import org.apache.zest.api.util.Classes; -import org.apache.zest.functional.Iterables; import static org.apache.zest.api.util.Classes.interfacesOf; @@ -87,8 +87,6 @@ public interface OSGiServiceExporter Class<? extends BundleContext> type = BundleContext.class; BundleContext context = ref.metaInfo( type ); ServiceComposite service = ref.get(); - Iterable<Class<?>> interfaces = Iterables.map( Classes.RAW_CLASS, interfacesOf( service.getClass() ) ); - String[] interfaceNames = new String[ (int) Iterables.count( interfaces ) ]; Properties properties = ref.metaInfo( Properties.class ); if( properties == null ) { @@ -97,13 +95,12 @@ public interface OSGiServiceExporter properties.put( "org.apache.zest.api.service.active", ref.isActive() ); properties.put( "org.apache.zest.api.service.available", ref.isAvailable() ); properties.put( "org.apache.zest.api.service.identity", ref.identity() ); - int i = 0; - for( Class cls : interfaces ) - { - interfaceNames[ i++] = cls.getName(); - } - registrations.add( context.registerService( interfaceNames, service, properties ) ); + + String[] interfaceNames = interfacesOf( service.getClass() ) + .map( Classes.RAW_CLASS ).toArray( String[]::new ); + + registrations.add( context.registerService( interfaceNames, service, properties ) ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityStateSerializer.java ---------------------------------------------------------------------- diff --git a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityStateSerializer.java b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityStateSerializer.java index b960d60..5977ed1 100644 --- a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityStateSerializer.java +++ b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityStateSerializer.java @@ -17,17 +17,9 @@ */ package org.apache.zest.library.rdf.entity; -import org.openrdf.model.BNode; -import org.openrdf.model.Graph; -import org.openrdf.model.Literal; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.GraphImpl; +import java.util.stream.Stream; import org.apache.zest.api.ZestAPI; import org.apache.zest.api.association.AssociationDescriptor; -import org.apache.zest.api.composite.Composite; import org.apache.zest.api.entity.EntityDescriptor; import org.apache.zest.api.entity.EntityReference; import org.apache.zest.api.injection.scope.Service; @@ -43,8 +35,14 @@ import org.apache.zest.api.value.ValueSerializer.Options; import org.apache.zest.library.rdf.Rdfs; import org.apache.zest.spi.entity.EntityState; import org.apache.zest.spi.entity.ManyAssociationState; - -import static org.apache.zest.functional.Iterables.first; +import org.openrdf.model.BNode; +import org.openrdf.model.Graph; +import org.openrdf.model.Literal; +import org.openrdf.model.Resource; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.GraphImpl; /** * JAVADOC @@ -67,7 +65,8 @@ public class EntityStateSerializer } public Iterable<Statement> serialize( final EntityState entityState, - final boolean includeNonQueryable ) + final boolean includeNonQueryable + ) { Graph graph = new GraphImpl(); serialize( entityState, includeNonQueryable, graph ); @@ -76,7 +75,8 @@ public class EntityStateSerializer public void serialize( final EntityState entityState, final boolean includeNonQueryable, - final Graph graph ) + final Graph graph + ) { ValueFactory values = graph.getValueFactory(); EntityReference identity = entityState.identity(); @@ -84,7 +84,7 @@ public class EntityStateSerializer graph.add( entityUri, Rdfs.TYPE, - values.createURI( Classes.toURI( first( entityState.entityDescriptor().types() ) ) ) ); + values.createURI( Classes.toURI( entityState.entityDescriptor().types().findFirst().orElse( null ) ) ) ); serializeProperties( entityState, graph, @@ -109,24 +109,25 @@ public class EntityStateSerializer final Graph graph, final Resource subject, final EntityDescriptor entityType, - final boolean includeNonQueryable ) + final boolean includeNonQueryable + ) { // Properties - for( PropertyDescriptor persistentProperty : entityType.state().properties() ) - { + entityType.state().properties().forEach( persistentProperty -> { Object property = entityState.propertyValueOf( persistentProperty.qualifiedName() ); if( property != null ) { serializeProperty( persistentProperty, property, subject, graph, includeNonQueryable ); } - } + } ); } private void serializeProperty( PropertyDescriptor persistentProperty, Object property, Resource subject, Graph graph, - boolean includeNonQueryable ) + boolean includeNonQueryable + ) { if( !( includeNonQueryable || persistentProperty.queryable() ) ) { @@ -159,55 +160,48 @@ public class EntityStateSerializer ValueType valueType, Graph graph, String baseUri, - boolean includeNonQueryable ) + boolean includeNonQueryable + ) { final ValueFactory valueFactory = graph.getValueFactory(); BNode collection = valueFactory.createBNode(); graph.add( subject, predicate, collection ); - for( PropertyDescriptor persistentProperty : ( (ValueCompositeType) valueType ).properties() ) - { + ( (ValueCompositeType) valueType ).properties().forEach( persistentProperty -> { Object propertyValue = ZestAPI.FUNCTION_COMPOSITE_INSTANCE_OF - .apply( (Composite) value ) + .apply( value ) .state() .propertyFor( persistentProperty.accessor() ) .get(); - if( propertyValue == null ) - { - continue; // Skip null values - } - - ValueType type = persistentProperty.valueType(); - if( type instanceof ValueCompositeType ) + if( propertyValue != null ) { - URI pred = valueFactory.createURI( baseUri, persistentProperty.qualifiedName().name() ); - serializeValueComposite( collection, pred, (ValueComposite) propertyValue, type, graph, - baseUri + persistentProperty.qualifiedName().name() + "/", - includeNonQueryable ); + ValueType type = persistentProperty.valueType(); + if( type instanceof ValueCompositeType ) + { + URI pred = valueFactory.createURI( baseUri, persistentProperty.qualifiedName().name() ); + serializeValueComposite( collection, pred, (ValueComposite) propertyValue, type, graph, + baseUri + persistentProperty.qualifiedName().name() + "/", + includeNonQueryable ); + } + else + { + serializeProperty( persistentProperty, propertyValue, collection, graph, includeNonQueryable ); + } } - else - { - serializeProperty( persistentProperty, propertyValue, collection, graph, includeNonQueryable ); - } - } + } ); } private void serializeAssociations( final EntityState entityState, final Graph graph, URI entityUri, - final Iterable<? extends AssociationDescriptor> associations, - final boolean includeNonQueryable ) + final Stream<? extends AssociationDescriptor> associations, + final boolean includeNonQueryable + ) { ValueFactory values = graph.getValueFactory(); // Associations - for( AssociationDescriptor associationType : associations ) - { - if( !( includeNonQueryable || associationType.queryable() ) ) - { - continue; // Skip non-queryable - } - + associations.filter( type -> includeNonQueryable || type.queryable() ).forEach( associationType -> { EntityReference associatedId = entityState.associationValueOf( associationType.qualifiedName() ); if( associatedId != null ) { @@ -215,25 +209,20 @@ public class EntityStateSerializer URI assocEntityURI = values.createURI( associatedId.toURI() ); graph.add( entityUri, assocURI, assocEntityURI ); } - } + } ); } private void serializeManyAssociations( final EntityState entityState, final Graph graph, final URI entityUri, - final Iterable<? extends AssociationDescriptor> associations, - final boolean includeNonQueryable ) + final Stream<? extends AssociationDescriptor> associations, + final boolean includeNonQueryable + ) { ValueFactory values = graph.getValueFactory(); // Many-Associations - for( AssociationDescriptor associationType : associations ) - { - if( !( includeNonQueryable || associationType.queryable() ) ) - { - continue; // Skip non-queryable - } - + associations.filter( type -> includeNonQueryable || type.queryable() ).forEach( associationType -> { BNode collection = values.createBNode(); graph.add( entityUri, values.createURI( associationType.qualifiedName().toURI() ), collection ); graph.add( collection, Rdfs.TYPE, Rdfs.SEQ ); @@ -244,6 +233,6 @@ public class EntityStateSerializer URI assocEntityURI = values.createURI( associatedId.toURI() ); graph.add( collection, Rdfs.LIST_ITEM, assocEntityURI ); } - } + } ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityTypeSerializer.java ---------------------------------------------------------------------- diff --git a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityTypeSerializer.java b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityTypeSerializer.java index da6a2ef..1883c18 100644 --- a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityTypeSerializer.java +++ b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/entity/EntityTypeSerializer.java @@ -21,6 +21,11 @@ import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; import java.util.Map; +import org.apache.zest.api.entity.EntityDescriptor; +import org.apache.zest.api.property.PropertyDescriptor; +import org.apache.zest.api.util.Classes; +import org.apache.zest.library.rdf.Rdfs; +import org.apache.zest.library.rdf.ZestEntityType; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; @@ -31,14 +36,6 @@ import org.openrdf.model.ValueFactory; import org.openrdf.model.impl.GraphImpl; import org.openrdf.model.vocabulary.OWL; import org.openrdf.model.vocabulary.XMLSchema; -import org.apache.zest.api.association.AssociationDescriptor; -import org.apache.zest.api.entity.EntityDescriptor; -import org.apache.zest.api.property.PropertyDescriptor; -import org.apache.zest.api.util.Classes; -import org.apache.zest.library.rdf.ZestEntityType; -import org.apache.zest.library.rdf.Rdfs; - -import static org.apache.zest.functional.Iterables.first; /** * JAVADOC @@ -69,12 +66,15 @@ public class EntityTypeSerializer { Graph graph = new GraphImpl(); ValueFactory values = graph.getValueFactory(); - URI entityTypeUri = values.createURI( Classes.toURI( first( entityDescriptor.types() ) ) ); + URI entityTypeUri = values.createURI( Classes.toURI( entityDescriptor.types().findFirst().orElse( null ) ) ); graph.add( entityTypeUri, Rdfs.TYPE, Rdfs.CLASS ); graph.add( entityTypeUri, Rdfs.TYPE, OWL.CLASS ); - graph.add( entityTypeUri, ZestEntityType.TYPE, values.createLiteral( first( entityDescriptor.types() ).toString() ) ); + graph.add( entityTypeUri, ZestEntityType.TYPE, values.createLiteral( entityDescriptor.types() + .findFirst() + .get() + .toString() ) ); graph.add( entityTypeUri, ZestEntityType.QUERYABLE, values.createLiteral( entityDescriptor.queryable() ) ); serializeMixinTypes( entityDescriptor, graph, entityTypeUri ); @@ -88,25 +88,24 @@ public class EntityTypeSerializer private void serializeMixinTypes( final EntityDescriptor entityDescriptor, final Graph graph, - final URI entityTypeUri ) + final URI entityTypeUri + ) { ValueFactory values = graph.getValueFactory(); - // Mixin types - for( Class<?> mixinType : entityDescriptor.mixinTypes() ) - { + entityDescriptor.mixinTypes().forEach( mixinType -> { graph.add( entityTypeUri, Rdfs.SUB_CLASS_OF, values.createURI( Classes.toURI( mixinType ) ) ); - } + } ); } private void serializeManyAssociationTypes( final EntityDescriptor entityDescriptor, final Graph graph, - final URI entityTypeUri ) + final URI entityTypeUri + ) { ValueFactory values = graph.getValueFactory(); // ManyAssociations - for( AssociationDescriptor manyAssociationType : entityDescriptor.state().manyAssociations() ) - { + entityDescriptor.state().manyAssociations().forEach( manyAssociationType -> { URI associationURI = values.createURI( manyAssociationType.qualifiedName().toURI() ); graph.add( associationURI, Rdfs.DOMAIN, entityTypeUri ); @@ -115,17 +114,17 @@ public class EntityTypeSerializer URI associatedURI = values.createURI( manyAssociationType.qualifiedName().toURI() ); graph.add( associationURI, Rdfs.RANGE, associatedURI ); graph.add( associationURI, Rdfs.RANGE, XMLSchema.ANYURI ); - } + } ); } private void serializeAssociationTypes( final EntityDescriptor entityDescriptor, final Graph graph, - final URI entityTypeUri ) + final URI entityTypeUri + ) { ValueFactory values = graph.getValueFactory(); // Associations - for( AssociationDescriptor associationType : entityDescriptor.state().associations() ) - { + entityDescriptor.state().associations().forEach( associationType -> { URI associationURI = values.createURI( associationType.qualifiedName().toURI() ); graph.add( associationURI, Rdfs.DOMAIN, entityTypeUri ); graph.add( associationURI, Rdfs.TYPE, Rdfs.PROPERTY ); @@ -133,18 +132,18 @@ public class EntityTypeSerializer URI associatedURI = values.createURI( Classes.toURI( Classes.RAW_CLASS.apply( associationType.type() ) ) ); graph.add( associationURI, Rdfs.RANGE, associatedURI ); graph.add( associationURI, Rdfs.RANGE, XMLSchema.ANYURI ); - } + } ); } private void serializePropertyTypes( final EntityDescriptor entityDescriptor, final Graph graph, - final URI entityTypeUri ) + final URI entityTypeUri + ) { ValueFactory values = graph.getValueFactory(); // Properties - for( PropertyDescriptor persistentProperty : entityDescriptor.state().properties() ) - { + entityDescriptor.state().properties().forEach( persistentProperty -> { URI propertyURI = values.createURI( persistentProperty.qualifiedName().toURI() ); graph.add( propertyURI, Rdfs.DOMAIN, entityTypeUri ); graph.add( propertyURI, Rdfs.TYPE, Rdfs.PROPERTY ); @@ -155,6 +154,6 @@ public class EntityTypeSerializer { graph.add( propertyURI, Rdfs.RANGE, type ); } - } + } ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rdf/src/main/java/org/apache/zest/library/rdf/model/ApplicationVisitor.java ---------------------------------------------------------------------- diff --git a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/model/ApplicationVisitor.java b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/model/ApplicationVisitor.java index 5c51b09..17f2808 100644 --- a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/model/ApplicationVisitor.java +++ b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/model/ApplicationVisitor.java @@ -25,8 +25,6 @@ import org.apache.zest.functional.HierarchicalVisitorAdapter; import org.apache.zest.library.rdf.ZestRdf; import org.apache.zest.library.rdf.serializer.SerializerContext; -import static org.apache.zest.functional.Iterables.first; - /** * JAVADOC */ @@ -78,7 +76,7 @@ class ApplicationVisitor extends HierarchicalVisitorAdapter<Object, Object, Runt if( visited instanceof TransientDescriptor ) { TransientDescriptor transientDescriptor = (TransientDescriptor) visited; - compositeUri = context.createCompositeUri( moduleUri, first( transientDescriptor.types() ) ); + compositeUri = context.createCompositeUri( moduleUri, transientDescriptor.types().findFirst().orElse( null ) ); context.addType( compositeUri, ZestRdf.TYPE_COMPOSITE ); context.addRelationship( moduleUri, ZestRdf.RELATIONSHIP_COMPOSITE, compositeUri ); } @@ -86,7 +84,7 @@ class ApplicationVisitor extends HierarchicalVisitorAdapter<Object, Object, Runt if( visited instanceof EntityDescriptor ) { EntityDescriptor entityDescriptor = (EntityDescriptor) visited; - compositeUri = context.createCompositeUri( moduleUri, first( entityDescriptor.types() ) ); + compositeUri = context.createCompositeUri( moduleUri, entityDescriptor.types().findFirst().orElse( null )); context.addType( compositeUri, ZestRdf.TYPE_ENTITY ); context.addRelationship( moduleUri, ZestRdf.RELATIONSHIP_ENTITY, compositeUri ); } @@ -94,7 +92,7 @@ class ApplicationVisitor extends HierarchicalVisitorAdapter<Object, Object, Runt if( visited instanceof ObjectDescriptor ) { ObjectDescriptor objectDescriptor = (ObjectDescriptor) visited; - compositeUri = context.createCompositeUri( moduleUri, first( objectDescriptor.types() ) ); + compositeUri = context.createCompositeUri( moduleUri, objectDescriptor.types().findFirst().orElse( null ) ); context.addType( compositeUri, ZestRdf.TYPE_OBJECT ); context.addRelationship( moduleUri, ZestRdf.RELATIONSHIP_OBJECT, compositeUri ); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rdf/src/main/java/org/apache/zest/library/rdf/model/Model2XML.java ---------------------------------------------------------------------- diff --git a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/model/Model2XML.java b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/model/Model2XML.java index c697919..e50a31c 100644 --- a/libraries/rdf/src/main/java/org/apache/zest/library/rdf/model/Model2XML.java +++ b/libraries/rdf/src/main/java/org/apache/zest/library/rdf/model/Model2XML.java @@ -38,8 +38,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; -import static org.apache.zest.functional.Iterables.first; - /** * TODO */ @@ -117,7 +115,7 @@ public class Model2XML TransientDescriptor descriptor = (TransientDescriptor) visited; Node node = document.createElement( "transient" ); - addAttribute( "type", first(descriptor.types()).getName(), node ); + addAttribute( "type", descriptor.types().findFirst().get().getName(), node ); addAttribute( "visibility", descriptor.visibility().name(), node ); current.push( node ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/api/ErrorHandler.java ---------------------------------------------------------------------- diff --git a/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/api/ErrorHandler.java b/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/api/ErrorHandler.java index 1f6f169..5a8d7cd 100644 --- a/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/api/ErrorHandler.java +++ b/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/api/ErrorHandler.java @@ -21,7 +21,6 @@ package org.apache.zest.library.rest.client.api; import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Predicate; -import org.apache.zest.functional.Specifications; import org.apache.zest.library.rest.client.spi.ResponseHandler; import org.restlet.Response; import org.restlet.data.Status; @@ -65,7 +64,7 @@ public class ErrorHandler public ErrorHandler onError(ResponseHandler handler) { - handlers.put( Specifications.<Response>TRUE(), handler ); + handlers.put( item -> true, handler ); return this; } http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/requestwriter/ValueCompositeRequestWriter.java ---------------------------------------------------------------------- diff --git a/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/requestwriter/ValueCompositeRequestWriter.java b/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/requestwriter/ValueCompositeRequestWriter.java index 6bd5571..81fb129 100644 --- a/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/requestwriter/ValueCompositeRequestWriter.java +++ b/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/requestwriter/ValueCompositeRequestWriter.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.Writer; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.property.PropertyDescriptor; import org.apache.zest.api.property.StateHolder; import org.apache.zest.api.service.qualifier.Tagged; import org.apache.zest.api.value.ValueComposite; @@ -65,31 +64,30 @@ public class ValueCompositeRequestWriter StateHolder holder = spi.stateOf( valueObject ); final ValueDescriptor descriptor = spi.valueDescriptorFor( valueObject ); - final Reference ref = request.getResourceRef(); - ref.setQuery( null ); - - try - { - for( PropertyDescriptor propertyDescriptor : descriptor.state().properties() ) + final Reference ref = request.getResourceRef(); + ref.setQuery( null ); + descriptor.state().properties().forEach( propertyDescriptor -> { + try { Object value = holder.propertyFor( propertyDescriptor.accessor() ).get(); String param; if( value == null ) { - param = null; + param = null; } else { - param = valueSerializer.serialize( value ); + param = valueSerializer.serialize( value ); } ref.addQueryParameter( propertyDescriptor.qualifiedName().name(), param ); } - } - catch( ValueSerializationException e ) - { - throw new ResourceException( e ); - } - } else + catch( ValueSerializationException e ) + { + throw new ResourceException( e ); + } + } ); + } + else { request.setEntity(new WriterRepresentation( MediaType.APPLICATION_JSON ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/RestServerException.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/RestServerException.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/RestServerException.java new file mode 100644 index 0000000..a76069f --- /dev/null +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/RestServerException.java @@ -0,0 +1,34 @@ +/* + * 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.library.rest.server; + +public class RestServerException extends RuntimeException +{ + public RestServerException( String message, Throwable cause ) + { + super( message, cause ); + } + + public RestServerException( String message ) + { + super( message ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ContextResource.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ContextResource.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ContextResource.java index 1c9f88a..f673e6e 100644 --- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ContextResource.java +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ContextResource.java @@ -871,10 +871,8 @@ public class ContextResource { ValueDescriptor valueDescriptor = module.valueDescriptor( valueType.getName() ); - for( PropertyDescriptor propertyDescriptor : valueDescriptor.state().properties() ) - { + valueDescriptor.state().properties().forEach(propertyDescriptor -> { String value = getValue( propertyDescriptor.qualifiedName().name(), queryAsForm, entityAsForm ); - if( value == null ) { Object initialValue = propertyDescriptor.initialValue( module ); @@ -883,9 +881,8 @@ public class ContextResource value = initialValue.toString(); } } - form.add( propertyDescriptor.qualifiedName().name(), value ); - } + }); } else if( valueType.isInterface() && interactionMethod.getParameterTypes().length == 1 ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/assembler/RestServerAssembler.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/assembler/RestServerAssembler.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/assembler/RestServerAssembler.java index 84d3348..5a7481f 100644 --- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/assembler/RestServerAssembler.java +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/assembler/RestServerAssembler.java @@ -42,8 +42,6 @@ import static org.apache.zest.api.util.Classes.isAssignableFrom; import static org.apache.zest.bootstrap.ImportedServiceDeclaration.INSTANCE; import static org.apache.zest.bootstrap.ImportedServiceDeclaration.NEW_OBJECT; import static org.apache.zest.functional.Iterables.filter; -import static org.apache.zest.functional.Specifications.and; -import static org.apache.zest.functional.Specifications.not; /** * JAVADOC @@ -98,8 +96,8 @@ public class RestServerAssembler // Standard response writers Iterable<Class<?>> writers = ClassScanner.findClasses( DefaultResponseWriter.class ); Predicate<Class<?>> responseWriterClass = isAssignableFrom( ResponseWriter.class ); - Predicate<Class<?>> isNotAnAbstract = not( hasModifier( Modifier.ABSTRACT ) ); - Iterable<Class<?>> candidates = filter( and( isNotAnAbstract, responseWriterClass ), writers ); + Predicate<Class<?>> isNotAnAbstract = hasModifier( Modifier.ABSTRACT ).negate(); + Iterable<Class<?>> candidates = filter( isNotAnAbstract.and( responseWriterClass ), writers ); for( Class<?> responseWriter : candidates ) { module.objects( responseWriter ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/freemarker/ValueCompositeTemplateModel.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/freemarker/ValueCompositeTemplateModel.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/freemarker/ValueCompositeTemplateModel.java index 6c8f48f..64a022d 100644 --- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/freemarker/ValueCompositeTemplateModel.java +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/freemarker/ValueCompositeTemplateModel.java @@ -24,10 +24,11 @@ import freemarker.template.TemplateHashModelEx; import freemarker.template.TemplateModel; import freemarker.template.TemplateModelException; import freemarker.template.TemplateScalarModel; +import java.util.List; import java.util.function.Function; +import java.util.stream.Collectors; import org.apache.zest.api.ZestAPI; import org.apache.zest.api.property.Property; -import org.apache.zest.api.property.PropertyDescriptor; import org.apache.zest.api.value.ValueComposite; import org.apache.zest.api.value.ValueDescriptor; import org.apache.zest.functional.Iterables; @@ -53,32 +54,26 @@ public class ValueCompositeTemplateModel public int size() throws TemplateModelException { - return (int) Iterables.count( descriptor.state().properties() ); + return (int) descriptor.state().properties().count(); } @Override public TemplateCollectionModel keys() throws TemplateModelException { - return (TemplateCollectionModel) wrapper.wrap( Iterables.map( new Function<PropertyDescriptor, String>() - { - @Override - public String apply( PropertyDescriptor propertyDescriptor ) - { - return propertyDescriptor.qualifiedName().name(); - } - }, descriptor.state().properties() ).iterator() ); + List<String> names = descriptor.state().properties() + .map( descriptor -> descriptor.qualifiedName().name() ) + .collect( Collectors.toList() ); + return (TemplateCollectionModel) wrapper.wrap( names.iterator() ); } @Override public TemplateCollectionModel values() throws TemplateModelException { - return (TemplateCollectionModel) wrapper.wrap( Iterables.map( new Function<Property<?>, Object>() - { - @Override - public Object apply( Property<?> objectProperty ) - { + List<Object> values = ZestAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply( composite ) + .state().properties() + .map( (Function<Property<?>, Object>) objectProperty -> { try { return wrapper.wrap( objectProperty.get() ); @@ -87,8 +82,10 @@ public class ValueCompositeTemplateModel { throw new IllegalStateException( e ); } - } - }, ZestAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply( composite ).state().properties() ).iterator() ); + } ) + .collect( Collectors.toList() ); + + return (TemplateCollectionModel) wrapper.wrap( values ); } @Override http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/responsewriter/RestResponseException.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/responsewriter/RestResponseException.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/responsewriter/RestResponseException.java new file mode 100644 index 0000000..466685a --- /dev/null +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/responsewriter/RestResponseException.java @@ -0,0 +1,31 @@ +/* + * 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.library.rest.server.restlet.responsewriter; + +import org.apache.zest.library.rest.server.RestServerException; + +public class RestResponseException extends RestServerException +{ + public RestResponseException( String message, Throwable cause ) + { + super( message, cause ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/responsewriter/ValueDescriptorResponseWriter.java ---------------------------------------------------------------------- diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/responsewriter/ValueDescriptorResponseWriter.java b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/responsewriter/ValueDescriptorResponseWriter.java index 1999c51..10ba4b7 100644 --- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/responsewriter/ValueDescriptorResponseWriter.java +++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/responsewriter/ValueDescriptorResponseWriter.java @@ -29,7 +29,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.property.PropertyDescriptor; import org.apache.zest.api.structure.Module; import org.apache.zest.api.value.ValueDescriptor; import org.restlet.Response; @@ -63,9 +62,8 @@ public class ValueDescriptorResponseWriter extends AbstractResponseWriter { JSONObject json = new JSONObject(); ValueDescriptor vd = (ValueDescriptor) result; - try - { - for( PropertyDescriptor propertyDescriptor : vd.state().properties() ) + vd.state().properties().forEach( propertyDescriptor -> { + try { Object o = propertyDescriptor.initialValue( module ); if( o == null ) @@ -77,15 +75,14 @@ public class ValueDescriptorResponseWriter extends AbstractResponseWriter json.put( propertyDescriptor.qualifiedName().name(), o.toString() ); } } - } - catch( JSONException e ) - { - throw new ResourceException(e); - } + catch( JSONException e ) + { + throw new RestResponseException( "Unable to serialize " + vd, e); + } + } ); StringRepresentation representation = new StringRepresentation( json.toString(), MediaType.APPLICATION_JSON ); response.setEntity( representation ); - return true; } else if( MediaType.TEXT_HTML.equals( type ) ) @@ -96,7 +93,7 @@ public class ValueDescriptorResponseWriter extends AbstractResponseWriter public void write( Writer writer ) throws IOException { - Map<String, Object> context = new HashMap<String, Object>(); + Map<String, Object> context = new HashMap<>(); context.put( "request", response.getRequest() ); context.put( "response", response ); context.put( "result", result ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java ---------------------------------------------------------------------- diff --git a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java index e8e3a71..481ee15 100644 --- a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java +++ b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java @@ -28,15 +28,11 @@ import java.util.Date; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.openrdf.model.Statement; -import org.openrdf.rio.RDFHandlerException; -import org.apache.zest.api.association.AssociationDescriptor; import org.apache.zest.api.entity.EntityDescriptor; import org.apache.zest.api.entity.EntityReference; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.Uses; -import org.apache.zest.api.property.PropertyDescriptor; import org.apache.zest.api.usecase.Usecase; import org.apache.zest.api.usecase.UsecaseBuilder; import org.apache.zest.api.value.ValueSerialization; @@ -53,6 +49,8 @@ import org.apache.zest.spi.entitystore.EntityStore; import org.apache.zest.spi.entitystore.EntityStoreUnitOfWork; import org.apache.zest.spi.entitystore.helpers.JSONEntityState; import org.apache.zest.spi.module.ModuleSpi; +import org.openrdf.model.Statement; +import org.openrdf.rio.RDFHandlerException; import org.restlet.data.CharacterSet; import org.restlet.data.Form; import org.restlet.data.Language; @@ -217,8 +215,7 @@ public class EntityResource final EntityDescriptor descriptor = entity.entityDescriptor(); - for( PropertyDescriptor persistentProperty : descriptor.state().properties() ) - { + descriptor.state().properties().forEach( persistentProperty -> { Object value = entity.propertyValueOf( persistentProperty.qualifiedName() ); out.println( "<tr><td>" + "<label for=\"" + persistentProperty.qualifiedName() + "\" >" @@ -231,12 +228,11 @@ public class EntityResource + "name=\"" + persistentProperty.qualifiedName() + "\" " + "value=\"" + ( value == null ? "" : valueSerialization.serialize( value ) ) + "\"/></td></tr>" ); - } + } ); out.println( "</table></fieldset>\n" ); out.println( "<fieldset><legend>Associations</legend>\n<table>" ); - for( AssociationDescriptor associationType : descriptor.state().associations() ) - { + descriptor.state().associations().forEach( associationType -> { Object value = entity.associationValueOf( associationType.qualifiedName() ); if( value == null ) { @@ -251,12 +247,11 @@ public class EntityResource + "size=\"80\" " + "name=\"" + associationType.qualifiedName() + "\" " + "value=\"" + value + "\"/></td></tr>" ); - } + } ); out.println( "</table></fieldset>\n" ); out.println( "<fieldset><legend>ManyAssociations</legend>\n<table>" ); - for( AssociationDescriptor associationType : descriptor.state().manyAssociations() ) - { + descriptor.state().manyAssociations().forEach( associationType -> { ManyAssociationState identities = entity.manyAssociationValueOf( associationType.qualifiedName() ); String value = ""; for( EntityReference identity : identities ) @@ -274,12 +269,11 @@ public class EntityResource + "name=\"" + associationType.qualifiedName() + "\" >" + value + "</textarea></td></tr>" ); - } + }); out.println( "</table></fieldset>\n" ); out.println( "<fieldset><legend>NamedAssociations</legend>\n<table>" ); - for( AssociationDescriptor associationType : descriptor.state().namedAssociations() ) - { + descriptor.state().namedAssociations().forEach( associationType -> { NamedAssociationState identities = entity.namedAssociationValueOf( associationType.qualifiedName() ); String value = ""; for( String name : identities ) @@ -297,7 +291,7 @@ public class EntityResource + "name=\"" + associationType.qualifiedName() + "\" >" + value + "</textarea></td></tr>" ); - } + } ); out.println( "</table></fieldset>\n" ); out.println( "<input type=\"submit\" value=\"Update\"/></form>\n" ); @@ -366,8 +360,7 @@ public class EntityResource final EntityDescriptor descriptor = entity.entityDescriptor(); // Parse JSON into properties - for( PropertyDescriptor persistentProperty : descriptor.state().properties() ) - { + descriptor.state().properties().forEach( persistentProperty -> { if( !persistentProperty.isImmutable() ) { String formValue = form.getFirstValue( persistentProperty.qualifiedName().name(), null ); @@ -382,10 +375,9 @@ public class EntityResource valueSerialization.deserialize( persistentProperty.valueType(), formValue ) ); } } - } + } ); - for( AssociationDescriptor associationType : descriptor.state().associations() ) - { + descriptor.state().associations().forEach( associationType -> { String newStringAssociation = form.getFirstValue( associationType.qualifiedName().name() ); if( newStringAssociation == null || newStringAssociation.isEmpty() ) { @@ -396,9 +388,8 @@ public class EntityResource entity.setAssociationValue( associationType.qualifiedName(), EntityReference.parseEntityReference( newStringAssociation ) ); } - } - for( AssociationDescriptor associationType : descriptor.state().manyAssociations() ) - { + } ); + descriptor.state().manyAssociations().forEach( associationType -> { String newStringAssociation = form.getFirstValue( associationType.qualifiedName().name() ); ManyAssociationState manyAssociation = entity.manyAssociationValueOf( associationType.qualifiedName() ); if( newStringAssociation == null ) @@ -408,51 +399,51 @@ public class EntityResource { manyAssociation.remove( entityReference ); } - continue; } - - BufferedReader bufferedReader = new BufferedReader( new StringReader( newStringAssociation ) ); - String identity; - - try + else { - // Synchronize old and new association - int index = 0; - while( ( identity = bufferedReader.readLine() ) != null ) - { - EntityReference reference = new EntityReference( identity ); + BufferedReader bufferedReader = new BufferedReader( new StringReader( newStringAssociation ) ); + String identity; - if( manyAssociation.count() < index && manyAssociation.get( index ).equals( reference ) ) + try + { + // Synchronize old and new association + int index = 0; + while( ( identity = bufferedReader.readLine() ) != null ) { - continue; + EntityReference reference = new EntityReference( identity ); + + if( manyAssociation.count() < index && manyAssociation.get( index ).equals( reference ) ) + { + continue; + } + + try + { + unitOfWork.entityStateOf( module, reference ); + + manyAssociation.remove( reference ); + manyAssociation.add( index++, reference ); + } + catch( EntityNotFoundException e ) + { + // Ignore this entity - doesn't exist + } } - try + // Remove "left-overs" + while( manyAssociation.count() > index ) { - unitOfWork.entityStateOf( module, reference ); - - manyAssociation.remove( reference ); - manyAssociation.add( index++, reference ); - } - catch( EntityNotFoundException e ) - { - // Ignore this entity - doesn't exist + manyAssociation.remove( manyAssociation.get( index ) ); } } - - // Remove "left-overs" - while( manyAssociation.count() > index ) + catch( IOException e ) { - manyAssociation.remove( manyAssociation.get( index ) ); + // Ignore } } - catch( IOException e ) - { - // Ignore - } - } - for( AssociationDescriptor associationType : descriptor.state().namedAssociations() ) - { + } ); + descriptor.state().namedAssociations().forEach( associationType -> { String newStringAssociation = form.getFirstValue( associationType.qualifiedName().name() ); NamedAssociationState namedAssociation = entity.namedAssociationValueOf( associationType.qualifiedName() ); if( newStringAssociation == null ) @@ -462,52 +453,51 @@ public class EntityResource { namedAssociation.remove( name ); } - continue; } - Set<String> names = new HashSet<>(); - BufferedReader bufferedReader = new BufferedReader( new StringReader( newStringAssociation ) ); - String line; - try + else { - while( ( line = bufferedReader.readLine() ) != null ) + Set<String> names = new HashSet<>(); + BufferedReader bufferedReader = new BufferedReader( new StringReader( newStringAssociation ) ); + String line; + try { - String name = line; - line = bufferedReader.readLine(); - if( line == null ) + while( ( line = bufferedReader.readLine() ) != null ) { - break; + String name = line; + line = bufferedReader.readLine(); + if( line == null ) + { + break; + } + String identity = line; + EntityReference reference = new EntityReference( identity ); + try + { + unitOfWork.entityStateOf( module, reference ); + + namedAssociation.remove( name ); + namedAssociation.put( name, reference ); + + names.add( name ); + } + catch( EntityNotFoundException e ) + { + // Ignore this entity - doesn't exist + } } - String identity = line; - EntityReference reference = new EntityReference( identity ); - try - { - unitOfWork.entityStateOf( module, reference ); - namedAssociation.remove( name ); - namedAssociation.put( name, reference ); - - names.add( name ); - } - catch( EntityNotFoundException e ) - { - // Ignore this entity - doesn't exist - } + // Remove "left-overs" + Iterables.toList( namedAssociation ) + .stream() + .filter( assocName -> !names.contains( assocName ) ) + .forEach( namedAssociation::remove ); } - - // Remove "left-overs" - for( String assocName : Iterables.toList( namedAssociation ) ) + catch( IOException e ) { - if( !names.contains( assocName ) ) - { - namedAssociation.remove( assocName ); - } + // Ignore } } - catch( IOException e ) - { - // Ignore - } - } + } ); } catch( ValueSerializationException | IllegalArgumentException e ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/restlet/src/main/java/org/apache/zest/library/restlet/RestForm.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/RestForm.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/RestForm.java index d3f1f57..f32ac45 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/RestForm.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/RestForm.java @@ -42,12 +42,7 @@ public interface RestForm @Override public FormField field( String name ) { - java.util.Optional<FormField> exists = fields().get().stream().filter( new NameFilter( name ) ).findFirst(); - if( exists.isPresent() ) - { - return exists.get(); - } - return null; + return fields().get().stream().filter( new NameFilter( name ) ).findFirst().orElse( null ); } } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/SmallCrudRepositoryMixin.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/SmallCrudRepositoryMixin.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/SmallCrudRepositoryMixin.java index 85b1e9f..5a92e98 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/SmallCrudRepositoryMixin.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/repository/SmallCrudRepositoryMixin.java @@ -35,7 +35,6 @@ import org.apache.zest.api.unitofwork.EntityTypeNotFoundException; import org.apache.zest.api.unitofwork.NoSuchEntityException; import org.apache.zest.api.unitofwork.UnitOfWork; import org.apache.zest.api.unitofwork.UnitOfWorkFactory; -import org.apache.zest.functional.Specifications; import org.apache.zest.library.restlet.identity.IdentityManager; public class SmallCrudRepositoryMixin<T extends Identity> @@ -102,7 +101,7 @@ public class SmallCrudRepositoryMixin<T extends Identity> @Override public Iterable<T> findAll() { - return find( Specifications.TRUE() ); + return find( item -> true ); } @Override http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/ResourceBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/ResourceBuilder.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/ResourceBuilder.java index 37bb53e..afe2f3a 100644 --- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/ResourceBuilder.java +++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/resource/ResourceBuilder.java @@ -167,7 +167,7 @@ public interface ResourceBuilder @Override public Route findRoute( String name, Router router ) { - return router.getRoutes().stream().filter( route -> name.equals( route.getName() ) ).findFirst().get(); + return router.getRoutes().stream().filter( route -> name.equals( route.getName() ) ).findFirst().orElse( null ); } } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/spring/src/main/java/org/apache/zest/library/spring/bootstrap/internal/service/ServiceFactoryBean.java ---------------------------------------------------------------------- diff --git a/libraries/spring/src/main/java/org/apache/zest/library/spring/bootstrap/internal/service/ServiceFactoryBean.java b/libraries/spring/src/main/java/org/apache/zest/library/spring/bootstrap/internal/service/ServiceFactoryBean.java index eca5e96..1ba8037 100644 --- a/libraries/spring/src/main/java/org/apache/zest/library/spring/bootstrap/internal/service/ServiceFactoryBean.java +++ b/libraries/spring/src/main/java/org/apache/zest/library/spring/bootstrap/internal/service/ServiceFactoryBean.java @@ -54,7 +54,7 @@ public final class ServiceFactoryBean @Override public final Class getObjectType() { - return first( serviceReference.types() ); + return serviceReference.types().findFirst().orElse( null ); } @Override http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/spring/src/main/java/org/apache/zest/library/spring/bootstrap/internal/service/ServiceLocator.java ---------------------------------------------------------------------- diff --git a/libraries/spring/src/main/java/org/apache/zest/library/spring/bootstrap/internal/service/ServiceLocator.java b/libraries/spring/src/main/java/org/apache/zest/library/spring/bootstrap/internal/service/ServiceLocator.java index 043a81a..9b2c867 100644 --- a/libraries/spring/src/main/java/org/apache/zest/library/spring/bootstrap/internal/service/ServiceLocator.java +++ b/libraries/spring/src/main/java/org/apache/zest/library/spring/bootstrap/internal/service/ServiceLocator.java @@ -71,7 +71,7 @@ final class ServiceLocator { layerName = tempLayerName; moduleName = tempModuleName; - serviceType = first( aDescriptor.types() ); + serviceType = aDescriptor.types().findFirst().orElse( null ); } } else if( visited instanceof ObjectDescriptor ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/sql/src/main/java/org/apache/zest/library/sql/datasource/DataSources.java ---------------------------------------------------------------------- diff --git a/libraries/sql/src/main/java/org/apache/zest/library/sql/datasource/DataSources.java b/libraries/sql/src/main/java/org/apache/zest/library/sql/datasource/DataSources.java index ea0c85f..a4953d8 100644 --- a/libraries/sql/src/main/java/org/apache/zest/library/sql/datasource/DataSources.java +++ b/libraries/sql/src/main/java/org/apache/zest/library/sql/datasource/DataSources.java @@ -24,7 +24,6 @@ import javax.sql.DataSource; import org.apache.zest.api.service.ServiceImporterException; import org.apache.zest.library.circuitbreaker.CircuitBreaker; -import static org.apache.zest.functional.Specifications.not; import static org.apache.zest.library.circuitbreaker.CircuitBreakers.in; import static org.apache.zest.library.circuitbreaker.CircuitBreakers.rootCause; @@ -40,7 +39,7 @@ public class DataSources { @SuppressWarnings( "unchecked" ) Predicate<Throwable> in = in( ConnectException.class ); - return new CircuitBreaker( threshold, timeout, not( rootCause( in ) ) ); + return new CircuitBreaker( threshold, timeout, rootCause( in ).negate() ); } public static DataSource wrapWithCircuitBreaker( final String dataSourceIdentity, final DataSource pool, final CircuitBreaker circuitBreaker ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/libraries/sql/src/main/java/org/apache/zest/library/sql/jmx/DataSourceConfigurationManagerService.java ---------------------------------------------------------------------- diff --git a/libraries/sql/src/main/java/org/apache/zest/library/sql/jmx/DataSourceConfigurationManagerService.java b/libraries/sql/src/main/java/org/apache/zest/library/sql/jmx/DataSourceConfigurationManagerService.java index 1a4e812..11e5ce5 100644 --- a/libraries/sql/src/main/java/org/apache/zest/library/sql/jmx/DataSourceConfigurationManagerService.java +++ b/libraries/sql/src/main/java/org/apache/zest/library/sql/jmx/DataSourceConfigurationManagerService.java @@ -47,7 +47,6 @@ import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.mixin.Mixins; import org.apache.zest.api.property.Property; -import org.apache.zest.api.property.PropertyDescriptor; import org.apache.zest.api.service.ServiceComposite; import org.apache.zest.api.service.ServiceImporter; import org.apache.zest.api.service.ServiceReference; @@ -116,7 +115,7 @@ public interface DataSourceConfigurationManagerService @Service ServiceReference<ServiceImporter<DataSource>> dataSourceService; - private List<ObjectName> configurationNames = new ArrayList<ObjectName>(); + private List<ObjectName> configurationNames = new ArrayList<>(); @Override public void exportDataSources() @@ -124,20 +123,20 @@ public interface DataSourceConfigurationManagerService { for ( ServiceReference<DataSource> dataSource : dataSources ) { String name = dataSource.identity(); - Module module = ( Module ) spi.moduleOf( dataSource ); + Module module = spi.moduleOf( dataSource ); EntityDescriptor descriptor = module.entityDescriptor( DataSourceConfiguration.class.getName() ); - List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>(); - Map<String, AccessibleObject> properties = new LinkedHashMap<String, AccessibleObject>(); - for ( PropertyDescriptor persistentProperty : descriptor.state().properties() ) { + List<MBeanAttributeInfo> attributes = new ArrayList<>(); + Map<String, AccessibleObject> properties = new LinkedHashMap<>(); + descriptor.state().properties().forEach(persistentProperty -> { if ( !persistentProperty.isImmutable() ) { String propertyName = persistentProperty.qualifiedName().name(); String type = persistentProperty.valueType().mainType().getName(); attributes.add( new MBeanAttributeInfo( propertyName, type, propertyName, true, true, type.equals( "java.lang.Boolean" ) ) ); properties.put( propertyName, persistentProperty.accessor() ); } - } + } ); - List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>(); + List<MBeanOperationInfo> operations = new ArrayList<>(); operations.add( new MBeanOperationInfo( "restart", "Restart DataSource", new MBeanParameterInfo[ 0 ], "void", MBeanOperationInfo.ACTION_INFO ) ); MBeanInfo mbeanInfo = new MBeanInfo( DataSourceConfiguration.class.getName(), name, attributes.toArray( new MBeanAttributeInfo[ attributes.size() ] ), null, operations.toArray( new MBeanOperationInfo[ operations.size() ] ), null ); @@ -221,11 +220,7 @@ public interface DataSourceConfigurationManagerService try { Object value = getAttribute( name ); list.add( new Attribute( name, value ) ); - } catch ( AttributeNotFoundException e ) { - e.printStackTrace(); - } catch ( MBeanException e ) { - e.printStackTrace(); - } catch ( ReflectionException e ) { + } catch ( AttributeNotFoundException | MBeanException | ReflectionException e ) { e.printStackTrace(); } } @@ -243,13 +238,7 @@ public interface DataSourceConfigurationManagerService try { setAttribute( attribute ); list.add( attribute ); - } catch ( AttributeNotFoundException e ) { - e.printStackTrace(); - } catch ( InvalidAttributeValueException e ) { - e.printStackTrace(); - } catch ( MBeanException e ) { - e.printStackTrace(); - } catch ( ReflectionException e ) { + } catch ( AttributeNotFoundException | InvalidAttributeValueException | ReflectionException | MBeanException e ) { e.printStackTrace(); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/samples/forum/src/main/java/org/apache/zest/sample/forum/assembler/ForumAssembler.java ---------------------------------------------------------------------- diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/assembler/ForumAssembler.java b/samples/forum/src/main/java/org/apache/zest/sample/forum/assembler/ForumAssembler.java index 3b19e63..136ec09 100644 --- a/samples/forum/src/main/java/org/apache/zest/sample/forum/assembler/ForumAssembler.java +++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/assembler/ForumAssembler.java @@ -56,7 +56,6 @@ import org.restlet.service.MetadataService; import static org.apache.zest.api.util.Classes.hasModifier; import static org.apache.zest.api.util.Classes.isAssignableFrom; import static org.apache.zest.functional.Iterables.filter; -import static org.apache.zest.functional.Specifications.not; /** * TODO @@ -106,7 +105,7 @@ public class ForumAssembler LayerAssembly context = assembly.layer( "Context" ).uses( data ); { ModuleAssembly contexts = context.module( "Context" ); - for( Class<?> contextClass : filter( not( hasModifier( Modifier.INTERFACE ) ), ClassScanner.findClasses( Context.class ) ) ) + for( Class<?> contextClass : filter( hasModifier( Modifier.INTERFACE ).negate(), ClassScanner.findClasses( Context.class ) ) ) { if( contextClass.getName().contains( "$" ) ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/samples/rental/src/main/java/org/apache/zest/sample/rental/web/Page.java ---------------------------------------------------------------------- diff --git a/samples/rental/src/main/java/org/apache/zest/sample/rental/web/Page.java b/samples/rental/src/main/java/org/apache/zest/sample/rental/web/Page.java index 824b9cc..a3aafc1 100644 --- a/samples/rental/src/main/java/org/apache/zest/sample/rental/web/Page.java +++ b/samples/rental/src/main/java/org/apache/zest/sample/rental/web/Page.java @@ -89,9 +89,8 @@ public interface Page private void execute( QuikitContext context, Element element, Element parent ) throws RenderException { - Class<? extends Composite> compositeType = (Class<Composite>) first( ZestAPI.FUNCTION_DESCRIPTOR_FOR - .apply( context.page() ) - .types() ); + Class<? extends Composite> compositeType = + (Class<Composite>) ZestAPI.FUNCTION_DESCRIPTOR_FOR.apply( context.page() ).types().findFirst().orElse( null ); try { Method method = findMethod( context.methodName(), compositeType ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/bd6fbad9/samples/rental/src/main/java/org/apache/zest/sample/rental/web/QuikitServlet.java ---------------------------------------------------------------------- diff --git a/samples/rental/src/main/java/org/apache/zest/sample/rental/web/QuikitServlet.java b/samples/rental/src/main/java/org/apache/zest/sample/rental/web/QuikitServlet.java index 4bad67d..df063bc 100644 --- a/samples/rental/src/main/java/org/apache/zest/sample/rental/web/QuikitServlet.java +++ b/samples/rental/src/main/java/org/apache/zest/sample/rental/web/QuikitServlet.java @@ -194,8 +194,8 @@ public class QuikitServlet private void renderPage( Page page, String path, PrintWriter output, HttpServletRequest httpRequest ) throws ParserConfigurationException, SAXException, IOException, RenderException, TransformerException { - Class<? extends Composite> pageClass = (Class<Composite>) first( ZestAPI.FUNCTION_DESCRIPTOR_FOR - .apply( page ).types() ); + Class<? extends Composite> pageClass = + (Class<Composite>) ZestAPI.FUNCTION_DESCRIPTOR_FOR.apply( page ).types().findFirst().orElse( null ); String pageName = pageClass.getSimpleName() + ".html"; DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder();
