/// Copyright (c) 2021 Iiro Iivanainen, Harri Linna, Jere Pakkanen, Riikka Vilavaara /// /// Permission is hereby granted, free of charge, to any person obtaining /// a copy of this software and associated documentation files (the /// "Software"), to deal in the Software without restriction, including /// without limitation the rights to use, copy, modify, merge, publish, /// distribute, sublicense, and/or sell copies of the Software, and to /// permit persons to whom the Software is furnished to do so, subject to /// the following conditions: /// /// The above copyright notice and this permission notice shall be included /// in all copies or substantial portions of the Software. /// /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, /// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF /// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. /// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY /// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, /// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE /// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /// using System.Collections.Generic; using System.Text.Json.Serialization; namespace CoreLibrary { /// /// Metas class contains list of metadata. /// Contains all metadata that is relative to a single object (attached data or sample) /// public class Metas { public List MetaList { get; set; } /// /// Constructor for JSON serialization and deserialization. Note that the /// parameter names must match the attribute names (non case sensitive) /// /// [JsonConstructor] public Metas(List metalist) { MetaList = metalist; } /// /// Default constructor of Metas. /// public Metas() { MetaList = new List(); } /// /// Returns a clone object of the Metas given /// /// Metas object to be cloned. /// A clonse object of the metas-object public static Metas Clone(Metas toBeCloned) { Metas clone = new Metas(); foreach(Meta m in toBeCloned.MetaList) { clone.AddData(m.Name, m.Info); } return clone; } /// /// Sets metadata of set name to set value or creates metadata /// of set name with set value if it doesn't exist. /// /// Name of the metadata. /// Content of the metadata. /// if the metadata existed. public bool SetData (string name, string info) { foreach (Meta m in this.MetaList) { if(m.Name == name) { m.Info = info; return true; } } this.AddData(name, info); return false; } /// /// Adds new metadata of specified name and value. /// /// Name of the metadata. /// Content of the metadata. public void AddData(string name, string info) { var m = new Meta(); m.Name = name; m.Info = info; MetaList.Add(m); } /// /// Adds a metadata object to the metadata list. /// /// Metadata object. public void AddData(Meta meta) { MetaList.Add(meta); } /// /// Removes the first matching metadata of specified name /// /// Name of the metadata. /// Was the metadata found and deleted. public bool RemoveMetaByName(string name) { var toBeRemoved = MetaList.Find(m => m.Name == name); return MetaList.Remove(toBeRemoved); } /// /// Removes metadata object from metadata list /// /// Metadata object to be removed /// Was the metadata found and deleted. public bool RemoveMeta(Meta meta) { return MetaList.Remove(meta); } /// /// Returns the metadata list. /// /// Metadata list. internal List GetMetaList() { return MetaList; } } }