1   package eu.fbk.dkm.premon.util;
2   
3   import javax.annotation.Nullable;
4   
5   /**
6    * Created by alessio on 09/10/15.
7    */
8   
9   public class NF {
10  
11      private String n;
12      private String f;
13  
14      public static final String AGENT = "a";
15      public static final String MOD = "mod";
16  
17      public NF(@Nullable String n, @Nullable String f) {
18  
19          // This is about n
20  
21          if (n != null && n.length() > 0) {
22  
23  				/*
24                  Property 'n' should be a number, 'm' or 'a'
25  				- number: is the arg-N (usually arg-0 is the agent)
26  				- 'a': arg-0 is not the agent
27  				- 'm': see property 'f'
28  
29  				Note: when n='a' => f=''
30  				*/
31  
32              // Bug: hunker-v.xml
33              if (n.toLowerCase().equals("dir")) {
34                  n = "m";
35                  f = "dir";
36              }
37  
38              // Bug: go-v.xml
39              if (n.toLowerCase().equals("argm-adv")) {
40                  n = "m";
41                  f = "adv";
42              }
43          } else {
44              n = null;
45          }
46  
47          if (n != null) {
48              n = n.toLowerCase();
49          }
50  
51          // This is about f
52  
53          if (f == null || f.length() <= 0) {
54              f = null;
55          }
56  
57          if (f != null) {
58              f = f.toLowerCase();
59              if (f.equals("str")) {
60                  f = null;
61              }
62          }
63  
64          this.n = n;
65          this.f = f;
66      }
67  
68      public String getArgName() {
69          if (n != null) {
70              if (n.equals("a")) {
71                  return AGENT;
72              } else if (n.equals("m")) {
73                  if (f != null) {
74                      return f;
75                  } else {
76                      //todo: if n='m' the attribute f should be populated, but it's not always true (see abandon-v.xml)
77                      // return MOD;
78                      return null; // FC: this will discard the role
79                  }
80              } else {
81                  return n;
82              }
83          }
84  
85          return f;
86      }
87  
88      public String getN() {
89          return n;
90      }
91  
92      public String getF() {
93          return f;
94      }
95  
96      @Override public String toString() {
97          return "NF{" +
98                  "n='" + n + '\'' +
99                  ", f='" + f + '\'' +
100                 '}';
101     }
102 }