Mercurial > hg > Database > Christie
changeset 141:8caca9158f0f
add FizzBuzz example
author | ichikitakahiro <e165713@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Jan 2019 19:17:08 +0900 |
parents | 6b33e7dfb146 |
children | 96f9c7c58c2b |
files | src/test/java/christie/example/FizzBuzz/Counter.java src/test/java/christie/example/FizzBuzz/FizzBuzz.java src/test/java/christie/example/FizzBuzz/StartFizzBuzz.java |
diffstat | 3 files changed, 73 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/FizzBuzz/Counter.java Thu Jan 03 19:17:08 2019 +0900 @@ -0,0 +1,22 @@ +package christie.example.FizzBuzz; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; + +public class Counter extends CodeGear { + @Take + int num; + + @Override + protected void run(CodeGearManager cgm) { + //System.out.println(num); + if (num <= 100) { + getDGM("fizzBuzz").put("num", num); + cgm.getLocalDGM().put("num", num + 1); + cgm.setup(new Counter()); + } + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/FizzBuzz/FizzBuzz.java Thu Jan 03 19:17:08 2019 +0900 @@ -0,0 +1,26 @@ +package christie.example.FizzBuzz; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; + +public class FizzBuzz extends CodeGear { + + @Take + int num; + + @Override + protected void run(CodeGearManager cgm) { + if (num % 3 == 0 && num % 5 == 0) { + System.out.println(num + ":FizzBuzz"); + }else if(num % 3 == 0){ + System.out.println(num + ":Fizz"); + }else if(num % 5 == 0){ + System.out.println(num + ":Buzz"); + }else{ + System.out.println(num); + } + cgm.setup(new FizzBuzz()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/FizzBuzz/StartFizzBuzz.java Thu Jan 03 19:17:08 2019 +0900 @@ -0,0 +1,25 @@ +package christie.example.FizzBuzz; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGearManager; +import christie.codegear.StartCodeGear; + +public class StartFizzBuzz extends StartCodeGear { + @Take + int i = 1; + + + public StartFizzBuzz(CodeGearManager cgm) { + super(cgm); + } + + public static void main(String[] args) { + CodeGearManager counter = createCGM(10001); + CodeGearManager fizzBuzz = createCGM(10002); + counter.setup(new Counter()); + fizzBuzz.setup(new FizzBuzz()); + counter.createRemoteDGM("fizzBuzz","localhost",10002); + counter.getLocalDGM().put("num", 1); + } +}