polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [5/7] polygene-java git commit: :core:spi refine
Date Sun, 14 May 2017 14:33:22 GMT
:core:spi refine

- prefer lambdas over anonymous classes
- prefer iterating over map entries
- prefer map.computeIfAbsent()
- remove unused imports
- formatting


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/ef4d38ed
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/ef4d38ed
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/ef4d38ed

Branch: refs/heads/develop
Commit: ef4d38ed8a41a0d5e1bad5959d9a9ad0d82d05c6
Parents: c24023e
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Sun May 14 16:21:13 2017 +0200
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Sun May 14 16:21:13 2017 +0200

----------------------------------------------------------------------
 .../serialization/javaxjson/JavaxJsonAdapter.java |  1 -
 .../javaxjson/JavaxJsonFactories.java             |  1 -
 .../javaxjson/JavaxJsonSerializer.java            | 15 +++++++--------
 .../entitystore/helpers/DefaultEntityState.java   | 18 +++++-------------
 .../helpers/JSONMapEntityStoreMixin.java          | 15 ++++++---------
 5 files changed, 18 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ef4d38ed/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonAdapter.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonAdapter.java
b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonAdapter.java
index c55690b..eaaa986 100644
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonAdapter.java
+++ b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonAdapter.java
@@ -19,7 +19,6 @@ package org.apache.polygene.serialization.javaxjson;
 
 import java.util.function.BiFunction;
 import java.util.function.Function;
-import javax.json.JsonBuilderFactory;
 import javax.json.JsonValue;
 import org.apache.polygene.api.type.ValueType;
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ef4d38ed/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonFactories.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonFactories.java
b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonFactories.java
index e691802..0a790f2 100644
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonFactories.java
+++ b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonFactories.java
@@ -19,7 +19,6 @@ package org.apache.polygene.serialization.javaxjson;
 
 import java.util.Arrays;
 import java.util.List;
-import javax.json.Json;
 import javax.json.JsonArray;
 import javax.json.JsonArrayBuilder;
 import javax.json.JsonBuilderFactory;

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ef4d38ed/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
index 0222f9c..065e28b 100644
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
+++ b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
@@ -222,19 +222,18 @@ public class JavaxJsonSerializer extends AbstractTextSerializer
         if( map.keySet().stream().allMatch( characterKeyPredicate ) )
         {
             JsonObjectBuilder builder = jsonFactories.builderFactory().createObjectBuilder();
-            map.entrySet().forEach( entry -> builder.add( entry.getKey().toString(),
-                                                          doSerialize( options, entry.getValue(),
false ) ) );
+            map.forEach( ( key, value ) -> builder.add( key.toString(),
+                                                        doSerialize( options, value, false
) ) );
             return builder.build();
         }
         else
         {
             JsonArrayBuilder builder = jsonFactories.builderFactory().createArrayBuilder();
-            map.entrySet().forEach(
-                entry -> builder.add(
-                    jsonFactories.builderFactory().createObjectBuilder()
-                                 .add( "key", doSerialize( options, entry.getKey(), false
) )
-                                 .add( "value", doSerialize( options, entry.getValue(), false
) )
-                                 .build() ) );
+            map.forEach( ( key, value ) -> builder.add(
+                jsonFactories.builderFactory().createObjectBuilder()
+                             .add( "key", doSerialize( options, key, false ) )
+                             .add( "value", doSerialize( options, value, false ) )
+                             .build() ) );
             return builder.build();
         }
     }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ef4d38ed/core/spi/src/main/java/org/apache/polygene/spi/entitystore/helpers/DefaultEntityState.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/spi/entitystore/helpers/DefaultEntityState.java
b/core/spi/src/main/java/org/apache/polygene/spi/entitystore/helpers/DefaultEntityState.java
index 10c43fe..2926b8c 100644
--- a/core/spi/src/main/java/org/apache/polygene/spi/entitystore/helpers/DefaultEntityState.java
+++ b/core/spi/src/main/java/org/apache/polygene/spi/entitystore/helpers/DefaultEntityState.java
@@ -59,7 +59,7 @@ public final class DefaultEntityState
     {
         this( "",
               currentTime,
-                reference,
+              reference,
               EntityStatus.NEW,
               entityDescriptor,
               new HashMap<>(),
@@ -138,24 +138,16 @@ public final class DefaultEntityState
     @Override
     public ManyAssociationState manyAssociationValueOf( QualifiedName stateName )
     {
-        List<EntityReference> manyAssociationState = manyAssociations.get( stateName
);
-        if( manyAssociationState == null )
-        {
-            manyAssociationState = new ArrayList<>();
-            manyAssociations.put( stateName, manyAssociationState );
-        }
+        List<EntityReference> manyAssociationState = manyAssociations.computeIfAbsent(
+            stateName, key -> new ArrayList<>() );
         return new DefaultManyAssociationState( this, manyAssociationState );
     }
 
     @Override
     public NamedAssociationState namedAssociationValueOf( QualifiedName stateName )
     {
-        Map<String, EntityReference> namedAssociationState = namedAssociations.get(
stateName );
-        if( namedAssociationState == null )
-        {
-            namedAssociationState = new LinkedHashMap<>();
-            namedAssociations.put( stateName, namedAssociationState );
-        }
+        Map<String, EntityReference> namedAssociationState = namedAssociations.computeIfAbsent(
+            stateName, key -> new LinkedHashMap<>() );
         return new DefaultNamedAssociationState( this, namedAssociationState );
     }
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ef4d38ed/core/spi/src/main/java/org/apache/polygene/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
b/core/spi/src/main/java/org/apache/polygene/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
index d593eb0..bc715b7 100644
--- a/core/spi/src/main/java/org/apache/polygene/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
+++ b/core/spi/src/main/java/org/apache/polygene/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
@@ -93,7 +93,7 @@ public class JSONMapEntityStoreMixin
     private JavaxJsonFactories jsonFactories;
 
     @Service
-    IdentityGenerator identityGenerator;
+    private IdentityGenerator identityGenerator;
 
     @Optional
     @Service
@@ -241,7 +241,7 @@ public class JSONMapEntityStoreMixin
     }
 
     @Override
-    public StateCommitter applyChanges( EntityStoreUnitOfWork uow, Iterable<EntityState>
state )
+    public StateCommitter applyChanges( EntityStoreUnitOfWork uow, Iterable<EntityState>
entityStates )
         throws EntityStoreException
     {
         return new StateCommitter()
@@ -251,10 +251,8 @@ public class JSONMapEntityStoreMixin
             {
                 try
                 {
-                    mapEntityStore.applyChanges( new MapEntityStore.MapChanges()
-                    {
-                        @Override
-                        public void visitMap( MapEntityStore.MapChanger changer ) throws
Exception
+                    mapEntityStore.applyChanges(
+                        changer ->
                         {
                             CacheOptions options = uow.usecase().metaInfo( CacheOptions.class
);
                             if( options == null )
@@ -262,7 +260,7 @@ public class JSONMapEntityStoreMixin
                                 options = CacheOptions.ALWAYS;
                             }
 
-                            for( EntityState entityState : state )
+                            for( EntityState entityState : entityStates )
                             {
                                 JSONEntityState state = (JSONEntityState) entityState;
                                 String newVersion = uow.identity().toString();
@@ -302,8 +300,7 @@ public class JSONMapEntityStoreMixin
                                     cache.remove( state.entityReference().identity().toString()
);
                                 }
                             }
-                        }
-                    } );
+                        } );
                 }
                 catch( Exception e )
                 {


Mime
View raw message