<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.vutbr.fit.pdb.containers;


import cz.vutbr.fit.pdb.db.DatabaseAPI;
import cz.vutbr.fit.pdb.model.BedsObject;
import cz.vutbr.fit.pdb.model.DataObject;
import cz.vutbr.fit.pdb.model.FencesObject;
import cz.vutbr.fit.pdb.model.PathObject;
import cz.vutbr.fit.pdb.model.SignObject;
import cz.vutbr.fit.pdb.model.SoilObject;
import cz.vutbr.fit.pdb.model.SpatialObject;
import cz.vutbr.fit.pdb.model.WaterObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import oracle.spatial.geometry.JGeometry;

/**
 * Container of spatial objects (those who have geometry). For correct function
 * it needs to be initialized together with DataContainer
 *
 * @author <NAME>
 */
public class SpatialContainer {
    private final DatabaseAPI db;

    private final Map<Integer, ArrayList<SpatialObject>> spatialObjectList;
    private SpatialObject selected;
    private SpatialObject hovered;
    private ArrayList<DataObject> layers;

    /**
     * Constructor of SpatialContainer.
     *
     * @param login Username to access database
     * @param password Password to access database
     */
    public SpatialContainer(String login, String password) {
        this.spatialObjectList = new HashMap<Integer, ArrayList<SpatialObject>>();
        this.layers = null;
        this.selected = null;
        this.hovered = null;

        this.db = new DatabaseAPI(login, password);
    }

    /**
     * Connect to DB and fill appropriate containers.
     */
    public void initialize() {
        if (this.layers != null) {
            /* Repeated initialization - need to clear the map and array */
            this.spatialObjectList.clear();
            this.layers.clear();
            this.selected = null;
            this.hovered = null;
        }

        /* Get the layers and store them */
        this.layers = this.db.getLayersAll();


        /* For every type of object get all of occurences from db and store them
         * under appropriate integer into spatialObjectList */
        ArrayList<SpatialObject> tmp = this.db.getBedsAll();
        if (!tmp.isEmpty()) {
            int layer = tmp.get(0).getLayer();
            this.spatialObjectList.put(layer, tmp);
        }

        tmp = this.db.getFencesAll();
        if (!tmp.isEmpty()) {
            int layer = tmp.get(0).getLayer();
            this.spatialObjectList.put(layer, tmp);
        }

        tmp = this.db.getPathAll();
        if (!tmp.isEmpty()) {
            int layer = tmp.get(0).getLayer();
            this.spatialObjectList.put(layer, tmp);
        }

        tmp = this.db.getSignAll();
        if (!tmp.isEmpty()) {
            int layer = tmp.get(0).getLayer();
            this.spatialObjectList.put(layer, tmp);
        }

        tmp = this.db.getSoilAll();
        if (!tmp.isEmpty()) {
            int layer = tmp.get(0).getLayer();
            this.spatialObjectList.put(layer, tmp);
        }

        tmp = this.db.getWaterAll();
        if (!tmp.isEmpty()) {
            int layer = tmp.get(0).getLayer();
            this.spatialObjectList.put(layer, tmp);
        }
    }
<commit_msg>Added constructor with databaseAPI instance and fixed loading data from db according to fact that objects can have variable layer set<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.vutbr.fit.pdb.containers;


import cz.vutbr.fit.pdb.db.DatabaseAPI;
import cz.vutbr.fit.pdb.model.BedsObject;
import cz.vutbr.fit.pdb.model.DataObject;
import cz.vutbr.fit.pdb.model.FencesObject;
import cz.vutbr.fit.pdb.model.PathObject;
import cz.vutbr.fit.pdb.model.SignObject;
import cz.vutbr.fit.pdb.model.SoilObject;
import cz.vutbr.fit.pdb.model.SpatialObject;
import cz.vutbr.fit.pdb.model.WaterObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import oracle.spatial.geometry.JGeometry;

/**
 * Container of spatial objects (those who have geometry). For correct function
 * it needs to be initialized together with DataContainer
 *
 * @author <NAME>
 */
public class SpatialContainer {
    private final DatabaseAPI db;

    private final Map<Integer, ArrayList<SpatialObject>> spatialObjectList;
    private SpatialObject selected;
    private SpatialObject hovered;
    private ArrayList<DataObject> layers;

    /**
     * Constructor of SpatialContainer.
     *
     * @param login Username to access database
     * @param password Password to access database
     */
    public SpatialContainer(String login, String password) {
        this.spatialObjectList = new HashMap<Integer, ArrayList<SpatialObject>>();
        this.layers = null;
        this.selected = null;
        this.hovered = null;

        this.db = new DatabaseAPI(login, password);
    }

    /**
     * Constructor of SpatialContainer.
     *
     * @param _db DatabaseAPI object instance
     */
    public SpatialContainer(DatabaseAPI _db) {
        this.spatialObjectList = new HashMap<Integer, ArrayList<SpatialObject>>();
        this.layers = null;
        this.selected = null;
        this.hovered = null;

        this.db = _db;
    }

    /**
     * Connect to DB and fill appropriate containers.
     */
    public void initialize() {
        if (this.layers != null) {
            /* Repeated initialization - need to clear the map and array */
            this.spatialObjectList.clear();
            this.layers.clear();
            this.selected = null;
            this.hovered = null;
        }

        /* Get the layers and store them */
        this.layers = this.db.getLayersAll();


        /* For every type of object get all of occurences from db and store them
         * under appropriate integer into spatialObjectList */
        ArrayList<SpatialObject> tmp = this.db.getBedsAll();
        for (SpatialObject o : tmp) {
            this.spatialObjectList.get(o.getLayer()).add(o);
        }

        tmp = this.db.getFencesAll();
        for (SpatialObject o : tmp) {
            this.spatialObjectList.get(o.getLayer()).add(o);
        }

        tmp = this.db.getPathAll();
        for (SpatialObject o : tmp) {
            this.spatialObjectList.get(o.getLayer()).add(o);
        }

        tmp = this.db.getSignAll();
        for (SpatialObject o : tmp) {
            this.spatialObjectList.get(o.getLayer()).add(o);
        }

        tmp = this.db.getSoilAll();
        for (SpatialObject o : tmp) {
            this.spatialObjectList.get(o.getLayer()).add(o);
        }

        tmp = this.db.getWaterAll();
        for (SpatialObject o : tmp) {
            this.spatialObjectList.get(o.getLayer()).add(o);
        }
    }

{'fraction_non_alphanumeric': 0.11194801358735786, 'fraction_numerical': 0.0008861320336730173, 'mean_word_length': 2.4064386317907447, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5212712', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1993, 'n_words': 489}