correction nom des Impl
This commit is contained in:
87
src/fr/impl/ConfigurationImpl.java
Normal file
87
src/fr/impl/ConfigurationImpl.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import src.fr.api.Category;
|
||||
import src.fr.api.PartType;
|
||||
import src.fr.api.CompatibilityManager;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfigurationImpl implements src.fr.api.Configuration {
|
||||
private Set<PartType> selectedParts;
|
||||
private CompatibilityManager compatibilityManager;
|
||||
private static int NB_CATEGORY = 4;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
if (this.isComplete()){
|
||||
for(PartType pt: selectedParts){
|
||||
//Verifier Requirements
|
||||
for(PartType require : compatibilityManager.getRequirements(pt)){
|
||||
if(!selectedParts.contains(require)) return false;
|
||||
}
|
||||
//Verifier Incompabilities
|
||||
for(PartType incompa : compatibilityManager.getIncompatibilities(pt)){
|
||||
if(selectedParts.contains(incompa)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
if(selectedParts.size()==NB_CATEGORY){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getSelectedParts() {
|
||||
return selectedParts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPart(PartType chosenPart) {
|
||||
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)){
|
||||
System.out.println("Il y a une pièce dans la même catégorie dans la configuration");
|
||||
return;
|
||||
}
|
||||
}
|
||||
selectedParts.add(chosenPart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartType getSelectionForCategory(Category category) {
|
||||
for( PartType pt: selectedParts){
|
||||
if(pt.getCategory().equals(category)){
|
||||
return pt;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unselectPartType(Category categoryToClear) {
|
||||
for( PartType pt: selectedParts){
|
||||
if(pt.getCategory().equals(categoryToClear)){
|
||||
selectedParts.remove(pt);
|
||||
}
|
||||
}
|
||||
System.out.println("Il n'y a pas des pièces dans cette catégorie");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.selectedParts.clear();;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user