test v2
This commit is contained in:
@@ -1,27 +1,28 @@
|
||||
package src.fr.impl;
|
||||
|
||||
//import java.util.HashMap;
|
||||
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;
|
||||
|
||||
public CompatibilityCheckerImpl( CompatibilityManager compatibilityManager){
|
||||
this.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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getIncompatibilities(PartType reference) {
|
||||
return this.compatibilityManager.getIncompatibilities(reference);
|
||||
return this.incompatibilities.get(reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference) {
|
||||
return this.compatibilityManager.getRequirements(reference);
|
||||
return this.requirements.get(reference);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Objects;
|
||||
@@ -29,7 +28,6 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
|
||||
|
||||
if(incompa.isEmpty()){
|
||||
incompatibilities.put(reference, target);
|
||||
|
||||
}else {
|
||||
for(PartType x: target){
|
||||
if (incompa.contains(x)){
|
||||
@@ -41,12 +39,10 @@ public class CompatibilityManagerImpl implements src.fr.api.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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,10 +61,8 @@ public class CompatibilityManagerImpl implements src.fr.api.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");
|
||||
}
|
||||
@@ -96,12 +90,10 @@ public class CompatibilityManagerImpl implements src.fr.api.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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,85 +113,25 @@ public class CompatibilityManagerImpl implements src.fr.api.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) {
|
||||
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;
|
||||
// Il faut verifier ref est existé dans Hashmap
|
||||
//return this.incompatibilities.get(reference);
|
||||
return this.incompatibilities.getOrDefault(reference, new HashSet<PartType>());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference) {
|
||||
Set<PartType> result = new HashSet<>();
|
||||
Femeture_Transivite(reference, result,new HashSet<>(),reference);
|
||||
return result;
|
||||
//return this.requirements.get(reference);
|
||||
return this.requirements.getOrDefault(reference, new HashSet<PartType>());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package src.fr.impl;
|
||||
import src.fr.api.Category;
|
||||
import src.fr.api.PartType;
|
||||
import src.fr.api.CompatibilityManager;
|
||||
import src.fr.api.Part;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -41,7 +42,7 @@ public class ConfigurationImpl implements src.fr.api.Configuration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getSelectedParts() {
|
||||
public Set<Part> getSelectedParts() {
|
||||
return selectedParts;
|
||||
}
|
||||
|
||||
|
||||
37
src/fr/impl/PartImpl.java
Normal file
37
src/fr/impl/PartImpl.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import src.fr.api.Category;
|
||||
import src.fr.api.PartType;
|
||||
|
||||
public class PartImpl implements src.fr.api.Part {
|
||||
|
||||
private PartType type;
|
||||
|
||||
public Category getCategory(){
|
||||
return this.type.getCategory();
|
||||
}
|
||||
public PartType getType(){
|
||||
return this.type;
|
||||
}
|
||||
@Override
|
||||
public Set<String> getPropertyNames() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Set<String> getAvailablePropertyValues(String propertyName) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Optional<String> getProperty(String propertyName) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void setProperty(String propertyName, String propertyValue) {
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ public class PartTypeImpl implements src.fr.api.PartType {
|
||||
private String name;
|
||||
private Category category;
|
||||
|
||||
//V2 implement
|
||||
private Class<? extends PartImpl> classRef;
|
||||
|
||||
public PartTypeImpl(String name, Category category ) {
|
||||
this.name = name;
|
||||
this.category = category;
|
||||
|
||||
Reference in New Issue
Block a user