View RockPaperScissorsLizardSpock.java
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class RockPaperScissorsLizardSpock {
public enum Item {
ROCK, PAPER, SCISSORS, LIZARD, SPOCK;
View NextMove.java
private Item nextMove(Item prev) {
if (nbThrows < 1) {
// first move => we can't use Markov Chain prediction
// so we use a random on the Item list
return Item.values()[RANDOM.nextInt(Item.values().length)];
}
// we try to predict next Item choosen by the user by reading data in our Markov Chain
// for the prev entry in the array
int nextIndex = 0;
View Item.java
public enum Item {
ROCK, PAPER, SCISSORS, LIZARD, SPOCK;
public List<Item> losesTo;
public boolean losesTo(Item other) {
return losesTo.contains(other);
}
static {
View MainActivity.java
package com.ssaurel.fastjson;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import com.alibaba.fastjson.JSON;
public class MainActivity extends AppCompatActivity {
View Decode.java
public Groups decode(String json) {
// Decode JSON in String format and bind it in Groups Java POJO Hierarchy
return JSON.parseObject(json, Groups.class);
}
View Encode.java
public String encode(Groups groups) {
// Encode POJO hierarchy to JSON quickly with Fastjson
return JSON.toJSONString(groups);
}
View CreateData.java
public Groups createData() {
Groups groups = new Groups();
Group group1 = new Group();
groups.addGroup(group1);
Group group2 = new Group();
groups.addGroup(group2);
group1.setId(0L);
group1.setName("Admin");
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/resultTv"
View Groups.java
package com.ssaurel.fastjson;
import java.util.ArrayList;
import java.util.List;
public class Groups {
private List<Group> groups = new ArrayList<>();
public List<Group> getGroups() {
View Group.java
package com.ssaurel.fastjson;
import java.util.ArrayList;
import java.util.List;
public class Group {
private Long id;
private String name;
private List<User> users = new ArrayList<>();