fix all bug
This commit is contained in:
@@ -1,30 +1,29 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import src.fr.api.PartType;
|
||||
import src.fr.api.CompatibilityChecker;
|
||||
import src.fr.api.CompatibilityManager;
|
||||
|
||||
|
||||
public class CompatibilityCheckerImpl implements CompatibilityChecker {
|
||||
|
||||
private HashMap<PartType, Set<PartType>> incompatibilities;
|
||||
private HashMap<PartType, Set<PartType>> requirements;
|
||||
private CompatibilityManager compatibilityManager;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package src.fr.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Objects;
|
||||
import src.fr.api.PartType;
|
||||
@@ -29,6 +30,7 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
|
||||
|
||||
if(incompa.isEmpty()){
|
||||
incompatibilities.put(reference, target);
|
||||
|
||||
}else {
|
||||
for(PartType x: target){
|
||||
if (incompa.contains(x)){
|
||||
@@ -40,10 +42,11 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
|
||||
//Ajout ref à x
|
||||
incompa.add(x);
|
||||
System.out.println("Add "+reference.getName() +" incompatible with "+x.getName());
|
||||
|
||||
this.incompatibilities.put(reference, incompa);
|
||||
// Symétrie
|
||||
//Ajoute x à ref
|
||||
this.getIncompatibilities(x).add(reference);
|
||||
System.out.println("Add "+x.getName() +" incompatible with "+reference.getName());
|
||||
//this.getIncompatibilities(x).add(reference);
|
||||
//System.out.println("Add "+x.getName() +" incompatible with "+reference.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,8 +65,10 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
|
||||
}else{
|
||||
if(incompa.contains(target)){
|
||||
incompa.remove(target);
|
||||
this.incompatibilities.replace(reference, incompa);
|
||||
// SyMéTrIe
|
||||
//Remove target -> ref
|
||||
this.getIncompatibilities(target).remove(reference);
|
||||
//this.getIncompatibilities(target).remove(reference);
|
||||
}else {
|
||||
System.out.println("This part doesn't exist in incompatibilities list");
|
||||
}
|
||||
@@ -91,10 +96,12 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
|
||||
//Ajout ref à x
|
||||
require.add(x);
|
||||
System.out.println("Add "+reference.getName() +" compatible with "+x.getName());
|
||||
|
||||
|
||||
this.requirements.put(reference, require);
|
||||
//Symétrie
|
||||
//Ajoute x à ref
|
||||
this.getRequirements(x).add(reference);
|
||||
System.out.println("Add "+x.getName() +" compatible with "+reference.getName());
|
||||
//this.getRequirements(x).add(reference);
|
||||
//System.out.println("Add "+x.getName() +" compatible with "+reference.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,25 +121,86 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
|
||||
}else{
|
||||
if(require.contains(target)){
|
||||
require.remove(target);
|
||||
this.requirements.replace(reference, require);
|
||||
// SyMéTrIe
|
||||
//Remove target -> ref
|
||||
this.getRequirements(target).remove(reference);
|
||||
//this.getRequirements(target).remove(reference);
|
||||
}else {
|
||||
System.out.println("This part doesn't exist in compatibilities list");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A -> B -> C -> A, D -> B
|
||||
//erquirement only
|
||||
private void Femeture_Transivite(PartType reference, Set<PartType> result, Set<PartType> visited, PartType start){
|
||||
//Condition de quitter la boucle
|
||||
if(visited.contains(reference)){
|
||||
return;
|
||||
}else {
|
||||
visited.add(reference);
|
||||
}
|
||||
|
||||
Set<PartType> list = null;
|
||||
//Get all requirement of A (in example is B)
|
||||
list = this.requirements.get(reference);
|
||||
|
||||
if(list != null){ // list = {B}
|
||||
for(PartType pt: list){
|
||||
if(!result.contains(pt)&& pt !=start){
|
||||
result.add(pt);
|
||||
}
|
||||
Femeture_Transivite(pt,result,visited,reference);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getIncompatibilities(PartType reference) {
|
||||
// Il faut verifier ref est existé dans Hashmap
|
||||
//return this.incompatibilities.get(reference);
|
||||
return this.incompatibilities.getOrDefault(reference, new HashSet<PartType>());
|
||||
Set<PartType> result = new HashSet<>();
|
||||
|
||||
// Remove the case of result become null
|
||||
Set<PartType> directIncompa = this.incompatibilities.get(reference);
|
||||
if(directIncompa!=null){
|
||||
result.addAll(directIncompa);
|
||||
}
|
||||
|
||||
// Collect the requirements list
|
||||
Set<PartType> requirements = new HashSet<>();
|
||||
Femeture_Transivite(reference, requirements,new HashSet<>(),reference);
|
||||
|
||||
for(Map.Entry<PartType, Set<PartType>> entry : this.incompatibilities.entrySet()){
|
||||
// check start
|
||||
if(entry.getValue().contains(reference)){
|
||||
result.add(entry.getKey());
|
||||
}
|
||||
|
||||
// check incompatible of A's requirements
|
||||
for(PartType pt: requirements){
|
||||
// In Catalog of pt
|
||||
if(entry.getValue().contains(pt)){
|
||||
result.add(entry.getKey());
|
||||
}
|
||||
// Direct of pt
|
||||
Set<PartType> direct_pt = this.incompatibilities.get(pt);
|
||||
if(direct_pt!=null){
|
||||
result.addAll(direct_pt);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference) {
|
||||
//return this.requirements.get(reference);
|
||||
return this.requirements.getOrDefault(reference, new HashSet<PartType>());
|
||||
Set<PartType> result = new HashSet<>();
|
||||
Femeture_Transivite(reference, result,new HashSet<>(),reference);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import src.fr.api.CompatibilityManager;
|
||||
import src.fr.api.Configuration;
|
||||
import src.fr.api.Part;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfigurationImpl implements Configuration {
|
||||
@@ -19,12 +20,28 @@ public class ConfigurationImpl implements Configuration {
|
||||
if (this.isComplete()){
|
||||
for(Part pt: selectedParts){
|
||||
//Verifier Requirements
|
||||
for(PartType require : compatibilityManager.getRequirements(pt)){
|
||||
if(!selectedParts.contains(require)) return false;
|
||||
for(PartType require : compatibilityManager.getRequirements(pt.getType())){
|
||||
//if(!selectedParts.contains(require)) return false;
|
||||
//IN V2, instead of verify if it's in selectedParts,
|
||||
//we will compare its type and selectedParts
|
||||
//boolean no_error = true;
|
||||
|
||||
for(Part selectPart : selectedParts){
|
||||
if (selectPart.getType().equals(require)){
|
||||
return false;
|
||||
//no_error= true;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//Verifier Incompabilities
|
||||
for(PartType incompa : compatibilityManager.getIncompatibilities(pt)){
|
||||
if(selectedParts.contains(incompa)) return false;
|
||||
for(PartType incompa : compatibilityManager.getIncompatibilities(pt.getType())){
|
||||
for (Part selectPart : selectedParts){
|
||||
if(selectPart.getType().equals(incompa)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -52,28 +69,28 @@ public class ConfigurationImpl implements Configuration {
|
||||
Category cat_chosenPart = chosenPart.getCategory();
|
||||
|
||||
//Vérifier s'il y a des pièces dans la même catégorie, si oui return
|
||||
for( PartType pt: selectedParts){
|
||||
if(pt.getCategory().equals(cat_chosenPart)){
|
||||
for(Part pt: selectedParts){
|
||||
if(pt.getCategory().equals(cat_chosenPart)){
|
||||
System.out.println("Il y a une pièce dans la même catégorie dans la configuration");
|
||||
return;
|
||||
}
|
||||
}
|
||||
selectedParts.add(chosenPart);
|
||||
selectedParts.add( ((PartTypeImpl)chosenPart).newInstance() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartType getSelectionForCategory(Category category) {
|
||||
for( PartType pt: selectedParts){
|
||||
public Optional<Part> getSelectionForCategory(Category category) {
|
||||
for( Part pt: selectedParts){
|
||||
if(pt.getCategory().equals(category)){
|
||||
return pt;
|
||||
return Optional.of(pt);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unselectPartType(Category categoryToClear) {
|
||||
for( PartType pt: selectedParts){
|
||||
for( Part pt: selectedParts){
|
||||
if(pt.getCategory().equals(categoryToClear)){
|
||||
selectedParts.remove(pt);
|
||||
}
|
||||
|
||||
7
src/fr/impl/Parts/Engine.java
Normal file
7
src/fr/impl/Parts/Engine.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package src.fr.impl.Parts;
|
||||
|
||||
import src.fr.impl.PartImpl;
|
||||
|
||||
public class Engine extends PartImpl {
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import src.fr.api.*;
|
||||
|
||||
|
||||
public class test {
|
||||
|
||||
/*
|
||||
Category Engine = new CategoryImpl("Engine");
|
||||
Category Transmission = new CategoryImpl("Transmission");
|
||||
Category Exterior= new CategoryImpl("Exterior");
|
||||
@@ -42,6 +42,7 @@ public class test {
|
||||
PartType IH= new PartTypeImpl("IH", Interior);
|
||||
PartType IS= new PartTypeImpl("IS", Interior);
|
||||
|
||||
|
||||
CompatibilityManager cm = new CompatibilityManagerImpl();
|
||||
|
||||
@Before
|
||||
@@ -89,10 +90,6 @@ public class test {
|
||||
cm.addRequirements(XS, XSRequirement);
|
||||
cm.addIncompatibilities(IS, ISIncompatibilities);
|
||||
cm.addRequirements(IS, ISRequirement);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,7 +133,7 @@ public class test {
|
||||
//assertTrue(cm.getIncompatibilities(XM).contains(EG100));
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user