fix all bug
This commit is contained in:
@@ -1,30 +1,29 @@
|
|||||||
package src.fr.impl;
|
package src.fr.impl;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import src.fr.api.PartType;
|
import src.fr.api.PartType;
|
||||||
import src.fr.api.CompatibilityChecker;
|
import src.fr.api.CompatibilityChecker;
|
||||||
|
import src.fr.api.CompatibilityManager;
|
||||||
|
|
||||||
|
|
||||||
public class CompatibilityCheckerImpl implements CompatibilityChecker {
|
public class CompatibilityCheckerImpl implements CompatibilityChecker {
|
||||||
|
|
||||||
private HashMap<PartType, Set<PartType>> incompatibilities;
|
private CompatibilityManager compatibilityManager;
|
||||||
private HashMap<PartType, Set<PartType>> requirements;
|
|
||||||
|
|
||||||
public CompatibilityCheckerImpl( HashMap<PartType, Set<PartType>> incompatibilities, HashMap<PartType, Set<PartType>> requirements){
|
public CompatibilityCheckerImpl( CompatibilityManager compatibilityManager){
|
||||||
this.incompatibilities=incompatibilities;
|
this.compatibilityManager=compatibilityManager;
|
||||||
this.requirements= requirements;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<PartType> getIncompatibilities(PartType reference) {
|
public Set<PartType> getIncompatibilities(PartType reference) {
|
||||||
return this.incompatibilities.get(reference);
|
return this.compatibilityManager.getIncompatibilities(reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<PartType> getRequirements(PartType reference) {
|
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.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import src.fr.api.PartType;
|
import src.fr.api.PartType;
|
||||||
@@ -29,6 +30,7 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
|
|||||||
|
|
||||||
if(incompa.isEmpty()){
|
if(incompa.isEmpty()){
|
||||||
incompatibilities.put(reference, target);
|
incompatibilities.put(reference, target);
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
for(PartType x: target){
|
for(PartType x: target){
|
||||||
if (incompa.contains(x)){
|
if (incompa.contains(x)){
|
||||||
@@ -40,10 +42,11 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
|
|||||||
//Ajout ref à x
|
//Ajout ref à x
|
||||||
incompa.add(x);
|
incompa.add(x);
|
||||||
System.out.println("Add "+reference.getName() +" incompatible with "+x.getName());
|
System.out.println("Add "+reference.getName() +" incompatible with "+x.getName());
|
||||||
|
this.incompatibilities.put(reference, incompa);
|
||||||
|
// Symétrie
|
||||||
//Ajoute x à ref
|
//Ajoute x à ref
|
||||||
this.getIncompatibilities(x).add(reference);
|
//this.getIncompatibilities(x).add(reference);
|
||||||
System.out.println("Add "+x.getName() +" incompatible with "+reference.getName());
|
//System.out.println("Add "+x.getName() +" incompatible with "+reference.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,8 +65,10 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
|
|||||||
}else{
|
}else{
|
||||||
if(incompa.contains(target)){
|
if(incompa.contains(target)){
|
||||||
incompa.remove(target);
|
incompa.remove(target);
|
||||||
|
this.incompatibilities.replace(reference, incompa);
|
||||||
|
// SyMéTrIe
|
||||||
//Remove target -> ref
|
//Remove target -> ref
|
||||||
this.getIncompatibilities(target).remove(reference);
|
//this.getIncompatibilities(target).remove(reference);
|
||||||
}else {
|
}else {
|
||||||
System.out.println("This part doesn't exist in incompatibilities list");
|
System.out.println("This part doesn't exist in incompatibilities list");
|
||||||
}
|
}
|
||||||
@@ -92,9 +97,11 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
|
|||||||
require.add(x);
|
require.add(x);
|
||||||
System.out.println("Add "+reference.getName() +" compatible with "+x.getName());
|
System.out.println("Add "+reference.getName() +" compatible with "+x.getName());
|
||||||
|
|
||||||
|
this.requirements.put(reference, require);
|
||||||
|
//Symétrie
|
||||||
//Ajoute x à ref
|
//Ajoute x à ref
|
||||||
this.getRequirements(x).add(reference);
|
//this.getRequirements(x).add(reference);
|
||||||
System.out.println("Add "+x.getName() +" compatible with "+reference.getName());
|
//System.out.println("Add "+x.getName() +" compatible with "+reference.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,25 +121,86 @@ public class CompatibilityManagerImpl implements CompatibilityManager {
|
|||||||
}else{
|
}else{
|
||||||
if(require.contains(target)){
|
if(require.contains(target)){
|
||||||
require.remove(target);
|
require.remove(target);
|
||||||
|
this.requirements.replace(reference, require);
|
||||||
|
// SyMéTrIe
|
||||||
//Remove target -> ref
|
//Remove target -> ref
|
||||||
this.getRequirements(target).remove(reference);
|
//this.getRequirements(target).remove(reference);
|
||||||
}else {
|
}else {
|
||||||
System.out.println("This part doesn't exist in compatibilities list");
|
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
|
@Override
|
||||||
public Set<PartType> getIncompatibilities(PartType reference) {
|
public Set<PartType> getIncompatibilities(PartType reference) {
|
||||||
// Il faut verifier ref est existé dans Hashmap
|
Set<PartType> result = new HashSet<>();
|
||||||
//return this.incompatibilities.get(reference);
|
|
||||||
return this.incompatibilities.getOrDefault(reference, new HashSet<PartType>());
|
// 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
|
@Override
|
||||||
public Set<PartType> getRequirements(PartType reference) {
|
public Set<PartType> getRequirements(PartType reference) {
|
||||||
//return this.requirements.get(reference);
|
Set<PartType> result = new HashSet<>();
|
||||||
return this.requirements.getOrDefault(reference, new HashSet<PartType>());
|
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.Configuration;
|
||||||
import src.fr.api.Part;
|
import src.fr.api.Part;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ConfigurationImpl implements Configuration {
|
public class ConfigurationImpl implements Configuration {
|
||||||
@@ -19,12 +20,28 @@ public class ConfigurationImpl implements Configuration {
|
|||||||
if (this.isComplete()){
|
if (this.isComplete()){
|
||||||
for(Part pt: selectedParts){
|
for(Part pt: selectedParts){
|
||||||
//Verifier Requirements
|
//Verifier Requirements
|
||||||
for(PartType require : compatibilityManager.getRequirements(pt)){
|
for(PartType require : compatibilityManager.getRequirements(pt.getType())){
|
||||||
if(!selectedParts.contains(require)) return false;
|
//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
|
//Verifier Incompabilities
|
||||||
for(PartType incompa : compatibilityManager.getIncompatibilities(pt)){
|
for(PartType incompa : compatibilityManager.getIncompatibilities(pt.getType())){
|
||||||
if(selectedParts.contains(incompa)) return false;
|
for (Part selectPart : selectedParts){
|
||||||
|
if(selectPart.getType().equals(incompa)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -52,28 +69,28 @@ public class ConfigurationImpl implements Configuration {
|
|||||||
Category cat_chosenPart = chosenPart.getCategory();
|
Category cat_chosenPart = chosenPart.getCategory();
|
||||||
|
|
||||||
//Vérifier s'il y a des pièces dans la même catégorie, si oui return
|
//Vérifier s'il y a des pièces dans la même catégorie, si oui return
|
||||||
for( PartType pt: selectedParts){
|
for(Part pt: selectedParts){
|
||||||
if(pt.getCategory().equals(cat_chosenPart)){
|
if(pt.getCategory().equals(cat_chosenPart)){
|
||||||
System.out.println("Il y a une pièce dans la même catégorie dans la configuration");
|
System.out.println("Il y a une pièce dans la même catégorie dans la configuration");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectedParts.add(chosenPart);
|
selectedParts.add( ((PartTypeImpl)chosenPart).newInstance() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PartType getSelectionForCategory(Category category) {
|
public Optional<Part> getSelectionForCategory(Category category) {
|
||||||
for( PartType pt: selectedParts){
|
for( Part pt: selectedParts){
|
||||||
if(pt.getCategory().equals(category)){
|
if(pt.getCategory().equals(category)){
|
||||||
return pt;
|
return Optional.of(pt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unselectPartType(Category categoryToClear) {
|
public void unselectPartType(Category categoryToClear) {
|
||||||
for( PartType pt: selectedParts){
|
for( Part pt: selectedParts){
|
||||||
if(pt.getCategory().equals(categoryToClear)){
|
if(pt.getCategory().equals(categoryToClear)){
|
||||||
selectedParts.remove(pt);
|
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 {
|
public class test {
|
||||||
|
/*
|
||||||
Category Engine = new CategoryImpl("Engine");
|
Category Engine = new CategoryImpl("Engine");
|
||||||
Category Transmission = new CategoryImpl("Transmission");
|
Category Transmission = new CategoryImpl("Transmission");
|
||||||
Category Exterior= new CategoryImpl("Exterior");
|
Category Exterior= new CategoryImpl("Exterior");
|
||||||
@@ -42,6 +42,7 @@ public class test {
|
|||||||
PartType IH= new PartTypeImpl("IH", Interior);
|
PartType IH= new PartTypeImpl("IH", Interior);
|
||||||
PartType IS= new PartTypeImpl("IS", Interior);
|
PartType IS= new PartTypeImpl("IS", Interior);
|
||||||
|
|
||||||
|
|
||||||
CompatibilityManager cm = new CompatibilityManagerImpl();
|
CompatibilityManager cm = new CompatibilityManagerImpl();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -89,10 +90,6 @@ public class test {
|
|||||||
cm.addRequirements(XS, XSRequirement);
|
cm.addRequirements(XS, XSRequirement);
|
||||||
cm.addIncompatibilities(IS, ISIncompatibilities);
|
cm.addIncompatibilities(IS, ISIncompatibilities);
|
||||||
cm.addRequirements(IS, ISRequirement);
|
cm.addRequirements(IS, ISRequirement);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -136,7 +133,7 @@ public class test {
|
|||||||
//assertTrue(cm.getIncompatibilities(XM).contains(EG100));
|
//assertTrue(cm.getIncompatibilities(XM).contains(EG100));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user