[maven-release-plugin] copy for tag wamblee-utils-0.2
[utils] / system / general / src / main / java / org / wamblee / system / adapters / ParameterValues.java
index 413481907a92dce77853cc40caa5bb9b75ed7164..1778981875ce07cff6286b1fdebc73781d92bfb8 100644 (file)
@@ -22,7 +22,14 @@ import org.wamblee.system.core.DefaultRequiredInterface;
 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;
 
@@ -33,10 +40,32 @@ public class ParameterValues {
         * @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;
        }
@@ -68,10 +97,15 @@ public class ParameterValues {
                _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) { 
@@ -82,6 +116,11 @@ public class ParameterValues {
                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++) {