Initial version.

This commit is contained in:
Oliver Hauff 2021-05-13 20:03:07 +02:00
parent 193aaa1a56
commit b72c67a53e
228 changed files with 25924 additions and 0 deletions

View file

@ -0,0 +1,19 @@
using System.Collections.Generic;
namespace TINK.Model.Station
{
public interface IStation
{
/// <summary> Holds the unique id of the station.c</summary>
int Id { get; }
/// <summary> Holds the group to which the station belongs.</summary>
IEnumerable<string> Group { get; }
/// <summary> Gets the name of the station.</summary>
string StationName { get; }
/// <summary> Holds the gps- position of the station.</summary>
Position Position { get; }
}
}

View file

@ -0,0 +1,20 @@
using System.Collections.Generic;
namespace TINK.Model.Station
{
/// <summary> Holds object representing null station.</summary>
public class NullStation : IStation
{
/// <summary> Holds the unique id of the station.c</summary>
public int Id => -1;
/// <summary> Holds the group to which the station belongs.</summary>
public IEnumerable<string> Group => new List<string>();
/// <summary> Gets the name of the station.</summary>
public string StationName => string.Empty;
/// <summary> Holds the gps- position of the station.</summary>
public Position Position => new Position(double.NaN, double.NaN);
}
}

View file

@ -0,0 +1,49 @@
using System;
namespace TINK.Model.Station
{
public class Position
{
private const double PRECISSION_LATITUDE_LONGITUDE = 0.000000000000001;
public Position()
{
}
public Position(double p_dLatitude, double p_dLongitude)
{
Latitude = p_dLatitude;
Longitude = p_dLongitude;
}
public double Latitude { get; private set; }
public double Longitude { get; private set; }
/// <summary>
/// Compares position with a target position.
/// </summary>
/// <param name="p_oTarget">Target position to compare with.</param>
/// <returns>True if positions are equal.</returns>
public override bool Equals(object p_oTarget)
{
var l_oTarget = p_oTarget as Position;
if (l_oTarget is null)
{
return false;
}
return Math.Abs(Latitude - l_oTarget.Latitude) < PRECISSION_LATITUDE_LONGITUDE
&& Math.Abs(Longitude - l_oTarget.Longitude) < PRECISSION_LATITUDE_LONGITUDE;
}
public override int GetHashCode()
{
var hashCode = -1416534245;
hashCode = hashCode * -1521134295 + Latitude.GetHashCode();
hashCode = hashCode * -1521134295 + Longitude.GetHashCode();
return hashCode;
}
}
}

View file

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
namespace TINK.Model.Station
{
/// <summary> Holds station info. </summary>
public class Station : IStation
{
/// <summary> Constructs a station object.</summary>
/// <param name="p_iId">Id of the station.</param>
/// <param name="p_oGroup">Group (TINK, Konrad) to which station is related.</param>
/// <param name="p_oPosition">GPS- position of the station.</param>
/// <param name="p_strStationName">Name of the station.</param>
public Station(
int p_iId,
IEnumerable<string> p_oGroup,
Position p_oPosition,
string p_strStationName = "")
{
Id = p_iId;
Group = p_oGroup ?? throw new ArgumentException("Can not construct station object. Group of stations must not be null.");
Position = p_oPosition;
StationName = p_strStationName ?? string.Empty;
}
/// <summary> Holds the unique id of the station.c</summary>
public int Id { get; }
/// <summary> Holds the group to which the station belongs.</summary>
public IEnumerable<string> Group { get; }
/// <summary> Gets the name of the station.</summary>
public string StationName { get; }
/// <summary> Holds the gps- position of the station.</summary>
public Position Position { get; }
}
}

View file

@ -0,0 +1,97 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace TINK.Model.Station
{
public class StationDictionary : IEnumerable<Station>
{
/// <summary> Holds the list of stations. </summary>
private readonly IDictionary<int, Station> m_oStationDictionary;
/// <summary> Count of stations. </summary>
public int Count { get { return m_oStationDictionary.Count; } }
public Version CopriVersion { get; }
/// <summary> Constructs a station dictionary object. </summary>
/// <param name="p_oVersion">Version of copri- service.</param>
public StationDictionary(Version p_oVersion = null, IDictionary<int, Station> p_oStations = null)
{
m_oStationDictionary = p_oStations ?? new Dictionary<int, Station>();
CopriVersion = p_oVersion != null
? new Version(p_oVersion.Major, p_oVersion.Minor, p_oVersion.Revision, p_oVersion.Build)
: new Version(0, 0, 0, 0);
}
public IEnumerator<Station> GetEnumerator()
{
return m_oStationDictionary.Values.GetEnumerator();
}
/// <summary>
/// Deteermines whether a station by given key exists.
/// </summary>
/// <param name="p_strKey">Key to check.</param>
/// <returns>True if station exists.</returns>
public bool ContainsKey(int p_strKey)
{
return m_oStationDictionary.ContainsKey(p_strKey);
}
/// <summary>
/// Remove a station by station id.
/// </summary>
/// <param name="p_iId"></param>
public void RemoveById(int p_iId)
{
if (!m_oStationDictionary.ContainsKey(p_iId))
{
// Nothing to do if there is no station with given name.
return;
}
m_oStationDictionary.Remove(p_iId);
}
/// <summary>
/// Remove a station by station name.
/// </summary>
/// <param name="p_iId"></param>
public Station GetById(int p_iId)
{
if (!m_oStationDictionary.ContainsKey(p_iId))
{
// Nothing to do if there is no station with given name.
return null;
}
return m_oStationDictionary[p_iId];
}
/// <summary>
/// Adds a station to dictionary of stations.
/// </summary>
/// <param name="p_oStation"></param>
public void Add(Station p_oStation)
{
if (p_oStation == null)
{
throw new ArgumentException("Can not add empty station to collection of stations.");
}
if (m_oStationDictionary.ContainsKey(p_oStation.Id))
{
throw new ArgumentException(string.Format("Can not add station {0} to collection of stations. A station with given name already exists.", p_oStation.Id));
}
m_oStationDictionary.Add(p_oStation.Id, p_oStation);
}
IEnumerator IEnumerable.GetEnumerator()
{
return m_oStationDictionary.Values.GetEnumerator();
}
}
}