import org.wamblee.system.core.RequiredInterface;
import org.wamblee.system.core.Scope;
+/**
+ * Represents parameter values for a method or constructor and allows for the configuration
+ * of how these values are retrieved.
+ *
+ * @author Erik Brakkee
+ */
public class ParameterValues {
+ private String[] _names;
private Class[] _types;
private ValueProvider[] _values;
* @param aClass Class to construct.
*/
public ParameterValues(Class[] aTypes) {
+ _names = new String[aTypes.length];
+ for (int i = 0; i < aTypes.length; i++) {
+ _names[i] = "arg" + i;
+ }
_types = aTypes;
resetValues();
}
+ /**
+ * Constructs the configuration. By default no constructor is selected and
+ * one of {@link #select(Class...)} or
+ * {@link #greedy()} must be called.
+ * @param aNames Names of the arguments.
+ * @param aClass Class to construct.
+ */
+ public ParameterValues(String[] aNames, Class[] aTypes) {
+ assert aNames.length == aTypes.length;
+ _names = aNames;
+ _types = aTypes;
+ resetValues();
+ }
+
+ /**
+ * The types of the parameter values.
+ * @return Types.
+ */
public Class[] getTypes() {
return _types;
}
_values = new ValueProvider[_types.length];
for (int i = 0; i < _values.length; i++) {
_values[i] = new RequiredInterfaceProvider(new DefaultRequiredInterface(
- "arg" + i, _types[i]));
+ _names[i], _types[i]));
}
}
+ /**
+ * Gets the required interfaces to provide values that are not provided
+ * in another way.
+ * @return Required interfaces.
+ */
public List<RequiredInterface> getRequiredInterfaces() {
List<RequiredInterface> result = new ArrayList<RequiredInterface>();
for (ValueProvider provider: _values) {
return result;
}
+ /**
+ * Returns the values to use in the given scope.
+ * @param aScope Scope within which to retrieve the values.
+ * @return Values.
+ */
public Object[] values(Scope aScope) {
Object[] values = new Object[_values.length];
for (int i = 0; i < _values.length; i++) {