From e7bc8f1fcf6c9c3a10131ca095f451a7e1017334 Mon Sep 17 00:00:00 2001
From: Dominique Marcadet <Dominique.Marcadet@centralesupelec.fr>
Date: Wed, 15 May 2019 16:43:34 +0200
Subject: [PATCH] correct AtMostOne condition

---
 .../nsd/PresenceConditionValidator.java       | 50 +++++++------------
 1 file changed, 17 insertions(+), 33 deletions(-)

diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/PresenceConditionValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/PresenceConditionValidator.java
index b33a316..2d674e7 100644
--- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/PresenceConditionValidator.java
+++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/PresenceConditionValidator.java
@@ -63,7 +63,7 @@ public class PresenceConditionValidator {
     private HashSet< String > mandatoryMulti;
     private HashSet< String > optionalMulti;
     private HashMap< Integer, HashSet< String > > atLeastOne;
-    private HashMap< Integer, HashSet< String > > atMostOne;
+    private HashSet< String > atMostOne;
     private HashMap< Integer, HashSet< String > > allOrNonePerGroup;
     private HashMap< Integer, HashSet< String > > allOnlyOneGroup;
     private HashMap< Integer, HashSet< String > > allAtLeastOneGroup;
@@ -183,23 +183,9 @@ public class PresenceConditionValidator {
             }
         case "AtMostOne" :
             // At most one of marked elements shall be present
-            if( atMostOne == null ) atMostOne = new HashMap<>();
-            try {
-                Integer arg = Integer.valueOf( presCondArgs );
-                if( arg <= 0 ) {
-                    console.warning( "NSD: argument of PresenceCondition \"AtMostOne\" is not a positive integer" );
-                    break;
-                }
-                if( ! atMostOne.containsKey( arg )) {
-                    atMostOne.put( arg, new HashSet<>() );
-                }
-                atMostOne.get( arg ).add( name );
-                break;
-            }
-            catch( NumberFormatException e ) {
-                console.warning( "NSD: argument of PresenceCondition \"AtMostOne\" is not an integer" );
-                break;
-            }
+            if( atMostOne == null ) atMostOne = new HashSet<>();
+            atMostOne.add( name );
+            break;
         case "AllOrNonePerGroup" :
             // Parameter n: group number (> 0).
             // All or none of the elements of a group n shall be present
@@ -794,23 +780,21 @@ public class PresenceConditionValidator {
         // At most one of marked elements shall be present
         // Usage in standard NSD files (version 2007B): DataObject
         if( atMostOne != null ) {
-            for( Entry< Integer, HashSet< String > > e1 : atMostOne.entrySet() ) {
-                int groupCount = 0;
-                for( String member : e1.getValue() ) {
-                    if( presentDO.get( member ) != null ) {
-                        ++groupCount;
-                    }
-                }
-                if( groupCount > 1 ) {
-                    diagnostics.add( new BasicDiagnostic(
-                            Diagnostic.ERROR,
-                            RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
-                            0,
-                            "[NSD] group " + e1.getKey() + " has more than one element in LNodeType (line " + lNodeType.getLineNumber() + ") with LNClass " + anyLNClassName,
-                            new Object[] { lNodeType } ));
-                    res = false;
+            int count = 0;
+            for( String s : atMostOne ) {
+                if( presentDO.get( s ) != null ) {
+                    ++count;
                 }
             }
+            if( count > 1 ) {
+                diagnostics.add( new BasicDiagnostic(
+                        Diagnostic.ERROR,
+                        RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
+                        0,
+                        "[NSD] LNodeType (line " + lNodeType.getLineNumber() + ") with LNClass " + anyLNClassName + " has more than one element marked AtMostOne",
+                        new Object[] { lNodeType } ));
+                res = false;
+            }
         }
         
         // presCond: "AllOrNonePerGroup" :
-- 
GitLab