-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
856fc87
commit 897f726
Showing
3 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
reference-examples/generation/src/main/java/com/fluxtion/example/reference/AddByName.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,47 @@ | ||
package com.fluxtion.example.reference; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import com.fluxtion.runtime.node.NamedNode; | ||
|
||
public class AddByName { | ||
|
||
public static class MyNode { | ||
|
||
private final String name; | ||
|
||
public MyNode(String name) { | ||
this.name = name; | ||
} | ||
|
||
|
||
public String getName() { | ||
return name; | ||
} | ||
} | ||
|
||
public static class MyNamedNode implements NamedNode { | ||
|
||
private final String name; | ||
|
||
public MyNamedNode(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws NoSuchFieldException { | ||
var processor = Fluxtion.interpret(cfg -> { | ||
cfg.addNode(new MyNode("customName"), "overrideName"); | ||
cfg.addNode(new MyNamedNode("name1")); | ||
}); | ||
processor.init(); | ||
|
||
System.out.println(processor.<MyNode>getNodeById("overrideName").getName()); | ||
System.out.println(processor.<MyNamedNode>getNodeById("name1").getName()); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...nce-examples/generation/src/main/java/com/fluxtion/example/reference/InjectNoFactory.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,41 @@ | ||
package com.fluxtion.example.reference; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import com.fluxtion.runtime.annotations.OnTrigger; | ||
import com.fluxtion.runtime.annotations.builder.Inject; | ||
|
||
public class InjectNoFactory { | ||
public static class MyNode { | ||
@OnEventHandler | ||
public boolean handleStringEvent(String stringToProcess) { | ||
System.out.println("MyNode::received:" + stringToProcess); | ||
return true; | ||
} | ||
} | ||
|
||
public static class Root1 { | ||
@Inject | ||
private final MyNode myNode; | ||
|
||
public Root1() { | ||
myNode = null; | ||
} | ||
|
||
public Root1(MyNode myNode) { | ||
this.myNode = myNode; | ||
} | ||
|
||
@OnTrigger | ||
public boolean trigger() { | ||
System.out.println("Root1::triggered"); | ||
return true; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
var processor = Fluxtion.interpret(cfg -> cfg.addNode(new Root1())); | ||
processor.init(); | ||
processor.onEvent("TEST"); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...ples/generation/src/main/java/com/fluxtion/example/reference/SharedEqualityReference.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,76 @@ | ||
package com.fluxtion.example.reference; | ||
|
||
import com.fluxtion.compiler.Fluxtion; | ||
import com.fluxtion.runtime.annotations.OnEventHandler; | ||
import com.fluxtion.runtime.annotations.OnTrigger; | ||
|
||
import java.util.Objects; | ||
|
||
public class SharedEqualityReference { | ||
|
||
public static class MyNode { | ||
private final String name; | ||
int identifier; | ||
|
||
public MyNode(String name, int identifier) { | ||
this.name = name; | ||
this.identifier = identifier; | ||
} | ||
|
||
@OnEventHandler | ||
public boolean handleStringEvent(String stringToProcess) { | ||
System.out.println(name + " identifier:" + identifier + " received:" + stringToProcess); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
MyNode myNode = (MyNode) o; | ||
return name.equals(myNode.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return name.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MyNode{" + | ||
"name='" + name + '\'' + | ||
", identifier=" + identifier + | ||
'}'; | ||
} | ||
} | ||
|
||
public static class Root1 { | ||
private final String name; | ||
private final MyNode myNode; | ||
|
||
public Root1(String name, MyNode myNode) { | ||
this.name = name; | ||
this.myNode = myNode; | ||
System.out.println(name + "::new " + myNode); | ||
} | ||
|
||
@OnTrigger | ||
public boolean trigger() { | ||
System.out.println(name + "::triggered " + myNode); | ||
return true; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
var processor = Fluxtion.interpret(cfg -> { | ||
MyNode myNode1 = new MyNode("myNode_1", 999); | ||
MyNode myNode2 = new MyNode("myNode_1", 444); | ||
cfg.addNode(new Root1("root_1", myNode1)); | ||
cfg.addNode(new Root1("root_2", myNode2)); | ||
}); | ||
processor.init(); | ||
System.out.println(); | ||
processor.onEvent("TEST"); | ||
} | ||
} |