All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.deechael.khl.message.cardmessage.struct.Paragraph Maven / Gradle / Ivy

There is a newer version: 1.09.0
Show newest version
package net.deechael.khl.message.cardmessage.struct;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.deechael.khl.message.cardmessage.Serializable;
import net.deechael.khl.message.cardmessage.Structable;
import net.deechael.khl.message.cardmessage.Textable;

import java.util.ArrayList;
import java.util.List;

public class Paragraph extends Struct implements Textable {

    private final List fields = new ArrayList<>();
    private int cols = 0;

    public Paragraph() {
        super("paragraph");
    }

    public void addCol(Structable fields) {
        this.fields.add(fields);
        cols++;
    }

    public int getCols() {
        return cols;
    }

    @Override
    public JsonObject asJson() {
        JsonObject json = super.asJson();
        json.addProperty("cols", cols);
        JsonArray array = new JsonArray();
        for (JsonObject object : fields.stream().map(Serializable::asJson).map(JsonElement::getAsJsonObject).toList()) {
            array.add(object);
        }
        json.add("fields", array);
        return json;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy