-
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.
- Loading branch information
Showing
12 changed files
with
215 additions
and
140 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
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
91 changes: 91 additions & 0 deletions
91
rimor/src/main/java/st/networkers/rimor/instruction/HandlerMethodInstruction.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,91 @@ | ||
package st.networkers.rimor.instruction; | ||
|
||
import st.networkers.rimor.inject.ExecutionContext; | ||
import st.networkers.rimor.inject.RimorInjector; | ||
import st.networkers.rimor.reflect.CachedMethod; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
public class HandlerMethodInstruction implements Instruction { | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
private final RimorInjector injector; | ||
|
||
private final Object bean; | ||
private final CachedMethod method; | ||
private final Collection<String> identifiers; | ||
|
||
public HandlerMethodInstruction(RimorInjector injector, Object bean, CachedMethod method, Collection<String> identifiers) { | ||
this.injector = injector; | ||
this.bean = bean; | ||
this.method = method; | ||
this.identifiers = identifiers; | ||
} | ||
|
||
@Override | ||
public Object run(ExecutionContext executionContext) { | ||
return injector.invokeMethod(method, bean, executionContext); | ||
} | ||
|
||
public Object getBean() { | ||
return bean; | ||
} | ||
|
||
public CachedMethod getMethod() { | ||
return method; | ||
} | ||
|
||
public Collection<String> getIdentifiers() { | ||
return identifiers; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof HandlerMethodInstruction)) return false; | ||
HandlerMethodInstruction that = (HandlerMethodInstruction) o; | ||
return Objects.equals(bean, that.bean) && Objects.equals(method, that.method) && Objects.equals(identifiers, that.identifiers); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(bean, method, identifiers); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private RimorInjector injector; | ||
private Object bean; | ||
private Method method; | ||
private Collection<String> identifiers; | ||
|
||
public Builder setInjector(RimorInjector injector) { | ||
this.injector = injector; | ||
return this; | ||
} | ||
|
||
public Builder setBean(Object bean) { | ||
this.bean = bean; | ||
return this; | ||
} | ||
|
||
public Builder setMethod(Method method) { | ||
this.method = method; | ||
return this; | ||
} | ||
|
||
public Builder setIdentifiers(Collection<String> identifiers) { | ||
this.identifiers = identifiers; | ||
return this; | ||
} | ||
|
||
public HandlerMethodInstruction create() { | ||
return new HandlerMethodInstruction(injector, bean, CachedMethod.build(method), identifiers); | ||
} | ||
} | ||
} |
45 changes: 6 additions & 39 deletions
45
rimor/src/main/java/st/networkers/rimor/instruction/Instruction.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 |
---|---|---|
@@ -1,46 +1,13 @@ | ||
package st.networkers.rimor.instruction; | ||
|
||
import st.networkers.rimor.execute.Executable; | ||
import st.networkers.rimor.reflect.CachedMethod; | ||
import st.networkers.rimor.inject.ExecutionContext; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
/** | ||
* A command instruction. | ||
*/ | ||
public interface Instruction extends Executable { | ||
|
||
public class Instruction implements Executable { | ||
Object run(ExecutionContext executionContext); | ||
|
||
private final Object commandInstance; | ||
private final CachedMethod method; | ||
|
||
private final Collection<String> identifiers; | ||
|
||
public Instruction(Object commandInstance, CachedMethod method, Collection<String> identifiers) { | ||
this.commandInstance = commandInstance; | ||
this.method = method; | ||
this.identifiers = identifiers; | ||
} | ||
|
||
public Object getCommandInstance() { | ||
return commandInstance; | ||
} | ||
|
||
public CachedMethod getMethod() { | ||
return method; | ||
} | ||
|
||
public Collection<String> getIdentifiers() { | ||
return identifiers; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof Instruction)) return false; | ||
Instruction that = (Instruction) o; | ||
return Objects.equals(commandInstance, that.commandInstance) && Objects.equals(method, that.method) && Objects.equals(identifiers, that.identifiers); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(commandInstance, method, identifiers); | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
rimor/src/main/java/st/networkers/rimor/instruction/InstructionBuilder.java
This file was deleted.
Oops, something went wrong.
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.