| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-07-19 20:24:40 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-07-19 20:24:40 +0200 | 
| commit | 158f8ef180d4ea448b351599529db53ff5e88f8c (patch) | |
| tree | 2982efaacb22dea8fb86850abc149b768ee428db /ast-to-instr/src/IDs.java | |
| parent | 0362751e41f731b22b7bfe511af4aa71a02be70a (diff) | |
Starting a Java implementation of ast-to-instr.
Keeping things clean, this time.
Diffstat (limited to 'ast-to-instr/src/IDs.java')
| -rw-r--r-- | ast-to-instr/src/IDs.java | 78 | 
1 files changed, 78 insertions, 0 deletions
| diff --git a/ast-to-instr/src/IDs.java b/ast-to-instr/src/IDs.java new file mode 100644 index 0000000..e3b9db4 --- /dev/null +++ b/ast-to-instr/src/IDs.java @@ -0,0 +1,78 @@ +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.HashMap; + +public class IDs +{ +   /** Static *****************************************************************/ +   private static final Map<String, IDs> FROM_XML; +   private static final Collection<IDs> ALL_IDS; +   private static int next_id; + +   static +   { +      next_id = 0; + +      FROM_XML = new HashMap<String, IDs>(); +      ALL_IDS = new ArrayList<IDs>(); +   } + + +   public static IDs get_id_from_xml_id +   ( +      final String xml_id, +      final String type +   ) +   { +      IDs result; + +      result = FROM_XML.get(xml_id); + +      if (result == null) +      { +         result = new IDs(type); + +         FROM_XML.put(xml_id, result); +      } + +      return result; +   } + +   public static IDs generate_new_id +   ( +      final String type +   ) +   { +      final IDs result; + +      result = new IDs(type); + +      ALL_IDS.add(result); + +      return result; +   } + +   /** Non-Static *************************************************************/ +   private final String type; +   private final int value; + +   private IDs (final String type) +   { +      this.type = type; + +      value = IDs.next_id; + +      IDs.next_id += 1; +   } + +   public String get_type () +   { +      return type; +   } + +   public int get_value () +   { +      return value; +   } +} | 


