/** * Spread the trailing [] argument into its component type assigning given names. * * @param baseName base name of the spread arguments * @param count number of arguments into which the last argument will decompose * @return a new signature with decomposed arguments in place of the trailing array */ public Signature spread(String baseName, int count) { String[] spreadNames = new String[count]; for (int i = 0; i < count; i++) spreadNames[i] = baseName + i; return spread(spreadNames); }
/** * Spread the trailing [] argument into its component type assigning given names. * * @param names names to use for the decomposed arguments * @return a new signature with decomposed arguments in place of the trailing array */ public Signature spread(String... names) { Class<?> aryType = lastArgType(); assert lastArgType().isArray(); Class<?>[] newTypes = new Class<?>[names.length]; Arrays.fill(newTypes, aryType.getComponentType()); return spread(names, newTypes); }
/** * Spread a trailing array into the specified argument types. * * @param spreadNames the names for the spread out arguments * @param spreadTypes the types as which to spread the incoming array * @return a new SmartBinder with the spread applied */ public SmartBinder spread(String[] spreadNames, Class<?>... spreadTypes) { return new SmartBinder(this, signature().spread(spreadNames, spreadTypes), binder.spread(spreadTypes)); }
/** * Spread a trailing array into count number of arguments, using the * natural component type for the array. Build names for the arguments * using the given baseName plus the argument's index. * * Example: * Current binder has a signature of (int, String[])void. We want * to spread the strings into five arguments named "str". * * <code>binder = binder.spread("str", 5)</code> * * The resulting signature will have five trailing arguments named * "arg0" through "arg4". * * @param baseName the base name from which to create the new argument names * @param count the count of arguments to spread * @return a new SmartBinder with the spread applied */ public SmartBinder spread(String baseName, int count) { return new SmartBinder(this, signature().spread(baseName, count), binder.spread(count)); }