zaaReloaded2/zaaReloaded2/LabModel/Laboratory.cs

96 lines
3.0 KiB
C#
Executable File

/* Laboratory.cs
* part of zaaReloaded2
*
* Copyright 2015-2017 Daniel Kraus
*
* 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.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace zaaReloaded2.LabModel
{
/// <summary>
/// Holds laboratory items grouped by time points.
/// </summary>
public class Laboratory
{
#region Properties
public ITimePointsDictionary TimePoints { get; private set; }
#endregion
#region Constructor
public Laboratory()
{
TimePoints = new TimePointsDictionary();
}
#endregion
#region Methods
/// <summary>
/// Adds a new time point with laboratory items to the laboratory.
/// If a time point with same time stamp exists already, the new
/// items will be added to the existing ones.
/// </summary>
/// <param name="timePoint">Time point to add to the laboratory.</param>
public void AddTimePoint(TimePoint timePoint)
{
if (timePoint == null)
throw new ArgumentNullException("timePoint");
TimePoint tp;
if (TimePoints.TryGetValue(timePoint.TimeStamp, out tp))
{
tp.MergeItems(timePoint);
}
else
{
TimePoints[timePoint.TimeStamp] = timePoint;
}
}
/// <summary>
/// Checks if the Laboratory contains a TimePoint with an identical
/// time stamp to the one being queried.
/// </summary>
/// <param name="timePoint">TimePoint whose time stamp to look for.</param>
/// <returns>True if a TimePoint with identical time stamp exists.</returns>
public bool HasTimePoint(TimePoint timePoint)
{
return TimePoints.ContainsKey(timePoint.TimeStamp);
}
/// <summary>
/// Looks for a TimePoint with a given timeStamp and returns
/// it as a reference parameter.
/// </summary>
/// <param name="timeStamp">Time stamp to look for.</param>
/// <param name="timePoint">Resulting TimePoint (if any).</param>
/// <returns>True if TimePoints contains a TimePoint with
/// the requested timeStamp.</returns>
public bool TryGetTimePoint(DateTime timeStamp, ref TimePoint timePoint)
{
return TimePoints.TryGetValue(timeStamp, out timePoint);
}
#endregion
}
}