package husacct.analyse.task.reconstruct.algorithms.hu.layers.scanniello;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import husacct.analyse.domain.IModelQueryService;
import husacct.analyse.task.reconstruct.AnalyseReconstructConstants;
import husacct.analyse.task.reconstruct.dto.ReconstructArchitectureDTO;
import husacct.analyse.task.reconstruct.parameters.ReconstructArchitectureParameterDTO;
import husacct.common.dto.SoftwareUnitDTO;
public class Layers_Scanniello_Root_Initial extends Layers_Scanniello_SuperClass{
public Layers_Scanniello_Root_Initial (IModelQueryService queryService) {
super(queryService);
}
@Override
public void executeAlgorithm(ReconstructArchitectureDTO dto, IModelQueryService queryService) {
this.threshold = dto.getThreshold();
List<SoftwareUnitDTO> classes = queryService.getAllClasses();
ArrayList<SoftwareUnitDTO> classesArray = new ArrayList<SoftwareUnitDTO>(classes);
boolean firstIdentification = true;
HashMap<Integer, ArrayList<SoftwareUnitDTO>> firstIdentifiedLayers = identifyLayersOriginal(classesArray, firstIdentification);
ArrayList<ArrayList<SoftwareUnitDTO>> topLayers = new ArrayList<>();
ArrayList<ArrayList<SoftwareUnitDTO>> bottomLayers = new ArrayList<>();
ArrayList<SoftwareUnitDTO> middleLayer = new ArrayList<>();
ArrayList<SoftwareUnitDTO> discLayer = new ArrayList<>();
topLayers.add(firstIdentifiedLayers.get(topLayerKey));
bottomLayers.add(firstIdentifiedLayers.get(bottomLayerKey));
middleLayer = firstIdentifiedLayers.get(middleLayerKey);
discLayer = firstIdentifiedLayers.get(discLayerKey);
boolean topOrBottomAreNotEmpty = firstIdentifiedLayers.get(topLayerKey).size() > 0 || firstIdentifiedLayers.get(bottomLayerKey).size() > 0;
while (topOrBottomAreNotEmpty){
firstIdentification = false;
HashMap<Integer, ArrayList<SoftwareUnitDTO>> newIdentifiedLayers = identifyLayersOriginal(middleLayer, firstIdentification);
if (!newIdentifiedLayers.get(topLayerKey).isEmpty()){
topLayers.add(newIdentifiedLayers.get(topLayerKey));
}
if (!newIdentifiedLayers.get(bottomLayerKey).isEmpty()){
bottomLayers.add(newIdentifiedLayers.get(bottomLayerKey));
}
middleLayer = newIdentifiedLayers.get(middleLayerKey);
topOrBottomAreNotEmpty = newIdentifiedLayers.get(topLayerKey).size() > 0 || newIdentifiedLayers.get(bottomLayerKey).size() > 0;
}
HashMap<Integer, ArrayList<SoftwareUnitDTO>> structuredLayers = RestructureLayers(topLayers, bottomLayers, middleLayer);
this.buildStructure(structuredLayers, discLayer);
}
@Override
public ReconstructArchitectureDTO getAlgorithmParameterSettings() {
ReconstructArchitectureDTO reconstructArchitecture = new ReconstructArchitectureDTO();
reconstructArchitecture.approachId = AnalyseReconstructConstants.Algorithms.Layers_Scanniello_Original;
reconstructArchitecture.threshold = 10;
reconstructArchitecture.relationType = AnalyseReconstructConstants.RelationTypes.allDependencies;
reconstructArchitecture.granularity = AnalyseReconstructConstants.Granularities.Classes;
reconstructArchitecture.parameterDTOs = createParameterPanels();
return reconstructArchitecture;
}
private ArrayList<ReconstructArchitectureParameterDTO> createParameterPanels(){
ArrayList<ReconstructArchitectureParameterDTO> parameterDTOs = new ArrayList<>();
parameterDTOs.add(ReconstructArchitectureParameterDTO.DefaultParameterDTOs.createThresholdParameter(10));
parameterDTOs.add(ReconstructArchitectureParameterDTO.DefaultParameterDTOs.createRelationTypeParameter(AnalyseReconstructConstants.RelationTypes.allDependencies));
parameterDTOs.add(ReconstructArchitectureParameterDTO.DefaultParameterDTOs.createGranularityPanel(AnalyseReconstructConstants.Granularities.Classes));
return parameterDTOs;
}
}