
// ValsMap.java
// Andrew Davison, ad@coe.psu.ac.th, Dec. 2022

/* Creates a map of an integer value to a list of
   variable names/labels. 

   It is used by JacopUtils.printGrouped() to collect 
   together all the variables with the same value so
   they can be printed in groups.
*/


import java.util.*;


public class ValsMap
{
  private TreeMap<Integer, List<String>> map;

  public ValsMap()
  {  map = new TreeMap<>();  }


  public void add(int val, String label)
  {
    List<String> labels = map.get(val);
    if (labels == null) {
      List<String> lbs = new ArrayList<>();
      lbs.add(label);
      map.put(val, lbs);
    }
    else {
      if (!labels.contains(label))
        labels.add(label);
      map.put(val, labels);
    }
  }  // end of add()


  public List<String> getLabel(int val)
  {  return map.get(val);  }


  public void print()
  {
    for (Integer val : map.keySet())
      System.out.println(val + " : " + map.get(val));
  }  // end of print()


}  // end of ValsMap class