<commit_before>package natlab.tame.valueanalysis;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import natlab.tame.classes.reference.ClassReference;
import natlab.tame.valueanalysis.value.Value;
import natlab.toolkits.analysis.Mergable;

/**
 * This represents a set of values that a variable can take on.
 * It is actually a map from ClassReference -> AbstractValue.
 * Objects of this class are immutable.
 * Note that this class uses factory method (newInstance) rather than constructors.
 * 
 * @author ant6n
 * 
 * Note about implementation: this will only actually use a map if there is more
 * than element stored by this set. If there is one, a singleton value is used.
 * This should be ok since this class is immutable.
 */
public class ValueSet<V extends Value<V>> implements 
  Iterable<V>, Mergable<ValueSet<V>>{
    LinkedHashMap<ClassReference, V> map = null;
    V singleton = null; //used if this value set only stores one value
    int size = 0; //number of elements in this
    public static boolean DEBUG = false;
    
    private ValueSet(){}
    public  static <V extends Value<V>> ValueSet<V> newInstance(){
        return new ValueSet<V>();
    }
    
    private ValueSet(Map<ClassReference, V> aMap){
        if (aMap.size() == 0) return;            
        if (aMap.size() == 1){
            size = 1;
            singleton = aMap.values().iterator().next();
        } else {
            map = new LinkedHashMap<ClassReference, V>();
            map.putAll(aMap);
            size = aMap.size();
        }
    }
    public static <V extends Value<V>> ValueSet<V> newInstance(Map<ClassReference, V> aMap){
        return new ValueSet<V>(aMap);<commit_msg>Xu added one method in this file to just return singleton(nothing else) and I comment where I add this method.<commit_after>package natlab.tame.valueanalysis;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import natlab.tame.classes.reference.ClassReference;
import natlab.tame.valueanalysis.value.Value;
import natlab.toolkits.analysis.Mergable;

/**
 * This represents a set of values that a variable can take on.
 * It is actually a map from ClassReference -> AbstractValue.
 * Objects of this class are immutable.
 * Note that this class uses factory method (newInstance) rather than constructors.
 * 
 * @author ant6n
 * 
 * Note about implementation: this will only actually use a map if there is more
 * than element stored by this set. If there is one, a singleton value is used.
 * This should be ok since this class is immutable.
 */
public class ValueSet<V extends Value<V>> implements 
  Iterable<V>, Mergable<ValueSet<V>>{
    LinkedHashMap<ClassReference, V> map = null;
    V singleton = null; //used if this value set only stores one value
    int size = 0; //number of elements in this
    public static boolean DEBUG = false;
    
    //Xu add this method for code generation
    public V getSingleton(){
    	return singleton;
    }
    
    private ValueSet(){}
    public  static <V extends Value<V>> ValueSet<V> newInstance(){
        return new ValueSet<V>();
    }
    
    private ValueSet(Map<ClassReference, V> aMap){
        if (aMap.size() == 0) return;            
        if (aMap.size() == 1){
            size = 1;
            singleton = aMap.values().iterator().next();
        } else {
            map = new LinkedHashMap<ClassReference, V>();
            map.putAll(aMap);
            size = aMap.size();
        }
    }
    public static <V extends Value<V>> ValueSet<V> newInstance(Map<ClassReference, V> aMap){
        return new ValueSet<V>(aMap);
{'fraction_non_alphanumeric': 0.10023012017386858, 'fraction_numerical': 0.0025568908207619537, 'mean_word_length': 3.0665280665280665, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3870206', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1115, 'n_words': 400}