errors
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import src.fr.api.Category;
|
||||
|
||||
public class CategoryImpl implements src.fr.api.Category {
|
||||
public class CategoryImpl implements Category {
|
||||
private String name;
|
||||
|
||||
public CategoryImpl(String name){
|
||||
|
||||
@@ -3,9 +3,10 @@ package src.fr.impl;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import src.fr.api.PartType;
|
||||
import src.fr.api.CompatibilityChecker;
|
||||
|
||||
|
||||
public class CompatibilityCheckerImpl implements src.fr.api.CompatibilityChecker {
|
||||
public class CompatibilityCheckerImpl implements CompatibilityChecker {
|
||||
|
||||
private HashMap<PartType, Set<PartType>> incompatibilities;
|
||||
private HashMap<PartType, Set<PartType>> requirements;
|
||||
|
||||
@@ -5,8 +5,9 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Objects;
|
||||
import src.fr.api.PartType;
|
||||
import src.fr.api.CompatibilityManager;
|
||||
|
||||
public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager {
|
||||
public class CompatibilityManagerImpl implements CompatibilityManager {
|
||||
|
||||
private HashMap<PartType, Set<PartType>> incompatibilities;
|
||||
private HashMap<PartType, Set<PartType>> requirements;
|
||||
|
||||
@@ -3,12 +3,13 @@ package src.fr.impl;
|
||||
import src.fr.api.Category;
|
||||
import src.fr.api.PartType;
|
||||
import src.fr.api.CompatibilityManager;
|
||||
import src.fr.api.Configuration;
|
||||
import src.fr.api.Part;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfigurationImpl implements src.fr.api.Configuration {
|
||||
private Set<PartType> selectedParts;
|
||||
public class ConfigurationImpl implements Configuration {
|
||||
private Set<Part> selectedParts;
|
||||
private CompatibilityManager compatibilityManager;
|
||||
private static int NB_CATEGORY = 4;
|
||||
|
||||
@@ -16,7 +17,7 @@ public class ConfigurationImpl implements src.fr.api.Configuration {
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
if (this.isComplete()){
|
||||
for(PartType pt: selectedParts){
|
||||
for(Part pt: selectedParts){
|
||||
//Verifier Requirements
|
||||
for(PartType require : compatibilityManager.getRequirements(pt)){
|
||||
if(!selectedParts.contains(require)) return false;
|
||||
|
||||
@@ -3,12 +3,13 @@ package src.fr.impl;
|
||||
import src.fr.api.Category;
|
||||
import src.fr.api.CompatibilityChecker;
|
||||
import src.fr.api.Configuration;
|
||||
import src.fr.api.Configurator;
|
||||
import src.fr.api.PartType;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfiguratorImpl implements src.fr.api.Configurator {
|
||||
public class ConfiguratorImpl implements Configurator {
|
||||
private Set<Category> categories;
|
||||
private Set<PartType> partTypes;
|
||||
private Configuration configuration;
|
||||
|
||||
@@ -1,37 +1,79 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import src.fr.api.Part;
|
||||
import src.fr.api.Category;
|
||||
import src.fr.api.PartType;
|
||||
|
||||
public class PartImpl implements src.fr.api.Part {
|
||||
public class PartImpl implements Part {
|
||||
|
||||
private PartType type;
|
||||
|
||||
private class Property {
|
||||
public final Supplier<String> getter;
|
||||
public final Consumer<String> setter;
|
||||
public final Set<String> possibleValues;
|
||||
|
||||
Property(Supplier<String> getter, Consumer<String> setter, Set<String> possibleValues) {
|
||||
this.getter = getter;
|
||||
this.setter = setter;
|
||||
this.possibleValues = possibleValues;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Property> properties = new HashMap<>();
|
||||
|
||||
protected void addProperty(String name, Supplier<String> getter, Consumer<String> setter, Set<String> possibleValues) {
|
||||
properties.put(name, new Property(getter, setter, possibleValues));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getPropertyNames() {
|
||||
return Collections.unmodifiableSet(properties.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getProperty(String propertyName) {
|
||||
Objects.requireNonNull(propertyName);
|
||||
|
||||
if (properties.containsKey(propertyName)) {
|
||||
return Optional.of(properties.get(propertyName).getter.get());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(String propertyName, String propertyValue) {
|
||||
Objects.requireNonNull(propertyName);
|
||||
Objects.requireNonNull(propertyValue);
|
||||
|
||||
if ((properties.containsKey(propertyName)) && (properties.get(propertyName).setter != null)) {
|
||||
properties.get(propertyName).setter.accept(propertyValue);
|
||||
} else {
|
||||
throw new IllegalArgumentException("bad property name or value: " + propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAvailablePropertyValues(String propertyName) {
|
||||
if (properties.containsKey(propertyName)) {
|
||||
return Collections.unmodifiableSet(properties.get(propertyName).possibleValues);
|
||||
}
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,37 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import src.fr.api.Category;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PartTypeImpl implements src.fr.api.PartType {
|
||||
import src.fr.api.Category;
|
||||
import src.fr.api.PartType;
|
||||
|
||||
public class PartTypeImpl implements PartType {
|
||||
private String name;
|
||||
private Category category;
|
||||
|
||||
//V2 implement
|
||||
private Class<? extends PartImpl> classRef;
|
||||
|
||||
public PartTypeImpl(String name, Category category ) {
|
||||
public PartTypeImpl(String name,Class<? extends PartImpl> classref, Category category ) {
|
||||
this.name = name;
|
||||
this.classRef= classref;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public PartImpl newInstance(){
|
||||
Constructor<? extends PartImpl> constructor;
|
||||
try{
|
||||
constructor = classRef.getConstructor();
|
||||
return constructor.newInstance();
|
||||
} catch(Exception e){
|
||||
Logger.getGlobal().log(Level.SEVERE, "constructor call failed",e);
|
||||
System.exit(-1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user