diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java index 12c2a47..08338b0 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java @@ -2,9 +2,9 @@ import javax.ws.rs.client.*; public class Group { - private List messages; - private Client client = ClientBuilder.newClient(); private List members; + private Client client = ClientBuilder.newClient(); + private List messages; public Map getValue() { Map temp_nil0 = new HashMap<>(); temp_nil0.put("messages",this.getMessages()); @@ -17,6 +17,9 @@ public List getMembers() { return this.members; } + public String getMember(int mno) { + return this.members.get(mno); + } public void postMessage(String gid, String message) throws JsonProcessingException { for (int mno = 0; mno < members.size(); mno++) { String member = getMember(mno); diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java index 9ce9193..cc91714 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java @@ -30,6 +30,12 @@ public List getMessagesValue(@PathParam("gid") String gid) { return getGroup(gid).getMessages(); } + @Path("/{gid}/members/{mno}") + @Produces(MediaType.APPLICATION_JSON) + @GET + public String getMemberValue(@PathParam("gid") String gid, @PathParam("mno") int mno) { + return getGroup(gid).getMember(mno); + } @Path("/{gid}/members") @Produces(MediaType.APPLICATION_JSON) @GET diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java new file mode 100644 index 0000000..ff5dda3 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java @@ -0,0 +1,34 @@ +import java.util.*; + +public class Account { + private String name; + private int point; + public Map getValue() { + Map temp_nil9 = new HashMap<>(); + temp_nil9.put("point",this.getPoint()); + temp_nil9.put("name",this.getName()); + return temp_nil9; + } + public String getName() { + return this.name; + } + public int getPoint() { + return point; + } + public void updatePointFromBattle(String self, String rid, int mno, boolean battle, String id) { + int temp_if0; + if (hasWon) { + temp_if0 = (this.point+1); + } else { + temp_if0 = this.point; + } + this.point = temp_if0; + } + public void changeName(String aid, String name) { + this.name = name; + } + public Account(String name, int point) { + this.name = name; + this.point = point; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java new file mode 100644 index 0000000..0e9528b --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java @@ -0,0 +1,53 @@ +import java.util.*; +import javax.ws.rs.*; +import javax.ws.rs.client.*; +import javax.ws.rs.core.*; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.JsonProcessingException; + +@Path("/accounts") +@Component +public class Accounts { + private Map value = new HashMap<>(); + @Produces(MediaType.APPLICATION_JSON) + @GET + public Map getValue() { + return new HashMap<>(value); + } + public Account getAccount(String mid) { + return this.value.get(mid); + } + @Path("accounts/{mid}/point") + @POST + public void updatePointFromBattle(@PathParam("mid") String mid, @FormParam("rid") String rid, @FormParam("mno") int mno, @FormParam("battle") boolean battle, @FormParam("id") String id) { + getAccount(mid).updatePointFromBattle(mid, rid, mno, battle, id); + } + @Path("/{mid}") + @Produces(MediaType.APPLICATION_JSON) + @GET + public Map getAccountValue(@PathParam("mid") String mid) { + return getAccount(mid).getValue(); + } + @Path("/{mid}/point") + @Produces(MediaType.APPLICATION_JSON) + @GET + public int getPointValue(@PathParam("mid") String mid) { + return getAccount(mid).getPoint(); + } + @Path("/{mid}/name") + @Produces(MediaType.APPLICATION_JSON) + @GET + public String getNameValue(@PathParam("mid") String mid) { + return getAccount(mid).getName(); + } + @POST + public void signUp(@FormParam("name") String name, @FormParam("aid") String aid) { + this.value.put(aid,new Account(name, 0)); + } + @Path("/{aid}/name") + @PUT + public void changeName(@PathParam("aid") String aid, @FormParam("name") String name) { + getAccount(aid).changeName(aid, name); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java new file mode 100644 index 0000000..f721703 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java @@ -0,0 +1,23 @@ +import java.util.*; +import javax.ws.rs.client.*; + +public class Member { + private Client client = ClientBuilder.newClient(); + private String id; + public Map getValue() { + Map temp_nil10 = new HashMap<>(); + temp_nil10.put("name",this.getName()); + temp_nil10.put("id",this.getId()); + return temp_nil10; + } + public String getName() { + String name = client.target("http://localhost:8080").path("/accounts."+id+".name").request().get(String.class); + return name; + } + public String getId() { + return this.id; + } + public Member(String id) { + this.id = id; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Members.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Members.java new file mode 100644 index 0000000..0dd75c8 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Members.java @@ -0,0 +1,14 @@ +import java.util.*; + +public class Members { + private List value = new ArrayList<>(); + public List getValue() { + return new ArrayList<>(value); + } + public Member getMember(int mno) { + return this.value.get(mno); + } + public void addRoomMember(String rid, String id) { + this.value.add(new Member(id)); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java new file mode 100644 index 0000000..581174c --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java @@ -0,0 +1,36 @@ +import java.util.*; +import javax.ws.rs.client.*; + +public class Room { + private Members members = new Members(); + private boolean battle; + private Client client = ClientBuilder.newClient(); + public Map getValue() { + Map temp_nil8 = new HashMap<>(); + temp_nil8.put("members",this.members.getValue()); + temp_nil8.put("battle",this.getBattle()); + return temp_nil8; + } + public Members getMembers() { + return this.members; + } + public boolean getBattle() { + return this.battle; + } + public void battle(String rid, boolean hasWon) throws JsonProcessingException { + for (int mno = 0; mno < members.getValue().size(); mno++) { + String id = getMembers().getMember(mno).getId(); + Form form = new Form(); + form.param("rid", rid.toString()); + form.param("mno", Integer.toString(mno)); + form.param("battle", Boolean.toString(battle)); + form.param("id", id.toString()); + Entity
entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); + String result = client.target("http://localhost:8080").path("/accounts."+id+".point").request().post(entity, String.class); + } + this.battle = hasWon; + } + public Room(boolean battle) { + this.battle = battle; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java new file mode 100644 index 0000000..8e0cde3 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java @@ -0,0 +1,71 @@ +import java.util.*; +import javax.ws.rs.*; +import javax.ws.rs.client.*; +import javax.ws.rs.core.*; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.JsonProcessingException; + +@Path("/rooms") +@Component +public class Rooms { + private Map value = new HashMap<>(); + @Produces(MediaType.APPLICATION_JSON) + @GET + public Map getValue() { + return new HashMap<>(value); + } + public Room getRoom(String rid) { + return this.value.get(rid); + } + @Path("/{rid}/members/{mno}/name") + @Produces(MediaType.APPLICATION_JSON) + @GET + public String getNameValue(@PathParam("rid") String rid, @PathParam("mno") int mno) { + return getRoom(rid).getMembers().getMember(mno).getName(); + } + @Path("/{rid}/members/{mno}") + @Produces(MediaType.APPLICATION_JSON) + @GET + public Map getMemberValue(@PathParam("rid") String rid, @PathParam("mno") int mno) { + return getRoom(rid).getMembers().getMember(mno).getValue(); + } + @Path("/{rid}/members/{mno}/id") + @Produces(MediaType.APPLICATION_JSON) + @GET + public String getIdValue(@PathParam("rid") String rid, @PathParam("mno") int mno) { + return getRoom(rid).getMembers().getMember(mno).getId(); + } + @Path("/{rid}") + @Produces(MediaType.APPLICATION_JSON) + @GET + public Map getRoomValue(@PathParam("rid") String rid) { + return getRoom(rid).getValue(); + } + @Path("/{rid}/members") + @Produces(MediaType.APPLICATION_JSON) + @GET + public List getMembersValue(@PathParam("rid") String rid) { + return getRoom(rid).getMembers().getValue(); + } + @Path("/{rid}/battle") + @Produces(MediaType.APPLICATION_JSON) + @GET + public boolean getBattleValue(@PathParam("rid") String rid) { + return getRoom(rid).getBattle(); + } + @POST + public void createRoom(@FormParam("rid") String rid) { + this.value.put(rid,new Room(false)); + } + @Path("/{rid}/members") + @POST + public void addRoomMember(@PathParam("rid") String rid, @FormParam("id") String id) { + getRoom(rid).getMembers().addRoomMember(rid, id); + } + @Path("/{rid}/battle") + @PUT + public void battle(@PathParam("rid") String rid, @FormParam("hasWon") boolean hasWon) throws JsonProcessingException { + getRoom(rid).battle(rid, hasWon); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Account.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Account.java index 4bed2b8..b41f785 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Account.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Account.java @@ -8,7 +8,10 @@ return temp_nil3; } public Map getNotifications() { - return this.notifications; + return new HashMap<>(notifications); + } + public void updateNotificationsFromMessages(String gid, int mno, List messages, String members) { + this.notifications.put(gid,true); } public void hasRead(String aid, String gid) { this.notifications.remove(gid); diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Group.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Group.java index 1bba44d..aacb2f8 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Group.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Group.java @@ -1,28 +1,37 @@ import java.util.*; public class Group { - private List messages; private List members; + private List messages; + private Account account; + private Accounts accounts; public Map getValue() { Map temp_nil2 = new HashMap<>(); - temp_nil2.put("members",this.getMembers()); temp_nil2.put("messages",this.getMessages()); + temp_nil2.put("members",this.getMembers()); return temp_nil2; } - public List getMessages() { - return this.messages; + public String getMember(int mno) { + return this.members.get(mno); } public List getMembers() { return this.members; } + public List getMessages() { + return this.messages; + } public void postMessage(String gid, String message) { this.messages.add(message); + + String member = this.groups.getGroup(gid).getMember(mno); + this.account.updateNotificationsFromMessages(gid, mno, messages, member); } public void addGroupMember(String gid, String aid) { this.members.add(aid); } - public Group(List messages, List members) { - this.messages = messages; + public Group(List members, List messages, Accounts accounts) { this.members = members; + this.messages = messages; + this.accounts = accounts; } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/GroupChat.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/GroupChat.java index f3ddadd..8b141cf 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/GroupChat.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/GroupChat.java @@ -7,29 +7,20 @@ accounts = new Accounts(); groups = new Groups(); } + public Map getGroup(String gid) { + return this.groups.getGroup(gid).getValue(); + } public Map getAccounts() { return this.accounts.getValue(); } public void signUp(String aid) { this.accounts.signUp(aid); } - public Map getNotifications(String v1) { - return this.accounts.getAccount(v1).getNotifications(); + public String getMember(String gid, int mno) { + return this.groups.getGroup(gid).getMember(mno); } - public void hasRead(String aid, String gid) { - this.accounts.getAccount(aid).hasRead(aid, gid); - } - public Map getGroups() { - return this.groups.getValue(); - } - public void createGroup(String gid) { - this.groups.createGroup(gid); - } - public List getMessages(String gid) { - return this.groups.getGroup(gid).getMessages(); - } - public void postMessage(String gid, String message) { - this.groups.getGroup(gid).postMessage(gid, message); + public Map getAccount(String v1) { + return this.accounts.getAccount(v1).getValue(); } public List getMembers(String gid) { return this.groups.getGroup(gid).getMembers(); @@ -37,10 +28,22 @@ public void addGroupMember(String gid, String aid) { this.groups.getGroup(gid).addGroupMember(gid, aid); } - public Map getGroup(String gid) { - return this.groups.getGroup(gid).getValue(); + public Map getNotifications(String v1) { + return this.accounts.getAccount(v1).getNotifications(); } - public Map getAccount(String v1) { - return this.accounts.getAccount(v1).getValue(); + public void hasRead(String aid, String gid) { + this.accounts.getAccount(aid).hasRead(aid, gid); + } + public List getMessages(String gid) { + return this.groups.getGroup(gid).getMessages(); + } + public void postMessage(String gid, String message) { + this.groups.getGroup(gid).postMessage(gid, message); + } + public Map getGroups() { + return this.groups.getValue(); + } + public void createGroup(String gid) { + this.groups.createGroup(gid); } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Groups.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Groups.java index 7e1cc35..014bc27 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Groups.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PULL-first/Groups.java @@ -9,6 +9,6 @@ return this.value.get(gid); } public void createGroup(String gid) { - this.value.put(gid,new Group(new ArrayList<>(), new ArrayList<>())); + this.value.put(gid,new Group(new ArrayList<>(), new ArrayList<>(), accounts)); } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Account.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Account.java index 31e9bb2..830c8ce 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Account.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Account.java @@ -8,7 +8,10 @@ return temp_nil7; } public Map getNotifications() { - return this.notifications; + return new HashMap<>(notifications); + } + public void updateNotificationsFromMessages(String gid, int mno, List messages, String members) { + this.notifications.put(gid,true); } public void hasRead(String aid, String gid) { this.notifications.remove(gid); diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Group.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Group.java index d97238f..6efaf35 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Group.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Group.java @@ -1,28 +1,37 @@ import java.util.*; public class Group { - private List messages; private List members; + private List messages; + private Account account; + private Accounts accounts; public Map getValue() { Map temp_nil6 = new HashMap<>(); - temp_nil6.put("members",this.getMembers()); temp_nil6.put("messages",this.getMessages()); + temp_nil6.put("members",this.getMembers()); return temp_nil6; } - public List getMessages() { - return this.messages; + public String getMember(int mno) { + return this.members.get(mno); } public List getMembers() { return this.members; } + public List getMessages() { + return this.messages; + } public void postMessage(String gid, String message) { this.messages.add(message); + + String member = this.groups.getGroup(gid).getMember(mno); + this.account.updateNotificationsFromMessages(gid, mno, messages, member); } public void addGroupMember(String gid, String aid) { this.members.add(aid); } - public Group(List messages, List members) { - this.messages = messages; + public Group(List members, List messages, Accounts accounts) { this.members = members; + this.messages = messages; + this.accounts = accounts; } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/GroupChat.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/GroupChat.java index f3ddadd..8b141cf 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/GroupChat.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/GroupChat.java @@ -7,29 +7,20 @@ accounts = new Accounts(); groups = new Groups(); } + public Map getGroup(String gid) { + return this.groups.getGroup(gid).getValue(); + } public Map getAccounts() { return this.accounts.getValue(); } public void signUp(String aid) { this.accounts.signUp(aid); } - public Map getNotifications(String v1) { - return this.accounts.getAccount(v1).getNotifications(); + public String getMember(String gid, int mno) { + return this.groups.getGroup(gid).getMember(mno); } - public void hasRead(String aid, String gid) { - this.accounts.getAccount(aid).hasRead(aid, gid); - } - public Map getGroups() { - return this.groups.getValue(); - } - public void createGroup(String gid) { - this.groups.createGroup(gid); - } - public List getMessages(String gid) { - return this.groups.getGroup(gid).getMessages(); - } - public void postMessage(String gid, String message) { - this.groups.getGroup(gid).postMessage(gid, message); + public Map getAccount(String v1) { + return this.accounts.getAccount(v1).getValue(); } public List getMembers(String gid) { return this.groups.getGroup(gid).getMembers(); @@ -37,10 +28,22 @@ public void addGroupMember(String gid, String aid) { this.groups.getGroup(gid).addGroupMember(gid, aid); } - public Map getGroup(String gid) { - return this.groups.getGroup(gid).getValue(); + public Map getNotifications(String v1) { + return this.accounts.getAccount(v1).getNotifications(); } - public Map getAccount(String v1) { - return this.accounts.getAccount(v1).getValue(); + public void hasRead(String aid, String gid) { + this.accounts.getAccount(aid).hasRead(aid, gid); + } + public List getMessages(String gid) { + return this.groups.getGroup(gid).getMessages(); + } + public void postMessage(String gid, String message) { + this.groups.getGroup(gid).postMessage(gid, message); + } + public Map getGroups() { + return this.groups.getValue(); + } + public void createGroup(String gid) { + this.groups.createGroup(gid); } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Groups.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Groups.java index 7e1cc35..014bc27 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Groups.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/GroupChat/PUSH-first/Groups.java @@ -9,6 +9,6 @@ return this.value.get(gid); } public void createGroup(String gid) { - this.value.put(gid,new Group(new ArrayList<>(), new ArrayList<>())); + this.value.put(gid,new Group(new ArrayList<>(), new ArrayList<>(), accounts)); } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Account.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Account.java new file mode 100644 index 0000000..7e7d242 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Account.java @@ -0,0 +1,34 @@ +import java.util.*; + +public class Account { + private String name; + private int point; + public Map getValue() { + Map temp_nil12 = new HashMap<>(); + temp_nil12.put("name",this.getName()); + temp_nil12.put("point",this.getPoint()); + return temp_nil12; + } + public String getName() { + return this.name; + } + public int getPoint() { + return point; + } + public void updatePointFromBattle(String self, String rid, int mno, boolean battle, String id) { + int temp_if1; + if (hasWon) { + temp_if1 = (this.point+1); + } else { + temp_if1 = this.point; + } + this.point = temp_if1; + } + public void changeName(String aid, String name) { + this.name = name; + } + public Account(String name, int point) { + this.name = name; + this.point = point; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Accounts.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Accounts.java new file mode 100644 index 0000000..6d92c89 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Accounts.java @@ -0,0 +1,14 @@ +import java.util.*; + +public class Accounts { + private Map value = new HashMap<>(); + public Map getValue() { + return new HashMap<>(value); + } + public Account getAccount(String mid) { + return this.value.get(mid); + } + public void signUp(String name, String aid) { + this.value.put(aid,new Account(name, 0)); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Member.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Member.java new file mode 100644 index 0000000..b23d481 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Member.java @@ -0,0 +1,23 @@ +import java.util.*; + +public class Member { + private String id; + private Account account; + private Accounts accounts; + public Map getValue() { + Map temp_nil13 = new HashMap<>(); + temp_nil13.put("id",this.getId()); + temp_nil13.put("name",this.getName()); + return temp_nil13; + } + public String getId() { + return this.id; + } + public String getName() { + return this.account.getName(); + } + public Member(String id, Accounts accounts) { + this.id = id; + this.accounts = accounts; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Members.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Members.java new file mode 100644 index 0000000..091b561 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Members.java @@ -0,0 +1,14 @@ +import java.util.*; + +public class Members { + private List value = new ArrayList<>(); + public List getValue() { + return new ArrayList<>(value); + } + public Member getMember(int mno) { + return this.value.get(mno); + } + public void addRoomMember(String rid, String id) { + this.value.add(new Member(id, accounts)); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/OnlineBattleGame2.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/OnlineBattleGame2.java new file mode 100644 index 0000000..9e20fae --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/OnlineBattleGame2.java @@ -0,0 +1,58 @@ +import java.util.*; + +public class OnlineBattleGame2 { + private Accounts accounts; + private Rooms rooms; + public OnlineBattleGame2() { + accounts = new Accounts(); + rooms = new Rooms(accounts); + } + public Map getAccount(String mid) { + return this.accounts.getAccount(mid).getValue(); + } + public List getMembers(String rid) { + return this.rooms.getRoom(rid).getMembers().getValue(); + } + public void addRoomMember(String rid, String id) { + this.rooms.getRoom(rid).getMembers().addRoomMember(rid, id); + } + public boolean getBattle(String rid) { + return this.rooms.getRoom(rid).getBattle(); + } + public void battle(String rid, boolean hasWon) { + this.rooms.getRoom(rid).battle(rid, hasWon); + } + public Map getRoom(String rid) { + return this.rooms.getRoom(rid).getValue(); + } + public String getName(String mid) { + return this.accounts.getAccount(mid).getName(); + } + public void changeName(String aid, String name) { + this.accounts.getAccount(aid).changeName(aid, name); + } + public String getId(String rid, int mno) { + return this.rooms.getRoom(rid).getMembers().getMember(mno).getId(); + } + public String getName(String rid, int mno) { + return this.rooms.getRoom(rid).getMembers().getMember(mno).getName(); + } + public Map getMember(String rid, int mno) { + return this.rooms.getRoom(rid).getMembers().getMember(mno).getValue(); + } + public int getPoint(String mid) { + return this.accounts.getAccount(mid).getPoint(); + } + public Map getAccounts() { + return this.accounts.getValue(); + } + public void signUp(String name, String aid) { + this.accounts.signUp(name, aid); + } + public Map getRooms() { + return this.rooms.getValue(); + } + public void createRoom(String rid) { + this.rooms.createRoom(rid); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Room.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Room.java new file mode 100644 index 0000000..b15a881 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Room.java @@ -0,0 +1,29 @@ +import java.util.*; + +public class Room { + private Members members = new Members(); + private boolean battle; + private Account account; + private Accounts accounts; + public Map getValue() { + Map temp_nil11 = new HashMap<>(); + temp_nil11.put("members",this.members.getValue()); + temp_nil11.put("battle",this.getBattle()); + return temp_nil11; + } + public Members getMembers() { + return this.members; + } + public boolean getBattle() { + return this.battle; + } + public void battle(String rid, boolean hasWon) { + this.battle = hasWon; + String id = this.rooms.getRoom(rid).getMembers().getMember(mno).getId(); + this.account.updatePointFromBattle(mid, rid, mno, battle, id); + } + public Room(boolean battle, Accounts accounts) { + this.battle = battle; + this.accounts = accounts; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Rooms.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Rooms.java new file mode 100644 index 0000000..d4230fa --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PULL-first/Rooms.java @@ -0,0 +1,18 @@ +import java.util.*; + +public class Rooms { + private Map value = new HashMap<>(); + private Accounts accounts; + public Map getValue() { + return new HashMap<>(value); + } + public Room getRoom(String rid) { + return this.value.get(rid); + } + public void createRoom(String rid) { + this.value.put(rid,new Room(false, accounts)); + } + public Rooms(Accounts accounts) { + this.accounts = accounts; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Account.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Account.java new file mode 100644 index 0000000..a0961b4 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Account.java @@ -0,0 +1,34 @@ +import java.util.*; + +public class Account { + private String name; + private int point; + public Map getValue() { + Map temp_nil15 = new HashMap<>(); + temp_nil15.put("name",this.getName()); + temp_nil15.put("point",this.getPoint()); + return temp_nil15; + } + public String getName() { + return this.name; + } + public int getPoint() { + return point; + } + public void updatePointFromBattle(String self, String rid, int mno, boolean battle, String id) { + int temp_if2; + if (hasWon) { + temp_if2 = (this.point+1); + } else { + temp_if2 = this.point; + } + this.point = temp_if2; + } + public void changeName(String aid, String name) { + this.name = name; + } + public Account(String name, int point) { + this.name = name; + this.point = point; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Accounts.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Accounts.java new file mode 100644 index 0000000..6d92c89 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Accounts.java @@ -0,0 +1,14 @@ +import java.util.*; + +public class Accounts { + private Map value = new HashMap<>(); + public Map getValue() { + return new HashMap<>(value); + } + public Account getAccount(String mid) { + return this.value.get(mid); + } + public void signUp(String name, String aid) { + this.value.put(aid,new Account(name, 0)); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Member.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Member.java new file mode 100644 index 0000000..9f84c84 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Member.java @@ -0,0 +1,23 @@ +import java.util.*; + +public class Member { + private String id; + private Account account; + private Accounts accounts; + public Map getValue() { + Map temp_nil16 = new HashMap<>(); + temp_nil16.put("id",this.getId()); + temp_nil16.put("name",this.getName()); + return temp_nil16; + } + public String getId() { + return this.id; + } + public String getName() { + return name; + } + public Member(String id, Accounts accounts) { + this.id = id; + this.accounts = accounts; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Members.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Members.java new file mode 100644 index 0000000..091b561 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Members.java @@ -0,0 +1,14 @@ +import java.util.*; + +public class Members { + private List value = new ArrayList<>(); + public List getValue() { + return new ArrayList<>(value); + } + public Member getMember(int mno) { + return this.value.get(mno); + } + public void addRoomMember(String rid, String id) { + this.value.add(new Member(id, accounts)); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/OnlineBattleGame2.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/OnlineBattleGame2.java new file mode 100644 index 0000000..1a826f3 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/OnlineBattleGame2.java @@ -0,0 +1,58 @@ +import java.util.*; + +public class OnlineBattleGame2 { + private Accounts accounts; + private Rooms rooms; + public OnlineBattleGame2() { + accounts = new Accounts(); + rooms = new Rooms(accounts); + } + public Map getAccount(String mid) { + return this.accounts.getAccount(mid).getValue(); + } + public List getMembers(String rid) { + return this.rooms.getRoom(rid).getMembers().getValue(); + } + public void addRoomMember(String rid, String id) { + this.rooms.getRoom(rid).getMembers().addRoomMember(rid, id); + } + public boolean getBattle(String rid) { + return this.rooms.getRoom(rid).getBattle(); + } + public void battle(String rid, boolean hasWon) { + this.rooms.getRoom(rid).battle(rid, hasWon); + } + public Map getRoom(String rid) { + return this.rooms.getRoom(rid).getValue(); + } + public String getId(String rid, int mno) { + return this.rooms.getRoom(rid).getMembers().getMember(mno).getId(); + } + public String getName(String rid, int mno) { + return this.rooms.getRoom(rid).getMembers().getMember(mno).getName(); + } + public String getName(String mid) { + return this.accounts.getAccount(mid).getName(); + } + public void changeName(String aid, String name) { + this.accounts.getAccount(aid).changeName(aid, name); + } + public Map getMember(String rid, int mno) { + return this.rooms.getRoom(rid).getMembers().getMember(mno).getValue(); + } + public int getPoint(String mid) { + return this.accounts.getAccount(mid).getPoint(); + } + public Map getAccounts() { + return this.accounts.getValue(); + } + public void signUp(String name, String aid) { + this.accounts.signUp(name, aid); + } + public Map getRooms() { + return this.rooms.getValue(); + } + public void createRoom(String rid) { + this.rooms.createRoom(rid); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Room.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Room.java new file mode 100644 index 0000000..5ad660f --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Room.java @@ -0,0 +1,29 @@ +import java.util.*; + +public class Room { + private Members members = new Members(); + private boolean battle; + private Account account; + private Accounts accounts; + public Map getValue() { + Map temp_nil14 = new HashMap<>(); + temp_nil14.put("members",this.members.getValue()); + temp_nil14.put("battle",this.getBattle()); + return temp_nil14; + } + public Members getMembers() { + return this.members; + } + public boolean getBattle() { + return this.battle; + } + public void battle(String rid, boolean hasWon) { + this.battle = hasWon; + String id = this.rooms.getRoom(rid).getMembers().getMember(mno).getId(); + this.account.updatePointFromBattle(mid, rid, mno, battle, id); + } + public Room(boolean battle, Accounts accounts) { + this.battle = battle; + this.accounts = accounts; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Rooms.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Rooms.java new file mode 100644 index 0000000..d4230fa --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/prototypes/Java/OnlineBattleGame2/PUSH-first/Rooms.java @@ -0,0 +1,18 @@ +import java.util.*; + +public class Rooms { + private Map value = new HashMap<>(); + private Accounts accounts; + public Map getValue() { + return new HashMap<>(value); + } + public Room getRoom(String rid) { + return this.value.get(rid); + } + public void createRoom(String rid) { + this.value.put(rid,new Room(false, accounts)); + } + public Rooms(Accounts accounts) { + this.accounts = accounts; + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/tests/JAXRSCodeGeneratorTest.java b/AlgebraicDataflowArchitectureModel/src/tests/JAXRSCodeGeneratorTest.java index 50764fa..e958d72 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/JAXRSCodeGeneratorTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/JAXRSCodeGeneratorTest.java @@ -58,6 +58,7 @@ testGroupChat(); testInventoryManagement(); testOnlineBattleGame(); + testOnlineBattleGame2(); testPOS(); testSimpleTwitter(); testWeatherObservationSystem(); @@ -736,6 +737,196 @@ } } + + private void testOnlineBattleGame2() { + try { + // check PULL-first + ArrayList generatedCode = generateCode("models/OnlineBattleGame2.model", null); + Map, // class annotations + Entry, // field name to type + Map, // class annotations + Entry, // arg types + Integer>>>>>>> // lines of code + exprectedStructure = new HashMap<>(); + exprectedStructure.put("Rooms", Map.entry(Set.of("@Path(\"/rooms\")","@Component"), + Map.entry(Map.ofEntries(Map.entry("value", "Map")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of("@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getRoom", Map.entry(Set.of(), + Map.entry("Room", + Map.entry(List.of("String"), + 1)))), + Map.entry("getIdValue", Map.entry(Set.of("@Path(\"/{rid}/members/{mno}/id\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("String", + Map.entry(List.of("String","int"), + 1)))), + Map.entry("getBattleValue", Map.entry(Set.of("@Path(\"/{rid}/battle\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("boolean", + Map.entry(List.of("String"), + 1)))), + Map.entry("getRoomValue", Map.entry(Set.of("@Path(\"/{rid}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of("String"), + 1)))), + Map.entry("getMemberValue", Map.entry(Set.of("@Path(\"/{rid}/members/{mno}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of("String","int"), + 1)))), + Map.entry("getMembersValue", Map.entry(Set.of("@Path(\"/{rid}/members\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("List", + Map.entry(List.of("String"), + 1)))), + Map.entry("getNameValue", Map.entry(Set.of("@Path(\"/{rid}/members/{mno}/name\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("String", + Map.entry(List.of("String","int"), + 1)))), + Map.entry("battle", Map.entry(Set.of("@Path(\"/{rid}/battle\")","@PUT"), + Map.entry("void", + Map.entry(List.of("String","boolean"), + 1)))), + Map.entry("addRoomMember", Map.entry(Set.of("@Path(\"/{rid}/members\")","@POST"), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))), + Map.entry("createRoom", Map.entry(Set.of("@POST"), + Map.entry("void", + Map.entry(List.of("String"), + 1)))))))); + exprectedStructure.put("Member", Map.entry(Set.of(), + Map.entry(Map.ofEntries(Map.entry("id", "String"), + Map.entry("client", "Client")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getId", Map.entry(Set.of(), + Map.entry("String", + Map.entry(List.of(), + 1)))), + Map.entry("getName", Map.entry(Set.of(), + Map.entry("String", + Map.entry(List.of(), + 2)))), + Map.entry("Member", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String"), + 1)))))))); + exprectedStructure.put("Account", Map.entry(Set.of(), + Map.entry(Map.ofEntries(Map.entry("name", "String"), + Map.entry("point", "int")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getName", Map.entry(Set.of(), + Map.entry("String", + Map.entry(List.of(), + 1)))), + Map.entry("getPoint", Map.entry(Set.of(), + Map.entry("int", + Map.entry(List.of(), + 1)))), + Map.entry("updatePointFromBattle", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","String","int","boolean","String"), + 1)))), + Map.entry("changeName", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))), + Map.entry("Account", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","int"), + 2)))))))); + exprectedStructure.put("Room", Map.entry(Set.of(), + Map.entry(Map.ofEntries(Map.entry("members", "Members"), + Map.entry("battle", "boolean"), + Map.entry("client", "Client")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getMembers", Map.entry(Set.of(), + Map.entry("Members", + Map.entry(List.of(), + 1)))), + Map.entry("getBattle", Map.entry(Set.of(), + Map.entry("boolean", + Map.entry(List.of(), + 1)))), + Map.entry("battle", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","boolean"), + 6)))), + Map.entry("Room", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("boolean"), + 1)))))))); + exprectedStructure.put("Accounts", Map.entry(Set.of("@Path(\"/accounts\")","@Component"), + Map.entry(Map.ofEntries(Map.entry("value", "Map")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of("@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of(), + 1)))), + Map.entry("getAccount", Map.entry(Set.of(), + Map.entry("Account", + Map.entry(List.of("String"), + 1)))), + Map.entry("updatePointFromBattle", Map.entry(Set.of("@Path(\"accounts/{mid}/point\")","@POST"), + Map.entry("void", + Map.entry(List.of("String","String","int","boolean","String"), + 1)))), + Map.entry("getAccountValue", Map.entry(Set.of("@Path(\"/{mid}\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("Map", + Map.entry(List.of("String"), + 1)))), + Map.entry("getNameValue", Map.entry(Set.of("@Path(\"/{mid}/name\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("String", + Map.entry(List.of("String"), + 1)))), + Map.entry("getPointValue", Map.entry(Set.of("@Path(\"/{mid}/point\")","@Produces(MediaType.APPLICATION_JSON)","@GET"), + Map.entry("int", + Map.entry(List.of("String"), + 1)))), + Map.entry("signUp", Map.entry(Set.of("@POST"), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))), + Map.entry("changeName", Map.entry(Set.of("@Path(\"/{aid}/name\")","@PUT"), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))))))); + exprectedStructure.put("Members", Map.entry(Set.of(), + Map.entry(Map.ofEntries(Map.entry("value", "List")), + Map.ofEntries(Map.entry("getValue", Map.entry(Set.of(), + Map.entry("List", + Map.entry(List.of(), + 1)))), + Map.entry("getMember", Map.entry(Set.of(), + Map.entry("Member", + Map.entry(List.of("int"), + 1)))), + Map.entry("addRoomMember", Map.entry(Set.of(), + Map.entry("void", + Map.entry(List.of("String","String"), + 1)))))))); + + checkStructure(generatedCode, exprectedStructure); +// generateCheckCode(generatedCode); + } catch (FileNotFoundException + | ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword + | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression + | WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket + | WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) { + e.printStackTrace(); + } + } + private void testPOS() { try { // check PULL-first diff --git a/AlgebraicDataflowArchitectureModel/src/tests/JavaCodeGeneratorTest.java b/AlgebraicDataflowArchitectureModel/src/tests/JavaCodeGeneratorTest.java index 5456ae6..dc82f8f 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/JavaCodeGeneratorTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/JavaCodeGeneratorTest.java @@ -55,6 +55,7 @@ testGroupChat(); testInventoryManagement(); // testOnlineBattleGame(); // A feature has not been implemented for Java prototype generation. + testOnlineBattleGame2(); // Two methods with the same signature are generated. testPOS(); testSimpleTwitter(); testWeatherObservationSystem(); @@ -1038,6 +1039,322 @@ } } + + private void testOnlineBattleGame2() { + try { + // check PULL-first + ArrayList generatedCode = generateCode("models/OnlineBattleGame2.model", PushPullValue.PULL); + Map, // field name to type + Map, // arg types + Integer>>>>> // lines of code + exprectedStructure = new HashMap<>(); + exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("accounts", "Accounts"), + Map.entry("rooms", "Rooms")), + Map.ofEntries(Map.entry("Main", Map.entry("void", + Map.entry(List.of(), + 2))), + Map.entry("getPoint", Map.entry("int", + Map.entry(List.of("String"), + 1))), + Map.entry("getName", Map.entry("String", + Map.entry(List.of("String"), + 1))), + Map.entry("changeName", Map.entry("void", + Map.entry(List.of("String","String"), + 1))), + Map.entry("getAccounts", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("signUp", Map.entry("void", + Map.entry(List.of("String","String"), + 1))), + Map.entry("getRooms", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("createRoom", Map.entry("void", + Map.entry(List.of("String"), + 1))), + Map.entry("getAccount", Map.entry("Map", + Map.entry(List.of("String"), + 1))), + Map.entry("getBattle", Map.entry("boolean", + Map.entry(List.of("String"), + 1))), + Map.entry("battle", Map.entry("void", + Map.entry(List.of("String","boolean"), + 1))), + Map.entry("getId", Map.entry("String", + Map.entry(List.of("String","int"), + 1))), + Map.entry("getMembers", Map.entry("List", + Map.entry(List.of("String"), + 1))), + Map.entry("addRoomMember", Map.entry("void", + Map.entry(List.of("String","String"), + 1))), +// Map.entry("getName", Map.entry("String", +// Map.entry(List.of("String","int"), +// 1))), + Map.entry("getRoom", Map.entry("Map", + Map.entry(List.of("String"), + 1))), + Map.entry("getMember", Map.entry("Map", + Map.entry(List.of("String","int"), + 1)))))); + exprectedStructure.put("Accounts", Map.entry(Map.ofEntries(), + Map.ofEntries(Map.entry("getValue", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("getAccount", Map.entry("Account", + Map.entry(List.of("String"), + 1))), + Map.entry("signUp", Map.entry("void", + Map.entry(List.of("String","String"), + 1)))))); + exprectedStructure.put("Rooms", Map.entry(Map.ofEntries(Map.entry("value", "Map"), + Map.entry("accounts", "Accounts")), + Map.ofEntries(Map.entry("getValue", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("getRoom", Map.entry("Room", + Map.entry(List.of("String"), + 1))), + Map.entry("createRoom", Map.entry("void", + Map.entry(List.of("String"), + 1))), + Map.entry("Rooms", Map.entry("void", + Map.entry(List.of("Accounts"), + 1)))))); + exprectedStructure.put("Account", Map.entry(Map.ofEntries(Map.entry("point", "int"), + Map.entry("name", "String")), + Map.ofEntries(Map.entry("getValue", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("getPoint", Map.entry("int", + Map.entry(List.of(), + 1))), + Map.entry("getName", Map.entry("String", + Map.entry(List.of(), + 1))), + Map.entry("updatePointFromBattle", Map.entry("void", + Map.entry(List.of("String","String","int","boolean","String"), + 1))), + Map.entry("changeName", Map.entry("void", + Map.entry(List.of("String","String"), + 1))), + Map.entry("Account", Map.entry("void", + Map.entry(List.of("int","String"), + 2)))))); + exprectedStructure.put("Members", Map.entry(Map.ofEntries(), + Map.ofEntries(Map.entry("getValue", Map.entry("List", + Map.entry(List.of(), + 1))), + Map.entry("getMember", Map.entry("Member", + Map.entry(List.of("int"), + 1))), + Map.entry("addRoomMember", Map.entry("void", + Map.entry(List.of("String","String"), + 1)))))); + exprectedStructure.put("Room", Map.entry(Map.ofEntries(Map.entry("members", "Members"), + Map.entry("battle", "boolean"), + Map.entry("account", "Account"), + Map.entry("accounts", "Accounts")), + Map.ofEntries(Map.entry("getValue", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("getMembers", Map.entry("Members", + Map.entry(List.of(), + 1))), + Map.entry("getBattle", Map.entry("boolean", + Map.entry(List.of(), + 1))), + Map.entry("battle", Map.entry("void", + Map.entry(List.of("String","boolean"), + 3))), + Map.entry("Room", Map.entry("void", + Map.entry(List.of("boolean","Accounts"), + 2)))))); + exprectedStructure.put("Member", Map.entry(Map.ofEntries(Map.entry("id", "String"), + Map.entry("account", "Account"), + Map.entry("accounts", "Accounts")), + Map.ofEntries(Map.entry("getValue", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("getId", Map.entry("String", + Map.entry(List.of(), + 1))), + Map.entry("getName", Map.entry("String", + Map.entry(List.of(), + 1))), + Map.entry("Member", Map.entry("void", + Map.entry(List.of("String","Accounts"), + 2)))))); + + checkStructure(generatedCode, exprectedStructure); +// generateCheckCode(generatedCode); + + // check PUSH-first + generatedCode = generateCode("models/OnlineBattleGame2.model", PushPullValue.PUSH); + exprectedStructure.clear(); + exprectedStructure.put("Main", Map.entry(Map.ofEntries(Map.entry("accounts", "Accounts"), + Map.entry("rooms", "Rooms")), + Map.ofEntries(Map.entry("Main", Map.entry("void", + Map.entry(List.of(), + 2))), + Map.entry("getRoom", Map.entry("Map", + Map.entry(List.of("String"), + 1))), + Map.entry("getAccounts", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("signUp", Map.entry("void", + Map.entry(List.of("String","String"), + 1))), + Map.entry("getAccount", Map.entry("Map", + Map.entry(List.of("String"), + 1))), + Map.entry("getRooms", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("createRoom", Map.entry("void", + Map.entry(List.of("String"), + 1))), + Map.entry("getPoint", Map.entry("int", + Map.entry(List.of("String"), + 1))), + Map.entry("getBattle", Map.entry("boolean", + Map.entry(List.of("String"), + 1))), + Map.entry("battle", Map.entry("void", + Map.entry(List.of("String","boolean"), + 1))), +// Map.entry("getName", Map.entry("String", +// Map.entry(List.of("String","int"), +// 1))), + Map.entry("getName", Map.entry("String", + Map.entry(List.of("String"), + 1))), + Map.entry("changeName", Map.entry("void", + Map.entry(List.of("String","String"), + 1))), + Map.entry("getId", Map.entry("String", + Map.entry(List.of("String","int"), + 1))), + Map.entry("getMember", Map.entry("Map", + Map.entry(List.of("String","int"), + 1))), + Map.entry("getMembers", Map.entry("List", + Map.entry(List.of("String"), + 1))), + Map.entry("addRoomMember", Map.entry("void", + Map.entry(List.of("String","String"), + 1)))))); + exprectedStructure.put("Room", Map.entry(Map.ofEntries(Map.entry("members", "Members"), + Map.entry("battle", "boolean"), + Map.entry("account", "Account"), + Map.entry("accounts", "Accounts")), + Map.ofEntries(Map.entry("getValue", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("getMembers", Map.entry("Members", + Map.entry(List.of(), + 1))), + Map.entry("getBattle", Map.entry("boolean", + Map.entry(List.of(), + 1))), + Map.entry("battle", Map.entry("void", + Map.entry(List.of("String","boolean"), + 3))), + Map.entry("Room", Map.entry("void", + Map.entry(List.of("boolean","Accounts"), + 2)))))); + exprectedStructure.put("Accounts", Map.entry(Map.ofEntries(), + Map.ofEntries(Map.entry("getValue", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("getAccount", Map.entry("Account", + Map.entry(List.of("String"), + 1))), + Map.entry("signUp", Map.entry("void", + Map.entry(List.of("String","String"), + 1)))))); + exprectedStructure.put("Account", Map.entry(Map.ofEntries(Map.entry("point", "int"), + Map.entry("name", "String")), + Map.ofEntries(Map.entry("getValue", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("getPoint", Map.entry("int", + Map.entry(List.of(), + 1))), + Map.entry("getName", Map.entry("String", + Map.entry(List.of(), + 1))), + Map.entry("updatePointFromBattle", Map.entry("void", + Map.entry(List.of("String","String","int","boolean","String"), + 1))), + Map.entry("changeName", Map.entry("void", + Map.entry(List.of("String","String"), + 1))), + Map.entry("Account", Map.entry("void", + Map.entry(List.of("int","String"), + 2)))))); + exprectedStructure.put("Rooms", Map.entry(Map.ofEntries(Map.entry("value", "Map"), + Map.entry("accounts", "Accounts")), + Map.ofEntries(Map.entry("getValue", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("getRoom", Map.entry("Room", + Map.entry(List.of("String"), + 1))), + Map.entry("createRoom", Map.entry("void", + Map.entry(List.of("String"), + 1))), + Map.entry("Rooms", Map.entry("void", + Map.entry(List.of("Accounts"), + 1)))))); + exprectedStructure.put("Member", Map.entry(Map.ofEntries(Map.entry("account", "Account"), + Map.entry("accounts", "Accounts"), + Map.entry("id", "String")), + Map.ofEntries(Map.entry("getValue", Map.entry("Map", + Map.entry(List.of(), + 1))), + Map.entry("getName", Map.entry("String", + Map.entry(List.of(), + 1))), + Map.entry("getId", Map.entry("String", + Map.entry(List.of(), + 1))), + Map.entry("updateNameFromId", Map.entry("void", + Map.entry(List.of("String","int","String","int","String"), + 2))), + Map.entry("Member", Map.entry("void", + Map.entry(List.of("Accounts","String"), + 2)))))); + exprectedStructure.put("Members", Map.entry(Map.ofEntries(), + Map.ofEntries(Map.entry("getValue", Map.entry("List", + Map.entry(List.of(), + 1))), + Map.entry("getMember", Map.entry("Member", + Map.entry(List.of("int"), + 1))), + Map.entry("addRoomMember", Map.entry("void", + Map.entry(List.of("String","String"), + 1)))))); + + checkStructure(generatedCode, exprectedStructure); +// generateCheckCode(generatedCode); + } catch (FileNotFoundException + | ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefOrSubKeyword + | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression + | WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedRightCurlyBracket + | WrongPathExpression | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) { + e.printStackTrace(); + } + } + private void testPOS() { try { // check PULL-first