test v2
This commit is contained in:
BIN
V2/ACO TD5 guide for students.pdf
Normal file
BIN
V2/ACO TD5 guide for students.pdf
Normal file
Binary file not shown.
13
V2/snippet API V2.txt
Normal file
13
V2/snippet API V2.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Changes to the V1 API
|
||||
*/
|
||||
public Set<Part> getSelectedParts();
|
||||
public Optional<Part> getSelectionForCategory(Category category);
|
||||
and for Part.java :
|
||||
public interface Part extends PropertyManager {
|
||||
default String getName() {
|
||||
return this.getClass().getTypeName();
|
||||
};
|
||||
Category getCategory();
|
||||
PartType getType();
|
||||
}
|
||||
60
V2/snippet PropertyManager implementation.txt
Normal file
60
V2/snippet PropertyManager implementation.txt
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Snippet to add a basic implementation of PropertyManager
|
||||
*/
|
||||
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();
|
||||
}
|
||||
24
V2/snippet V2 PartTypeImpl.txt
Normal file
24
V2/snippet V2 PartTypeImpl.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Snippet to add to your PartTypeImpl to support
|
||||
* the V2 API
|
||||
*/
|
||||
public class PartTypeImpl implements PartType {
|
||||
private String name;
|
||||
private Class<? extends PartImpl> classRef;
|
||||
private 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;
|
||||
}
|
||||
Reference in New Issue
Block a user