Program: 56820
Project: 56820
Buggy source:
/** 
 * <p> Converts a   {@link Perspective} with an IDType that is not the {@link #recordIDType} or the{@link #dimensionIDType}, but is of the same   {@link IDCategory} as one of the two to a new Perspective with thelocal  {@link IDType}. </p> <p> Grouping, and naming is preserved, sample elements and trees are not. </p>
 */
public Perspective convertForeignPerspective(Perspective foreignPerspective){
  foreignPerspective.setCrossDatasetID(foreignPerspective.getPerspectiveID());
  IDType localIDType=getPrimaryIDType(foreignPerspective.getIdType());
  IDMappingManager idMappingManager=IDMappingManagerRegistry.get().getIDMappingManager(localIDType);
  if (foreignPerspective.getIdType() == localIDType)   return foreignPerspective;
  VirtualArray foreignVA=foreignPerspective.getVirtualArray();
  GroupList groupList=foreignVA.getGroupList();
  PerspectiveInitializationData data=new PerspectiveInitializationData();
  ArrayList<Integer> indices=new ArrayList<Integer>(foreignVA.size());
  ArrayList<Integer> groupSizes=new ArrayList<Integer>(groupList.size());
  ArrayList<Integer> sampleElements=new ArrayList<Integer>(groupList.size());
  ArrayList<String> groupNames=new ArrayList<String>(groupList.size());
  for (  Group foreignGroup : groupList) {
    groupSizes.add(0);
    sampleElements.add(0);
    groupNames.add(foreignGroup.getLabel());
  }
  int count=0;
  int unmapped=0;
  IIDTypeMapper<Integer,Integer> mapper=idMappingManager.getIDTypeMapper(foreignVA.getIdType(),localIDType);
  for (  Integer foreignVAID : foreignVA) {
    Set<Integer> localVAIDS=mapper.apply(foreignVAID);
    if (localVAIDS == null) {
      unmapped++;
      continue;
    }
    for (    Integer localVAID : localVAIDS) {
      if (localVAID == null) {
        unmapped++;
        continue;
      }
      indices.add(localVAID);
      int groupIndex=groupList.getGroupOfVAIndex(foreignVA.indexOf(foreignVAID)).getGroupIndex();
      groupSizes.set(groupIndex,groupSizes.get(groupIndex) + 1);
      sampleElements.set(groupIndex,count);
      count++;
    }
  }
  if (unmapped > 0) {
    Logger.log(new Status(IStatus.INFO,this.toString(),"String_Node_Str" + unmapped + "String_Node_Str"+ foreignPerspective+ "String_Node_Str"+ foreignPerspective.getVirtualArray().size()+ "String_Node_Str"));
  }
  data.setData(indices,groupSizes,sampleElements,groupNames);
  Perspective localPerspective=new Perspective(this,localIDType);
  localPerspective.setUnmappedElements(unmapped);
  localPerspective.setCrossDatasetID(foreignPerspective.getCrossDatasetID());
  localPerspective.setIDType(localIDType);
  localPerspective.init(data);
  localPerspective.setLabel(foreignPerspective.getLabel(),foreignPerspective.isLabelDefault());
  return localPerspective;
}

Fixed version (ground truth):
/** 
 * <p> Converts a   {@link Perspective} with an IDType that is not the {@link #recordIDType} or the{@link #dimensionIDType}, but is of the same   {@link IDCategory} as one of the two to a new Perspective with thelocal  {@link IDType}. </p> <p> Grouping, and naming is preserved, sample elements and trees are not. </p>
 */
public Perspective convertForeignPerspective(Perspective foreignPerspective){
  foreignPerspective.setCrossDatasetID(foreignPerspective.getPerspectiveID());
  IDType localIDType=getPrimaryIDType(foreignPerspective.getIdType());
  if (foreignPerspective.getIdType() == localIDType)   return foreignPerspective;
  IDMappingManager idMappingManager=IDMappingManagerRegistry.get().getIDMappingManager(localIDType);
  VirtualArray foreignVA=foreignPerspective.getVirtualArray();
  GroupList groupList=foreignVA.getGroupList();
  PerspectiveInitializationData data=new PerspectiveInitializationData();
  ArrayList<Integer> indices=new ArrayList<Integer>(foreignVA.size());
  ArrayList<Integer> groupSizes=new ArrayList<Integer>(groupList.size());
  ArrayList<Integer> sampleElements=new ArrayList<Integer>(groupList.size());
  ArrayList<String> groupNames=new ArrayList<String>(groupList.size());
  for (  Group foreignGroup : groupList) {
    groupSizes.add(0);
    sampleElements.add(0);
    groupNames.add(foreignGroup.getLabel());
  }
  int count=0;
  int unmapped=0;
  IIDTypeMapper<Integer,Integer> mapper=idMappingManager.getIDTypeMapper(foreignVA.getIdType(),localIDType);
  for (  Integer foreignVAID : foreignVA) {
    Set<Integer> localVAIDS=mapper.apply(foreignVAID);
    if (localVAIDS == null) {
      unmapped++;
      continue;
    }
    for (    Integer localVAID : localVAIDS) {
      if (localVAID == null) {
        unmapped++;
        continue;
      }
      indices.add(localVAID);
      int groupIndex=groupList.getGroupOfVAIndex(foreignVA.indexOf(foreignVAID)).getGroupIndex();
      groupSizes.set(groupIndex,groupSizes.get(groupIndex) + 1);
      sampleElements.set(groupIndex,count);
      count++;
    }
  }
  if (unmapped > 0) {
    Logger.log(new Status(IStatus.INFO,this.toString(),"String_Node_Str" + unmapped + "String_Node_Str"+ foreignPerspective+ "String_Node_Str"+ foreignPerspective.getVirtualArray().size()+ "String_Node_Str"));
  }
  data.setData(indices,groupSizes,sampleElements,groupNames);
  Perspective localPerspective=new Perspective(this,localIDType);
  localPerspective.setUnmappedElements(unmapped);
  localPerspective.setCrossDatasetID(foreignPerspective.getCrossDatasetID());
  localPerspective.setIDType(localIDType);
  localPerspective.init(data);
  localPerspective.setLabel(foreignPerspective.getLabel(),foreignPerspective.isLabelDefault());
  return localPerspective;
}