Maybe the incompatible will be useful

This commit is contained in:
Minh VU
2024-10-24 11:28:26 +02:00
parent 1a09eda6e7
commit 1168b5377f
3 changed files with 54 additions and 45 deletions

9
.idea/workspace.xml generated
View File

@@ -4,9 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="12bd6c53-8ba7-454c-a61e-7a76cc3b801b" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list>
<list default="true" id="12bd6c53-8ba7-454c-a61e-7a76cc3b801b" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -23,6 +21,9 @@
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProblemsViewState">
<option name="selectedTabId" value="ProjectErrors" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 1
}</component>
@@ -35,6 +36,7 @@
"keyToString": {
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "dev__v1",
"ignore.virus.scanning.warn.message": "true",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "C:/Users/vumin/Desktop/M1/ALO/cartailor",
"node.js.detected.package.eslint": "true",
@@ -90,6 +92,7 @@
<workItem from="1729507889060" duration="386000" />
<workItem from="1729595321874" duration="25000" />
<workItem from="1729743145740" duration="122000" />
<workItem from="1729757559608" duration="166000" />
</task>
<servers />
</component>

View File

@@ -2,27 +2,26 @@ package src.fr.impl;
import java.util.HashMap;
import java.util.Set;
import src.fr.api.PartType;
import src.fr.api.CompatibilityManager;
public class CompatibilityCheckerImpl implements src.fr.api.CompatibilityChecker {
private CompatibilityManager compatibilityManager;
private HashMap<PartType, Set<PartType>> incompatibilities;
private HashMap<PartType, Set<PartType>> requirements;
public CompatibilityCheckerImpl( HashMap<PartType, Set<PartType>> incompatibilities, HashMap<PartType, Set<PartType>> requirements){
this.incompatibilities=incompatibilities;
this.requirements= requirements;
public CompatibilityCheckerImpl( CompatibilityManager compatibilityManager){
this.compatibilityManager=compatibilityManager;
}
@Override
public Set<PartType> getIncompatibilities(PartType reference) {
return this.incompatibilities.get(reference);
return this.compatibilityManager.getIncompatibilities(reference);
}
@Override
public Set<PartType> getRequirements(PartType reference) {
return this.requirements.get(reference);
return this.compatibilityManager.getRequirements(reference);
}

View File

@@ -1,6 +1,7 @@
package src.fr.impl;
import java.util.HashMap;
import java.util.Map;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;
@@ -128,48 +129,54 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
}
}
// A - incompatible B + B require C => A incompatbile C
// This is B require C
protected Set<PartType> getIncompability_middle(PartType reference){
return this.requirements.getOrDefault(reference, new HashSet<PartType>());
// A -> B -> C -> A, D -> B
//bool verify requirement (1) or incompatible (0)
private void Femeture_Transivite(PartType reference, Set<PartType> result, Set<PartType> visited, boolean bool){
//Condition de quitter la boucle
if(visited.contains(reference)){
return;
}else {
visited.add(reference);
}
Set<PartType> list = null;
if(bool==true){ // requirement
//Get all requirement of A (in example is B)
list = this.requirements.get(reference);
}else{ //incompatible
list = this.incompatibilities.get(reference);
}
if(list != null){ // list = {B}
for(PartType pt: list){
if(!result.contains(pt)){
result.add(pt);
}
Femeture_Transivite(pt,result,visited,bool);
}
}
}
private void check_All_Catalog(PartType reference, Set<PartType> result, boolean bool){
if(bool){ //
}
}
@Override
public Set<PartType> getIncompatibilities(PartType reference) {
// Il faut verifier ref est existé dans Hashmap
//return this.incompatibilities.get(reference);
Set<PartType> result = new HashSet<>();
Femeture_Transivite(reference, result,new HashSet<>(),false);
return result;
}
//A incompatible B
Set<PartType> parts = this.incompatibilities.getOrDefault(reference, new HashSet<PartType>());
// A incompatible C
//Get all incomptability with transivity
if (parts != null){
for( PartType p: parts){
parts.addAll(this.getIncompability_middle(p));
}
}
return parts;
}
//Same but B incompatible C
protected Set<PartType> getRequirement_middle(PartType reference){
return this.incompatibilities.getOrDefault(reference, new HashSet<PartType>());
}
@Override
public Set<PartType> getRequirements(PartType reference) {
Set<PartType> parts = this.requirements.getOrDefault(reference, new HashSet<PartType>());
// A incompatible C
//Get all incomptability with transivity
if (parts != null){
for( PartType p: parts){
parts.addAll(this.getRequirement_middle(p));
}
}
return parts;
Set<PartType> result = new HashSet<>();
Femeture_Transivite(reference, result,new HashSet<>(),true);
return result;
}
}