/* 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
{
///
/// Holds laboratory items grouped by time points.
///
public class Laboratory
{
#region Properties
public ITimePointsDictionary TimePoints { get; private set; }
#endregion
#region Constructor
public Laboratory()
{
TimePoints = new TimePointsDictionary();
}
#endregion
#region Methods
///
/// 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.
///
/// Time point to add to the laboratory.
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;
}
}
///
/// Checks if the Laboratory contains a TimePoint with an identical
/// time stamp to the one being queried.
///
/// TimePoint whose time stamp to look for.
/// True if a TimePoint with identical time stamp exists.
public bool HasTimePoint(TimePoint timePoint)
{
return TimePoints.ContainsKey(timePoint.TimeStamp);
}
///
/// Looks for a TimePoint with a given timeStamp and returns
/// it as a reference parameter.
///
/// Time stamp to look for.
/// Resulting TimePoint (if any).
/// True if TimePoints contains a TimePoint with
/// the requested timeStamp.
public bool TryGetTimePoint(DateTime timeStamp, ref TimePoint timePoint)
{
return TimePoints.TryGetValue(timeStamp, out timePoint);
}
#endregion
}
}