public TrackStretch Add(TrackStretch stretch) { if (stretch == null) { throw new ArgumentNullException(nameof(stretch)); } if (TrackStretches.Contains(stretch)) { return(stretch); } TrackStretches.Add(stretch); return(TrackStretches.Last()); }
public Maybe <TrackStretch> TrackStretch(Station from, Station to) { var stretches = TrackStretches.Where(ts => (ts.Start.Station.Equals(from) && ts.End.Station.Equals(to)) || (ts.Start.Station.Equals(to) && ts.End.Station.Equals(from))); if (stretches.Count() == 1) { return(Maybe <TrackStretch> .Item(stretches.First())); } if (!stretches.Any()) { return(Maybe <TrackStretch> .None(string.Format(CultureInfo.CurrentCulture, Resources.Strings.ThereIsNoStretchBetweenStation1AndStation2, from, to))); } return(Maybe <TrackStretch> .None(string.Format(CultureInfo.CurrentCulture, Resources.Strings.MoreThanOneStretchBetweenStations, from, to))); }