forked from micronaut-projects/micronaut-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support BiConsumer/BiFunction in Groovy
- Loading branch information
1 parent
632e8be
commit aa48927
Showing
26 changed files
with
870 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
function-groovy/src/main/groovy/org/particleframework/function/groovy/FunctionScript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2017 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.particleframework.function.groovy; | ||
|
||
import org.particleframework.context.ApplicationContext; | ||
import org.particleframework.context.env.PropertySource; | ||
import org.particleframework.core.annotation.Internal; | ||
import org.particleframework.function.executor.FunctionInitializer; | ||
|
||
import java.util.Iterator; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Base class for Function scripts | ||
* | ||
* @author Graeme Rocher | ||
* @since 1.0 | ||
*/ | ||
public abstract class FunctionScript extends FunctionInitializer implements PropertySource { | ||
|
||
public FunctionScript() { | ||
} | ||
|
||
protected FunctionScript(ApplicationContext applicationContext) { | ||
super(applicationContext, false); | ||
} | ||
|
||
private Map<String, Object> props; | ||
|
||
@Override | ||
@Internal | ||
public Object get(String key) { | ||
return resolveProps().get(key); | ||
} | ||
|
||
@Override | ||
@Internal | ||
public Iterator<String> iterator() { | ||
return resolveProps().keySet().iterator(); | ||
} | ||
|
||
protected void addProperty(String name, Object value) { | ||
resolveProps().put(name, value); | ||
} | ||
|
||
private Map<String, Object> resolveProps() { | ||
if(props == null) { | ||
props = new LinkedHashMap<>(); | ||
} | ||
return props; | ||
} | ||
|
||
@Override | ||
@Internal | ||
protected void startThis(ApplicationContext applicationContext) { | ||
// no-op this, equivalent behaviour will be called from the script constructor | ||
} | ||
|
||
@Override | ||
@Internal | ||
protected void injectThis(ApplicationContext applicationContext) { | ||
// no-op this, equivalent behaviour will be called from the script constructor | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.