You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by ma...@apache.org on 2023/10/13 06:35:32 UTC

[incubator-kie-drools] branch main updated: DROOLS-7552: improve updateObjectTypesList() (#5552)

This is an automated email from the ASF dual-hosted git repository.

mariofusco pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git


The following commit(s) were added to refs/heads/main by this push:
     new d62dde5af1 DROOLS-7552: improve updateObjectTypesList() (#5552)
d62dde5af1 is described below

commit d62dde5af1ff99d4f0419c15811de9eebf7d50f8
Author: nprentza <90...@users.noreply.github.com>
AuthorDate: Fri Oct 13 09:35:26 2023 +0300

    DROOLS-7552: improve updateObjectTypesList() (#5552)
    
    * updateObjectTypesList() improvements
    
    * use isEmpty with findAny
---
 .../SimpleSerializationReliableRefObjectStore.java | 28 +++++++---------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/SimpleSerializationReliableRefObjectStore.java b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/SimpleSerializationReliableRefObjectStore.java
index 53edfafa26..747df903ef 100644
--- a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/SimpleSerializationReliableRefObjectStore.java
+++ b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/SimpleSerializationReliableRefObjectStore.java
@@ -23,23 +23,20 @@ import org.drools.core.common.Storage;
 
 import java.lang.reflect.Field;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.IdentityHashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 
 public class SimpleSerializationReliableRefObjectStore extends SimpleSerializationReliableObjectStore {
 
-    private Map<String, Long> uniqueObjectTypesInStore;  // object type name, occurances
+    private Set<String> uniqueObjectTypesInStorage;
     private transient IdentityHashMap<Object, Long> inverseStorage;
 
     public SimpleSerializationReliableRefObjectStore(Storage<Long, StoredObject> storage) {
         super(storage);
-        uniqueObjectTypesInStore = new HashMap<>();
+        uniqueObjectTypesInStorage = new HashSet<>();
         setInverseStorage(storage);
         if (!storage.isEmpty()) {
             updateObjectTypesList();
@@ -119,32 +116,25 @@ public class SimpleSerializationReliableRefObjectStore extends SimpleSerializati
 
     private List<Field> getReferencedObjects(Object object) {
         Field[] fields = object.getClass().getDeclaredFields();
-
         return Arrays.stream(fields)
-                .filter(field -> uniqueObjectTypesInStore.containsKey(field.getType().getName()))
+                .filter(field -> uniqueObjectTypesInStorage.contains(field.getType().getName()))
                 .collect(Collectors.toList());
     }
 
     private void updateObjectTypesList(Object object) {
-        uniqueObjectTypesInStore.put(object.getClass().getName(),
-                storage.values().stream().filter(sObject -> sObject.getObject().getClass().equals(object.getClass())).count());
-        // if count==0 then remove entry
-        if (uniqueObjectTypesInStore.get(object.getClass().getName()) == 0) {
-            uniqueObjectTypesInStore.remove(object.getClass().getName());
+        if (!inverseStorage.keySet().stream().filter(sObject -> sObject.getClass().equals(object.getClass())).findAny().isEmpty()){
+            uniqueObjectTypesInStorage.add(object.getClass().getName());
+        }else{
+            uniqueObjectTypesInStorage.remove(object.getClass().getName());
         }
     }
 
     private void updateObjectTypesList() {
         // list of unique object types in storage
-        Set<String> uTypeNames = new HashSet<String>();
+        uniqueObjectTypesInStorage.clear();
         storage.values().forEach(sObject -> {
-            uTypeNames.add(sObject.getObject().getClass().getName());
+            uniqueObjectTypesInStorage.add(sObject.getObject().getClass().getName());
         });
-        // add unique object types + their occurrences in the uniqueObjectTypesInStore
-        uniqueObjectTypesInStore.putAll(storage.values().stream()
-                .map(sObject -> sObject.getObject().getClass().getName())
-                .filter(uTypeNames::contains)
-                .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())));
     }
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org