fix all bug
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user