Advertisement
Guest User

Untitled

a guest
May 26th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. package main.java.Platform.demo;
  2.  
  3. import java.time.Clock;
  4. import java.time.Instant;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.Scanner;
  8.  
  9. import main.java.Platform.Chimera.implementation.Platform.ChimeraExecutable;
  10. import main.java.Platform.Chimera.implementation.Platform.Transaction.Annotation.Transaction;
  11. import main.java.Platform.Chimera.implementation.common.ChimeraSignature;
  12.  
  13. public class DemoApp extends ChimeraExecutable {
  14.     private List<String> log = new ArrayList<>();
  15.  
  16.     public DemoApp(DemoUser user) {
  17.         super(user);
  18.     }
  19.  
  20.     @Override
  21.     public void main() {
  22.         Scanner in = new Scanner(System.in);
  23.  
  24.         //literally a bug in the AspectJ compiler that a while/for will not work here
  25.         recurseInsteadOfWhile(in);
  26.     }
  27.  
  28.     private void recurseInsteadOfWhile(Scanner in){
  29.         while (true) {
  30.             System.out.print("> ");
  31.             String what = in.nextLine();
  32.             ChimeraSignature sig = user.sign(what);
  33.             if (what.equals("!exit")) {
  34.                 System.out.println("<chat end>");
  35.                 in.close();
  36.                 System.out.println(this.getState());
  37.                 return;
  38.             }
  39.  
  40.             timeStamp(Clock.systemUTC().instant());
  41.             say((DemoUser) this.user, what, sig);
  42.  
  43.         }
  44.     }
  45.  
  46.     @Transaction
  47.     public void timeStamp(Instant time){
  48.         log.add(time.toString());
  49.     }
  50.  
  51.     @Transaction
  52.     public void say(DemoUser who, String what, ChimeraSignature sig) {
  53.         if(who.verifySignature(what, sig))
  54.            log.add(who.getName() + ": " + what);
  55.         printState();
  56.     }
  57.  
  58.     private void printState() {
  59.         System.out.println("==== LOG ====");
  60.         for (String s : log) {
  61.             System.out.println(s);
  62.         }
  63.         System.out.println("=============");
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement