<commit_before>/*
 Copyright 2015 <NAME> (<EMAIL>)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package com.sothawo.trakxmap.db;

import com.sothawo.mapjfx.CoordinateLine;
import com.sothawo.mapjfx.Extent;
import com.sothawo.trakxmap.util.I18N;
import com.sothawo.trakxmap.util.PathTools;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.paint.Color;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * A track that can be displayed on the map with additional data.
 *
 * @author <NAME> (<EMAIL>).
 */
@Entity
@Table(name = "TRACK")
public class Track {
// ------------------------------ FIELDS ------------------------------

    /** db id of the track */
    private Long id;
    /** the filename where the track was loaded from (without path) */
    private String filename;

    /** the name of the track */
    private final SimpleStringProperty name = new SimpleStringProperty(I18N.get(I18N.TRACK_NAME_DEFAULT));
    /** the waypoints of the track */
    private List<WayPoint> wayPoints = new ArrayList<>();
    /** the routepoints of the track */
    private List<RoutePoint> routePoints = new ArrayList<>();
    /** the trackpoints of the track */
    private List<TrackPoint> trackPoints = new ArrayList<>();

    /** the extent of the track */
    private Extent extent = null;
    /** CoordinateLine representing this track */
    private CoordinateLine coordinateLine = null;

// --------------------------- CONSTRUCTORS ---------------------------

    public Track() {
    }

    public Track(String name) {
        this.name.set(name);
    }

// --------------------- GETTER / SETTER METHODS ---------------------

    @Transient
    public CoordinateLine getCoordinateLine() {
        if (null == coordinateLine) {
            coordinateLine =
                    new CoordinateLine(trackPoints.stream().map(TrackPoint::getCoordinate).collect(Collectors.toList())
                    ).setColor(Color.RED).setWidth(5);
        }
        return coordinateLine;
    }

    /**
     * gets the extent for the contined trackpoints. If the list of trackpoints is changed after the extent is
     * calculated, the new extent must be calculated by calling recalculateExtent().
     *
     * @return the extent
     */
    @Transient
    public Optional<Extent> getExtent() {
        // extent can only be calculated when more than 2 points are available
        if (null == extent && trackPoints.size() >= 2) {
            extent = Extent.forCoordinates(
                    trackPoints.stream().map(TrackPoint::getCoordinate).collect(Collectors.toList()));
        }
        return Optional.ofNullable(extent);
    }

    @Column(name = "FILENAME", length = 255)
    public String getFilename() {
        return filename;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true)
    public Long getId() {<commit_msg>track extent takes waypoints and route points into account<commit_after>/*
 Copyright 2015 <NAME> (<EMAIL>)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package com.sothawo.trakxmap.db;

import com.sothawo.mapjfx.Coordinate;
import com.sothawo.mapjfx.CoordinateLine;
import com.sothawo.mapjfx.Extent;
import com.sothawo.trakxmap.util.I18N;
import com.sothawo.trakxmap.util.PathTools;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.paint.Color;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * A track that can be displayed on the map with additional data.
 *
 * @author <NAME> (<EMAIL>).
 */
@Entity
@Table(name = "TRACK")
public class Track {
// ------------------------------ FIELDS ------------------------------

    /** db id of the track */
    private Long id;
    /** the filename where the track was loaded from (without path) */
    private String filename;

    /** the name of the track */
    private final SimpleStringProperty name = new SimpleStringProperty(I18N.get(I18N.TRACK_NAME_DEFAULT));
    /** the waypoints of the track */
    private List<WayPoint> wayPoints = new ArrayList<>();
    /** the routepoints of the track */
    private List<RoutePoint> routePoints = new ArrayList<>();
    /** the trackpoints of the track */
    private List<TrackPoint> trackPoints = new ArrayList<>();

    /** the extent of the track */
    private Extent extent = null;
    /** CoordinateLine representing this track */
    private CoordinateLine coordinateLine = null;

// --------------------------- CONSTRUCTORS ---------------------------

    public Track() {
    }

    public Track(String name) {
        this.name.set(name);
    }

// --------------------- GETTER / SETTER METHODS ---------------------

    @Transient
    public CoordinateLine getCoordinateLine() {
        if (null == coordinateLine) {
            coordinateLine =
                    new CoordinateLine(trackPoints.stream().map(TrackPoint::getCoordinate).collect(Collectors.toList())
                    ).setColor(Color.RED).setWidth(5);
        }
        return coordinateLine;
    }

    /**
     * gets the extent for the contined trackpoints. If the list of trackpoints is changed after the extent is
     * calculated, the new extent must be calculated by calling recalculateExtent().
     *
     * @return the extent
     */
    @Transient
    public Optional<Extent> getExtent() {
        // extent can only be calculated when more than 2 points are available
        if (null == extent) {
            List<Coordinate> coordinates = trackPoints.stream().map(TrackPoint::getCoordinate).collect(Collectors
                    .toList());
            coordinates.addAll(routePoints.stream().map(RoutePoint::getCoordinate).collect(Collectors.toList()));
            coordinates.addAll(wayPoints.stream().map(WayPoint::getCoordinate).collect(Collectors.toList()));
            if (coordinates.size() >= 2) {
                extent = Extent.forCoordinates(coordinates);
            }
        }
        return Optional.ofNullable(extent);
    }

    @Column(name = "FILENAME", length = 255)
    public String getFilename() {
        return filename;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true)
    public Long getId() {
{'fraction_non_alphanumeric': 0.1387579145897885, 'fraction_numerical': 0.005388656877273339, 'mean_word_length': 2.5251661918328585, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7384517', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1953, 'n_words': 630}