<commit_before>package models;

import helpers.Json;
import helpers.JsonObject;

import java.util.HashSet;

public class Cell implements Serializable<Cell> {
    private Space space; 
    private int elevation; 
    private Player developerPlayer;
    private Developer developer;
    private int x; 
    private int y; 
    private HashSet<Cell> connectedCells;
    private boolean fromLowlands;
    private boolean fromMountains;

    public Cell(int x, int y, boolean fromLowlands, boolean fromMountains) {
    	this.x = x;
    	this.y = y;
    	this.fromLowlands = fromLowlands;
    	this.fromMountains = fromMountains;
      developer = null;
    }
    
    public Cell(Space space) {
        this.space = space;
    }
    
    public void setDeveloper(Developer developer){
    	this.developer = developer;
    }
    
    public void removeDeveloper(Developer developer){
    	developer = null;
    }
    
    public Developer getDeveloper(){
    	
    	return developer;
    }
    
    public Space getSpace() {
        return space;
    }
    
    public void setSpace(Space space) {
        this.space = space;
    }
    
    public int getElevation() {
        return elevation; 
    }

    public boolean setElevation(int elevation) {
        if(elevation < 0) 
            return false; 
        this.elevation = elevation;
        return true;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public HashSet<Cell> getConnectedCells() {
        return connectedCells;
    }

    public void setConnectedCells(HashSet<Cell> connectedCells) {
        this.connectedCells = connectedCells;
    }
    
    public boolean getFromMountains() {
    	return fromMountains;
    }
     
    public boolean getFromLowlands() {
    	return fromLowlands;
    }
    
    
    
    public boolean hasDeveloper()
    {
         return developer != null;
    }

    public String serialize() {
		return Json.jsonObject(Json.jsonMembers(
				Json.jsonPair("space", (space == null ? null : space.serialize())),
				//Json.jsonPair("developerPlayer", developerPlayer.serialize()),
				Json.jsonPair("elevation", Json.jsonValue(elevation + "")),
				Json.jsonPair("x", Json.jsonValue(x + "")),
				Json.jsonPair("y", Json.jsonValue(y + "")),
    			Json.jsonPair("connectedCells", (connectedCells == null ? null : Json.serializeArray(connectedCells.toArray()))),
    			Json.jsonPair("fromLowLands", Json.jsonValue(fromLowlands + "")),
    			Json.jsonPair("fromMountains", Json.jsonValue(fromMountains + ""))
		));
    }<commit_msg>Serialize saves connected cells<commit_after>package models;

import helpers.Json;
import helpers.JsonObject;

import java.util.HashSet;
import java.util.LinkedList;

public class Cell implements Serializable<Cell> {
    private Space space; 
    private int elevation; 
    private Player developerPlayer;
    private Developer developer;
    private int x; 
    private int y; 
    private HashSet<Cell> connectedCells;
    private boolean fromLowlands;
    private boolean fromMountains;

    public Cell(int x, int y, boolean fromLowlands, boolean fromMountains) {
    	this.x = x;
    	this.y = y;
    	this.fromLowlands = fromLowlands;
    	this.fromMountains = fromMountains;
      developer = null;
    }
    
    public Cell(Space space) {
        this.space = space;
    }
    
    public void setDeveloper(Developer developer){
    	this.developer = developer;
    }
    
    public void removeDeveloper(Developer developer){
    	developer = null;
    }
    
    public Developer getDeveloper(){
    	
    	return developer;
    }
    
    public Space getSpace() {
        return space;
    }
    
    public void setSpace(Space space) {
        this.space = space;
    }
    
    public int getElevation() {
        return elevation; 
    }

    public boolean setElevation(int elevation) {
        if(elevation < 0) 
            return false; 
        this.elevation = elevation;
        return true;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public HashSet<Cell> getConnectedCells() {
        return connectedCells;
    }

    public void setConnectedCells(HashSet<Cell> connectedCells) {
        this.connectedCells = connectedCells;
    }
    
    public boolean getFromMountains() {
    	return fromMountains;
    }
     
    public boolean getFromLowlands() {
    	return fromLowlands;
    }
    
    
    
    public boolean hasDeveloper()
    {
         return developer != null;
    }

    public String serialize() {
    	LinkedList<String> connections = new LinkedList<String>(); 
    	if(connectedCells != null)
    		for(Cell cell : connectedCells)
    			connections.add(Json.jsonObject(Json.jsonMembers(Json.jsonPair("x", cell.x + ""), Json.jsonPair("y", cell.y + ""))));
		return Json.jsonObject(Json.jsonMembers(
				Json.jsonPair("space", (space == null ? null : space.serialize())),
				//Json.jsonPair("developerPlayer", developerPlayer.serialize()),
				Json.jsonPair("elevation", Json.jsonValue(elevation + "")),
				Json.jsonPair("x", Json.jsonValue(x + "")),
				Json.jsonPair("y", Json.jsonValue(y + "")),
    			//Json.jsonPair("connectedCells", (connectedCells == null ? null : Json.serializeArray(connectedCells.toArray()))),
				Json.jsonPair("connectedCells", connections.size() > 0 ? null : Json.jsonArray(Json.jsonElements(connections.toArray(new String[1])))),
    			Json.jsonPair("fromLowLands", Json.jsonValue(fromLowlands + "")),
    			Json.jsonPair("fromMountains", Json.jsonValue(fromMountains + ""))
		));
    }
{'fraction_non_alphanumeric': 0.10829769033361848, 'fraction_numerical': 0.0006843455945252353, 'mean_word_length': 2.5366001209921354, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3997245', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1704, 'n_words': 394}