Program: 107968
Project: 107968
Buggy source:
/** 
 * Creates a new data manager from pre-encoded data.
 * @param header
 * @param data
 * @param dictionary
 * @param definition
 * @param criteria
 * @param function
 */
public DataManager(final String[] header,final int[][] data,final Dictionary dictionary,final DataDefinition definition,final Set<PrivacyCriterion> criteria,final Map<String,DistributionAggregateFunction> functions){
  this.header=header;
  Set<String> attributesGemeralized=definition.getQuasiIdentifiersWithGeneralization();
  Set<String> attributesSensitive=definition.getSensitiveAttributes();
  Set<String> attributesMicroaggregated=definition.getQuasiIdentifiersWithMicroaggregation();
  Set<String> attributesInsensitive=definition.getInsensitiveAttributes();
  final Dictionary dictionaryGeneralized=new Dictionary(attributesGemeralized.size());
  final Dictionary dictionaryAnalyzed=new Dictionary(attributesSensitive.size() + attributesMicroaggregated.size());
  final Dictionary dictionaryStatic=new Dictionary(attributesInsensitive.size());
  final int[] mapGeneralized=new int[dictionaryGeneralized.getNumDimensions()];
  final int[] mapAnalyzed=new int[dictionaryAnalyzed.getNumDimensions()];
  final int[] mapStatic=new int[dictionaryStatic.getNumDimensions()];
  this.microaggregationMap=new int[attributesMicroaggregated.size()];
  this.microaggregationStartIndex=attributesSensitive.size();
  this.microaggregationNumAttributes=attributesMicroaggregated.size();
  int indexStatic=0;
  int indexGeneralized=0;
  int indexAnalyzed=0;
  int indexSensitive=0;
  int indexMicroaggregated=this.microaggregationStartIndex;
  int counter=0;
  final int[] map=new int[header.length * 2];
  final String[] headerGH=new String[dictionaryGeneralized.getNumDimensions()];
  final String[] headerDI=new String[dictionaryAnalyzed.getNumDimensions()];
  final String[] headerIS=new String[dictionaryStatic.getNumDimensions()];
  microaggregationHeader=new String[attributesMicroaggregated.size()];
  for (  final String column : header) {
    final int idx=counter * 2;
    if (attributesGemeralized.contains(column)) {
      map[idx]=AttributeTypeInternal.QUASI_IDENTIFYING_GENERALIZED;
      map[idx + 1]=indexGeneralized;
      mapGeneralized[indexGeneralized]=counter;
      dictionaryGeneralized.registerAll(indexGeneralized,dictionary,counter);
      headerGH[indexGeneralized]=header[counter];
      indexGeneralized++;
    }
 else     if (attributesMicroaggregated.contains(column)) {
      map[idx]=AttributeTypeInternal.QUASI_IDENTIFYING_MICROAGGREGATED;
      map[idx + 1]=indexMicroaggregated;
      mapAnalyzed[indexMicroaggregated]=counter;
      dictionaryAnalyzed.registerAll(indexMicroaggregated,dictionary,counter);
      headerDI[indexMicroaggregated]=header[counter];
      indexMicroaggregated++;
      microaggregationMap[indexAnalyzed]=counter;
      microaggregationHeader[indexAnalyzed]=header[counter];
      indexAnalyzed++;
    }
 else     if (attributesInsensitive.contains(column)) {
      map[idx]=AttributeTypeInternal.INSENSITIVE;
      map[idx + 1]=indexStatic;
      mapStatic[indexStatic]=counter;
      dictionaryStatic.registerAll(indexStatic,dictionary,counter);
      headerIS[indexStatic]=header[counter];
      indexStatic++;
    }
 else     if (attributesSensitive.contains(column)) {
      map[idx]=AttributeTypeInternal.SENSITIVE;
      map[idx + 1]=indexSensitive;
      mapAnalyzed[indexSensitive]=counter;
      dictionaryAnalyzed.registerAll(indexSensitive,dictionary,counter);
      headerDI[indexSensitive]=header[counter];
      indexSensitive++;
    }
 else {
      map[idx]=AttributeTypeInternal.IDENTIFYING;
      map[idx + 1]=-1;
    }
    counter++;
  }
  final Data[] ddata=encode(data,map,mapGeneralized,mapAnalyzed,mapStatic,dictionaryGeneralized,dictionaryAnalyzed,dictionaryStatic,headerGH,headerDI,headerIS);
  dataGeneralized=ddata[0];
  dataAnalyzed=ddata[1];
  dataStatic=ddata[2];
  minLevels=new int[attributesGemeralized.size()];
  hierarchiesHeights=new int[attributesGemeralized.size()];
  maxLevels=new int[attributesGemeralized.size()];
  hierarchiesGeneralized=new GeneralizationHierarchy[attributesGemeralized.size()];
  for (int i=0; i < header.length; i++) {
    final int idx=i * 2;
    if (attributesGemeralized.contains(header[i]) && map[idx] == AttributeTypeInternal.QUASI_IDENTIFYING_GENERALIZED) {
      final int dictionaryIndex=map[idx + 1];
      final String name=header[i];
      if (definition.getHierarchy(name) != null) {
        hierarchiesGeneralized[dictionaryIndex]=new GeneralizationHierarchy(name,definition.getHierarchy(name),dictionaryIndex,dictionaryGeneralized);
      }
 else {
        throw new IllegalStateException("String_Node_Str" + header[i] + "String_Node_Str");
      }
      hierarchiesHeights[dictionaryIndex]=hierarchiesGeneralized[dictionaryIndex].getArray()[0].length;
      final Integer minGenLevel=definition.getMinimumGeneralization(name);
      minLevels[dictionaryIndex]=minGenLevel == null ? 0 : minGenLevel;
      final Integer maxGenLevel=definition.getMaximumGeneralization(name);
      maxLevels[dictionaryIndex]=maxGenLevel == null ? hierarchiesHeights[dictionaryIndex] - 1 : maxGenLevel;
    }
  }
  for (  PrivacyCriterion c : criteria) {
    if (c instanceof EDDifferentialPrivacy) {
      DataGeneralizationScheme scheme=((EDDifferentialPrivacy)c).getGeneralizationScheme();
      for (int i=0; i < header.length; i++) {
        final int idx=i * 2;
        if (attributesGemeralized.contains(header[i]) && map[idx] == AttributeTypeInternal.QUASI_IDENTIFYING_GENERALIZED) {
          minLevels[map[idx + 1]]=scheme.getGeneralizationLevel(header[i],definition);
          maxLevels[map[idx + 1]]=scheme.getGeneralizationLevel(header[i],definition);
        }
      }
      break;
    }
  }
  Map<String,String[][]> sensitiveHierarchies=new HashMap<String,String[][]>();
  for (  PrivacyCriterion c : criteria) {
    if (c instanceof HierarchicalDistanceTCloseness) {
      HierarchicalDistanceTCloseness t=(HierarchicalDistanceTCloseness)c;
      sensitiveHierarchies.put(t.getAttribute(),t.getHierarchy().getHierarchy());
    }
  }
  hierarchiesSensitive=new HashMap<String,GeneralizationHierarchy>();
  indexesSensitive=new HashMap<String,Integer>();
  int index=0;
  for (int i=0; i < header.length; i++) {
    final String name=header[i];
    final int idx=i * 2;
    if (sensitiveHierarchies.containsKey(name) && map[idx] == AttributeTypeInternal.SENSITIVE) {
      final int dictionaryIndex=map[idx + 1];
      final String[][] hiers=sensitiveHierarchies.get(name);
      if (hiers != null) {
        hierarchiesSensitive.put(name,new GeneralizationHierarchy(name,hiers,dictionaryIndex,dictionaryAnalyzed));
      }
    }
    if (attributesSensitive.contains(header[i])) {
      indexesSensitive.put(name,index);
      index++;
    }
  }
  Map<String,String[][]> maHierarchies=new HashMap<String,String[][]>();
  for (  String attribute : functions.keySet()) {
    if (functions.get(attribute) instanceof DistributionAggregateFunctionGeneralization) {
      maHierarchies.put(attribute,definition.getHierarchy(attribute));
    }
  }
  Map<String,int[][]> hierarchiesMA=new HashMap<String,int[][]>();
  index=0;
  for (int i=0; i < header.length; i++) {
    final String name=header[i];
    final int idx=i * 2;
    if (maHierarchies.containsKey(name) && map[idx] == AttributeTypeInternal.QUASI_IDENTIFYING_MICROAGGREGATED) {
      final int dictionaryIndex=map[idx + 1];
      final String[][] hiers=maHierarchies.get(name);
      if (hiers != null) {
        hierarchiesMA.put(name,new GeneralizationHierarchy(name,hiers,dictionaryIndex,dictionaryAnalyzed).map);
      }
    }
  }
  dictionaryGeneralized.finalizeAll();
  dictionaryAnalyzed.finalizeAll();
  dictionaryStatic.finalizeAll();
  microaggregationFunctions=new DistributionAggregateFunction[attributesMicroaggregated.size()];
  for (int i=0; i < header.length; i++) {
    final int idx=i * 2;
    if (attributesMicroaggregated.contains(header[i]) && map[idx] == AttributeTypeInternal.QUASI_IDENTIFYING_MICROAGGREGATED) {
      final int dictionaryIndex=map[idx + 1] - microaggregationStartIndex;
      final String name=header[i];
      if (definition.getMicroAggregationFunction(name) != null) {
        microaggregationFunctions[dictionaryIndex]=functions.get(name);
        microaggregationFunctions[dictionaryIndex].initialize(dictionaryAnalyzed.getMapping()[dictionaryIndex + microaggregationStartIndex],definition.getDataType(name),hierarchiesMA.get(name));
      }
 else {
        throw new IllegalStateException("String_Node_Str" + header[i] + "String_Node_Str");
      }
    }
  }
  for (  PrivacyCriterion c : criteria) {
    if (c.getSubset() != null) {
      subset=c.getSubset().getSet();
      subsetSize=c.getSubset().getArray().length;
    }
  }
}

Fixed version (ground truth):
/** 
 * Creates a new data manager from pre-encoded data.
 * @param header
 * @param data
 * @param dictionary
 * @param definition
 * @param criteria
 * @param function
 */
public DataManager(final String[] header,final int[][] data,final Dictionary dictionary,final DataDefinition definition,final Set<PrivacyCriterion> criteria,final Map<String,DistributionAggregateFunction> functions){
  this.header=header;
  Set<String> attributesGemeralized=definition.getQuasiIdentifiersWithGeneralization();
  Set<String> attributesSensitive=definition.getSensitiveAttributes();
  Set<String> attributesMicroaggregated=definition.getQuasiIdentifiersWithMicroaggregation();
  Set<String> attributesInsensitive=definition.getInsensitiveAttributes();
  final Dictionary dictionaryGeneralized=new Dictionary(attributesGemeralized.size());
  final Dictionary dictionaryAnalyzed=new Dictionary(attributesSensitive.size() + attributesMicroaggregated.size());
  final Dictionary dictionaryStatic=new Dictionary(attributesInsensitive.size());
  final int[] mapGeneralized=new int[dictionaryGeneralized.getNumDimensions()];
  final int[] mapAnalyzed=new int[dictionaryAnalyzed.getNumDimensions()];
  final int[] mapStatic=new int[dictionaryStatic.getNumDimensions()];
  this.microaggregationMap=new int[attributesMicroaggregated.size()];
  this.microaggregationStartIndex=attributesSensitive.size();
  this.microaggregationNumAttributes=attributesMicroaggregated.size();
  int indexStatic=0;
  int indexGeneralized=0;
  int indexAnalyzed=0;
  int indexSensitive=0;
  int indexMicroaggregated=this.microaggregationStartIndex;
  int counter=0;
  final int[] map=new int[header.length * 2];
  final String[] headerGH=new String[dictionaryGeneralized.getNumDimensions()];
  final String[] headerDI=new String[dictionaryAnalyzed.getNumDimensions()];
  final String[] headerIS=new String[dictionaryStatic.getNumDimensions()];
  microaggregationHeader=new String[attributesMicroaggregated.size()];
  for (  final String column : header) {
    final int idx=counter * 2;
    if (attributesGemeralized.contains(column)) {
      map[idx]=AttributeTypeInternal.QUASI_IDENTIFYING_GENERALIZED;
      map[idx + 1]=indexGeneralized;
      mapGeneralized[indexGeneralized]=counter;
      dictionaryGeneralized.registerAll(indexGeneralized,dictionary,counter);
      headerGH[indexGeneralized]=header[counter];
      indexGeneralized++;
    }
 else     if (attributesMicroaggregated.contains(column)) {
      map[idx]=AttributeTypeInternal.QUASI_IDENTIFYING_MICROAGGREGATED;
      map[idx + 1]=indexMicroaggregated;
      mapAnalyzed[indexMicroaggregated]=counter;
      dictionaryAnalyzed.registerAll(indexMicroaggregated,dictionary,counter);
      headerDI[indexMicroaggregated]=header[counter];
      indexMicroaggregated++;
      microaggregationMap[indexAnalyzed]=counter;
      microaggregationHeader[indexAnalyzed]=header[counter];
      indexAnalyzed++;
    }
 else     if (attributesInsensitive.contains(column)) {
      map[idx]=AttributeTypeInternal.INSENSITIVE;
      map[idx + 1]=indexStatic;
      mapStatic[indexStatic]=counter;
      dictionaryStatic.registerAll(indexStatic,dictionary,counter);
      headerIS[indexStatic]=header[counter];
      indexStatic++;
    }
 else     if (attributesSensitive.contains(column)) {
      map[idx]=AttributeTypeInternal.SENSITIVE;
      map[idx + 1]=indexSensitive;
      mapAnalyzed[indexSensitive]=counter;
      dictionaryAnalyzed.registerAll(indexSensitive,dictionary,counter);
      headerDI[indexSensitive]=header[counter];
      indexSensitive++;
    }
 else {
      map[idx]=AttributeTypeInternal.IDENTIFYING;
      map[idx + 1]=-1;
    }
    counter++;
  }
  final Data[] ddata=encode(data,map,mapGeneralized,mapAnalyzed,mapStatic,dictionaryGeneralized,dictionaryAnalyzed,dictionaryStatic,headerGH,headerDI,headerIS);
  dataGeneralized=ddata[0];
  dataAnalyzed=ddata[1];
  dataStatic=ddata[2];
  minLevels=new int[attributesGemeralized.size()];
  hierarchiesHeights=new int[attributesGemeralized.size()];
  maxLevels=new int[attributesGemeralized.size()];
  hierarchiesGeneralized=new GeneralizationHierarchy[attributesGemeralized.size()];
  for (int i=0; i < header.length; i++) {
    final int idx=i * 2;
    if (attributesGemeralized.contains(header[i]) && map[idx] == AttributeTypeInternal.QUASI_IDENTIFYING_GENERALIZED) {
      final int dictionaryIndex=map[idx + 1];
      final String name=header[i];
      if (definition.getHierarchy(name) != null) {
        hierarchiesGeneralized[dictionaryIndex]=new GeneralizationHierarchy(name,definition.getHierarchy(name),dictionaryIndex,dictionaryGeneralized);
      }
 else {
        throw new IllegalStateException("String_Node_Str" + header[i] + "String_Node_Str");
      }
      hierarchiesHeights[dictionaryIndex]=hierarchiesGeneralized[dictionaryIndex].getArray()[0].length;
      final Integer minGenLevel=definition.getMinimumGeneralization(name);
      minLevels[dictionaryIndex]=minGenLevel == null ? 0 : minGenLevel;
      final Integer maxGenLevel=definition.getMaximumGeneralization(name);
      maxLevels[dictionaryIndex]=maxGenLevel == null ? hierarchiesHeights[dictionaryIndex] - 1 : maxGenLevel;
    }
  }
  for (  PrivacyCriterion c : criteria) {
    if (c instanceof EDDifferentialPrivacy) {
      DataGeneralizationScheme scheme=((EDDifferentialPrivacy)c).getGeneralizationScheme();
      for (int i=0; i < header.length; i++) {
        final int idx=i * 2;
        if (attributesGemeralized.contains(header[i]) && map[idx] == AttributeTypeInternal.QUASI_IDENTIFYING_GENERALIZED) {
          minLevels[map[idx + 1]]=scheme.getGeneralizationLevel(header[i],definition);
          maxLevels[map[idx + 1]]=scheme.getGeneralizationLevel(header[i],definition);
        }
      }
      break;
    }
  }
  Map<String,String[][]> sensitiveHierarchies=new HashMap<String,String[][]>();
  for (  PrivacyCriterion c : criteria) {
    if (c instanceof HierarchicalDistanceTCloseness) {
      HierarchicalDistanceTCloseness t=(HierarchicalDistanceTCloseness)c;
      sensitiveHierarchies.put(t.getAttribute(),t.getHierarchy().getHierarchy());
    }
  }
  hierarchiesSensitive=new HashMap<String,GeneralizationHierarchy>();
  indexesSensitive=new HashMap<String,Integer>();
  int index=0;
  for (int i=0; i < header.length; i++) {
    final String name=header[i];
    final int idx=i * 2;
    if (sensitiveHierarchies.containsKey(name) && map[idx] == AttributeTypeInternal.SENSITIVE) {
      final int dictionaryIndex=map[idx + 1];
      final String[][] hiers=sensitiveHierarchies.get(name);
      if (hiers != null) {
        hierarchiesSensitive.put(name,new GeneralizationHierarchy(name,hiers,dictionaryIndex,dictionaryAnalyzed));
      }
    }
    if (attributesSensitive.contains(header[i])) {
      indexesSensitive.put(name,index);
      index++;
    }
  }
  Map<String,String[][]> maHierarchies=new HashMap<String,String[][]>();
  for (  String attribute : functions.keySet()) {
    if (functions.get(attribute) instanceof DistributionAggregateFunctionGeneralization) {
      maHierarchies.put(attribute,definition.getHierarchy(attribute));
    }
  }
  Map<String,int[][]> hierarchiesMA=new HashMap<String,int[][]>();
  index=0;
  for (int i=0; i < header.length; i++) {
    final String name=header[i];
    final int idx=i * 2;
    if (maHierarchies.containsKey(name) && map[idx] == AttributeTypeInternal.QUASI_IDENTIFYING_MICROAGGREGATED) {
      final int dictionaryIndex=map[idx + 1];
      final String[][] hiers=maHierarchies.get(name);
      if (hiers != null) {
        hierarchiesMA.put(name,new GeneralizationHierarchy(name,hiers,dictionaryIndex,dictionaryAnalyzed).map);
      }
    }
  }
  dictionaryGeneralized.finalizeAll();
  dictionaryAnalyzed.finalizeAll();
  dictionaryStatic.finalizeAll();
  microaggregationFunctions=new DistributionAggregateFunction[attributesMicroaggregated.size()];
  for (int i=0; i < header.length; i++) {
    final int idx=i * 2;
    if (attributesMicroaggregated.contains(header[i]) && map[idx] == AttributeTypeInternal.QUASI_IDENTIFYING_MICROAGGREGATED) {
      final int dictionaryIndex=map[idx + 1] - microaggregationStartIndex;
      final String name=header[i];
      if (definition.getMicroAggregationFunction(name) != null) {
        microaggregationFunctions[dictionaryIndex]=functions.get(name);
        microaggregationFunctions[dictionaryIndex].initialize(dictionaryAnalyzed.getMapping()[dictionaryIndex + microaggregationStartIndex],definition.getDataType(name),hierarchiesMA.get(name));
      }
 else {
        throw new IllegalStateException("String_Node_Str" + header[i] + "String_Node_Str");
      }
    }
  }
  for (  PrivacyCriterion c : criteria) {
    if (c instanceof EDDifferentialPrivacy) {
      ((EDDifferentialPrivacy)c).initialize(this);
    }
    if (c.getSubset() != null) {
      subset=c.getSubset().getSet();
      subsetSize=c.getSubset().getArray().length;
    }
  }
}