reorginazise
This commit is contained in:
13
src/fr/impl/Category.java
Normal file
13
src/fr/impl/Category.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package src;
|
||||
|
||||
public class Category implements fr.istic.nplouzeau.cartaylor.api.Category {
|
||||
private String name;
|
||||
|
||||
public Category(String name){
|
||||
this.name= name;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
29
src/fr/impl/CompatibilityChecker.java
Normal file
29
src/fr/impl/CompatibilityChecker.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package src;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import fr.istic.nplouzeau.cartaylor.api.PartType;
|
||||
|
||||
|
||||
public class CompatibilityChecker implements fr.istic.nplouzeau.cartaylor.api.CompatibilityChecker {
|
||||
|
||||
private HashMap<PartType, Set<PartType>> incompatibilities;
|
||||
private HashMap<PartType, Set<PartType>> requirements;
|
||||
|
||||
public CompatibilityChecker( 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.incompatibilities.get(reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference) {
|
||||
return this.requirements.get(reference);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
131
src/fr/impl/CompatibilityManager.java
Normal file
131
src/fr/impl/CompatibilityManager.java
Normal file
@@ -0,0 +1,131 @@
|
||||
package src;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import fr.istic.nplouzeau.cartaylor.api.PartType;
|
||||
|
||||
public class CompatibilityManager implements fr.istic.nplouzeau.cartaylor.api.CompatibilityManager {
|
||||
|
||||
private HashMap<PartType, Set<PartType>> incompatibilities;
|
||||
private HashMap<PartType, Set<PartType>> requirements;
|
||||
|
||||
@Override
|
||||
public void addIncompatibilities(PartType reference, Set<PartType> target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
|
||||
Set<PartType> incompa = this.getIncompatibilities(reference);
|
||||
Set<PartType> require = this.getRequirements(reference);
|
||||
|
||||
if(incompa== null){
|
||||
incompa=target;
|
||||
}else {
|
||||
for(PartType x: target){
|
||||
if (incompa.contains(x)){
|
||||
System.out.println("We have it already");
|
||||
}else {
|
||||
if(require.contains(x)){
|
||||
System.out.println("Cannot remove");
|
||||
}else{
|
||||
//Ajout ref à x
|
||||
incompa.add(x);
|
||||
System.out.println("Add "+reference.getName() +" incompatible with "+x.getName());
|
||||
|
||||
//Ajoute x à ref
|
||||
this.getIncompatibilities(x).add(reference);
|
||||
System.out.println("Add "+x.getName() +" incompatible with "+reference.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeIncompatibility(PartType reference, PartType target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
|
||||
Set<PartType> incompa = this.getIncompatibilities(reference);
|
||||
if(incompa==null){
|
||||
System.out.println("No part incompatible");
|
||||
}else{
|
||||
if(incompa.contains(target)){
|
||||
incompa.remove(target);
|
||||
//Remove target -> ref
|
||||
this.getIncompatibilities(target).remove(reference);
|
||||
}else {
|
||||
System.out.println("This part doesn't exist in incompatibilities list");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(PartType reference, Set<PartType> target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
|
||||
Set<PartType> incompa = this.getIncompatibilities(reference);
|
||||
Set<PartType> require = this.getRequirements(reference);
|
||||
if(require== null){
|
||||
require= target;
|
||||
}else {
|
||||
for(PartType x: target){
|
||||
if (require.contains(x)){
|
||||
System.out.println("We have it already");
|
||||
}else {
|
||||
if(incompa.contains(x)){
|
||||
System.out.println("Cannot remove");
|
||||
}else{
|
||||
//Ajout ref à x
|
||||
require.add(x);
|
||||
System.out.println("Add "+reference.getName() +" compatible with "+x.getName());
|
||||
|
||||
//Ajoute x à ref
|
||||
this.getRequirements(x).add(reference);
|
||||
System.out.println("Add "+x.getName() +" compatible with "+reference.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRequirement(PartType reference, PartType target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
|
||||
Set<PartType> require = this.getRequirements(reference);
|
||||
if(require ==null){
|
||||
System.out.println("No part compatible");
|
||||
}else{
|
||||
if(require.contains(target)){
|
||||
require.remove(target);
|
||||
//Remove target -> ref
|
||||
this.getRequirements(target).remove(reference);
|
||||
}else {
|
||||
System.out.println("This part doesn't exist in compatibilities list");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getIncompatibilities(PartType reference) {
|
||||
return this.incompatibilities.get(reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference) {
|
||||
return this.requirements.get(reference);
|
||||
}
|
||||
|
||||
}
|
||||
87
src/fr/impl/Configuration.java
Normal file
87
src/fr/impl/Configuration.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package src;
|
||||
|
||||
import fr.istic.nplouzeau.cartaylor.api.Category;
|
||||
import fr.istic.nplouzeau.cartaylor.api.PartType;
|
||||
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class Configuration implements fr.istic.nplouzeau.cartaylor.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();;
|
||||
}
|
||||
}
|
||||
48
src/fr/impl/Configurator.java
Normal file
48
src/fr/impl/Configurator.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package src;
|
||||
|
||||
import fr.istic.nplouzeau.cartaylor.api.Category;
|
||||
import fr.istic.nplouzeau.cartaylor.api.CompatibilityChecker;
|
||||
import fr.istic.nplouzeau.cartaylor.api.Configuration;
|
||||
import fr.istic.nplouzeau.cartaylor.api.PartType;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Configurator implements fr.istic.nplouzeau.cartaylor.api.Configurator {
|
||||
private Set<Category> categories;
|
||||
private Set<PartType> partTypes;
|
||||
private Configuration configuration;
|
||||
private CompatibilityChecker compatibilityChecker;
|
||||
|
||||
public Configurator (Set<Category> cat, Set<PartType> pt, Configuration config) {
|
||||
this.categories= cat;
|
||||
this.partTypes=pt;
|
||||
this.configuration=config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Category> getCategories() {
|
||||
return this.categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getVariants(Category category) {
|
||||
Set<PartType>a = new HashSet<PartType>();
|
||||
for(PartType x : partTypes){
|
||||
if (x.getCategory()==category){
|
||||
a.add(x);
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration getConfiguration() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompatibilityChecker getCompatibilityChecker() {
|
||||
return this.compatibilityChecker;
|
||||
}
|
||||
}
|
||||
19
src/fr/impl/PartType.java
Normal file
19
src/fr/impl/PartType.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package src;
|
||||
|
||||
public class PartType implements fr.istic.nplouzeau.cartaylor.api.PartType {
|
||||
private String name;
|
||||
private Category category;
|
||||
|
||||
public PartType(String name, Category category ) {
|
||||
this.name = name;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Category getCategory(){
|
||||
return this.category;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user