sebwrede commented on a change in pull request #946:
URL: https://github.com/apache/systemml/pull/946#discussion_r441446884



##########
File path: src/main/java/org/apache/sysds/runtime/privacy/PrivacyMonitor.java
##########
@@ -30,23 +30,33 @@
 import org.apache.sysds.runtime.privacy.PrivacyConstraint.PrivacyLevel;
 
 public class PrivacyMonitor 
-{
-       //TODO maybe maintain a log of checked constaints for transfers
-       // in order to provide 'privacy explanations' similar to our stats 
-       private static ConcurrentHashMap<PrivacyLevel,LongAdder> 
checkedConstraints = new ConcurrentHashMap<PrivacyLevel,LongAdder>();
+{ 
+       private static HashMap<PrivacyLevel,LongAdder> checkedConstraints;
+
+       static {
+               checkedConstraints = new HashMap<PrivacyLevel,LongAdder>();
+               for ( PrivacyLevel level : PrivacyLevel.values() ){
+                       checkedConstraints.put(level, new LongAdder());
+               }
+       }
+
        private static boolean checkPrivacy = false;
 
-       public static ConcurrentHashMap<PrivacyLevel,LongAdder> 
getCheckedConstraints(){
+       public static HashMap<PrivacyLevel,LongAdder> getCheckedConstraints(){
                return checkedConstraints;
        }
 
        private static void incrementCheckedConstraints(PrivacyLevel 
privacyLevel){
-               if ( checkPrivacy )
-                       checkedConstraints.computeIfAbsent(privacyLevel, k -> 
new LongAdder()).increment();
+               if ( checkPrivacy ){
+                       if ( privacyLevel == null )
+                               throw new NullPointerException("Cannot 
increment checked constraints log: Privacy level is null.");
+                       checkedConstraints.get(privacyLevel).increment();
+               }
+                       
        }
 
        public static void clearCheckedConstraints(){
-               checkedConstraints.clear();
+               checkedConstraints.replaceAll((k,v)->new LongAdder());

Review comment:
       But I only add new key types very rarely. It is the PrivacyLevel enum, 
which only has three different types right now. When it comes to the code, the 
current implementation would not require me to change anything in this map in 
PrivacyMonitor. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to