package _VisualDVM.ProjectData.SapforData.Variants; import Common.Database.Objects.DBObject; import _VisualDVM.Visual.UI; import _VisualDVM.ProjectData.PredictorStatistic.PredictorStatistics_2021; import _VisualDVM.ProjectData.Project.db_project_info; import _VisualDVM.ProjectData.SapforData.Arrays.ProjectArray; import _VisualDVM.ProjectData.SapforData.Regions.ParallelRegion; import javafx.util.Pair; import java.io.File; import java.math.BigInteger; import java.nio.file.Paths; import java.util.LinkedHashMap; import java.util.Vector; public class ParallelVariant extends DBObject { public static final long statNaN = -1; public static final long rankNaN = 1; public String UniqKey = ""; public int dc = 0; public db_project_info father = null; public PredictorStatistics_2021 stats = null; public Vector templates_description = new Vector<>(); public LinkedHashMap, Long> key = new LinkedHashMap<>(); public ParallelVariant(db_project_info father_in, Vector vector) { father = father_in; UniqKey = ""; dc = 0; for (int i = 0; i < vector.size(); i += 3) { ProjectArray template = father.getTemplateByAddress(vector.get(i)); long varID = vector.get(i + 1).longValue(); //тут вар ид. он обычный лонг. ParallelRegion region = father.parallelRegions.get(vector.get(i + 2)); if (varID != 0) dc++; templates_description.add(template.GetShortNameForVariant(varID)); UniqKey += template.name + "_" + varID + "_" + region.originalName; key.put(new Pair<>(template.address, region.regionId), varID); } load_stats(); } public void load_stats() { stats = father.db.predictorStatistics.Data.containsKey(UniqKey) ? father.db.predictorStatistics.Data.get(UniqKey) : new PredictorStatistics_2021(UniqKey); } public void UpdateStats(String packed, String last_version) throws Exception { stats.Unpack(packed); stats.last_version = last_version; if (stats.loaded) { father.db.Update(stats); } else { father.db.Insert(stats); stats.loaded = true; } } public boolean Match(boolean distributed) { for (Pair p : key.keySet()) { ProjectArray template = father.getTemplateByAddress(p.getKey()); if (!template.CheckFilterMask(key.get(p), distributed)) return false; } return true; } public String getVector() { String res = ""; int i = 0; for (Pair p : key.keySet()) { res += p.getKey() + "|" + key.get(p) + "|" + p.getValue() + ((i < key.size() - 1) ? "|" : ""); ++i; } res = i + "|" + res; return res; } public String getDescription() { return String.join(";", templates_description); } @Override public Object getPK() { return UniqKey; } @Override public void Select(boolean flag) { super.Select(flag); UI.getVersionsWindow().getVariantsWindow().ShowCheckedVariantsCount(); } public File project = null; public File restoreProject() { project=null; if (stats != null) { if (stats.last_version.isEmpty()) return null; project = Paths.get(father.Home.getAbsolutePath(), stats.last_version).toFile(); return project.exists() ? project : null; } return project; } }