2
* Copyright 2003-2007 the original author or authors.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package org.codehaus.groovy.runtime;
20
import groovy.lang.Closure;
23
* Represents wrapper around a Closure to support currying
25
* @author Jochen Theodorou
27
public final class CurriedClosure extends Closure {
29
private Object[] curriedParams;
31
public CurriedClosure(Closure uncurriedClosure, Object[] arguments) {
32
super(uncurriedClosure);
33
curriedParams = arguments;
34
maximumNumberOfParameters = uncurriedClosure.getMaximumNumberOfParameters()-arguments.length;
37
public CurriedClosure(Closure uncurriedClosure, int i) {
38
this(uncurriedClosure, new Object[]{Integer.valueOf(i)});
41
public Object[] getUncurriedArguments(Object[] arguments) {
42
final Object newCurriedParams[] = new Object[curriedParams.length + arguments.length];
43
System.arraycopy(curriedParams, 0, newCurriedParams, 0, curriedParams.length);
44
System.arraycopy(arguments, 0, newCurriedParams, curriedParams.length, arguments.length);
45
return newCurriedParams;
48
public void setDelegate(Object delegate) {
49
((Closure)getOwner()).setDelegate(delegate);
52
public Object clone() {
53
Closure uncurriedClosure = (Closure) ((Closure) getOwner()).clone();
54
return new CurriedClosure(uncurriedClosure,curriedParams);
57
public Class[] getParameterTypes() {
58
Class[] oldParams = ((Closure)getOwner()).getParameterTypes();
59
Class[] newParams = new Class[oldParams.length-curriedParams.length];
60
System.arraycopy(oldParams, curriedParams.length, newParams, 0, newParams.length);
2
* Copyright 2003-2007 the original author or authors.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package org.codehaus.groovy.runtime;
20
import groovy.lang.Closure;
23
* Represents wrapper around a Closure to support currying
25
* @author Jochen Theodorou
27
public final class CurriedClosure extends Closure {
29
private Object[] curriedParams;
31
public CurriedClosure(Closure uncurriedClosure, Object[] arguments) {
32
super(uncurriedClosure);
33
curriedParams = arguments;
34
maximumNumberOfParameters = uncurriedClosure.getMaximumNumberOfParameters()-arguments.length;
37
public CurriedClosure(Closure uncurriedClosure, int i) {
38
this(uncurriedClosure, new Object[]{Integer.valueOf(i)});
41
public Object[] getUncurriedArguments(Object[] arguments) {
42
final Object newCurriedParams[] = new Object[curriedParams.length + arguments.length];
43
System.arraycopy(curriedParams, 0, newCurriedParams, 0, curriedParams.length);
44
System.arraycopy(arguments, 0, newCurriedParams, curriedParams.length, arguments.length);
45
return newCurriedParams;
48
public void setDelegate(Object delegate) {
49
((Closure)getOwner()).setDelegate(delegate);
52
public Object clone() {
53
Closure uncurriedClosure = (Closure) ((Closure) getOwner()).clone();
54
return new CurriedClosure(uncurriedClosure,curriedParams);
57
public Class[] getParameterTypes() {
58
Class[] oldParams = ((Closure)getOwner()).getParameterTypes();
59
Class[] newParams = new Class[oldParams.length-curriedParams.length];
60
System.arraycopy(oldParams, curriedParams.length, newParams, 0, newParams.length);