using System.Text.Json.Serialization; namespace OSMDatastructure; [Serializable] public class TagManager { [JsonRequired]public Dictionary> wayTagSets { get; set; } public TagManager() { wayTagSets = new(); } public bool ContainsKey(ulong wayId, Tag.TagType key) { return wayTagSets.ContainsKey(wayId) && wayTagSets[wayId].Any(tag => tag.key == key); } public object? GetTag(ulong wayId, Tag.TagType key) { return ContainsKey(wayId, key) ? wayTagSets[wayId].First(tag => tag.key == key).value : null; } public void AddTag(ulong wayId, string key, string value) { HashSet pTags = Tag.ConvertToTags(key, value); if(pTags.Count > 0) foreach (Tag pTag in pTags) AddTag(wayId, pTag); } public void AddTag(ulong wayId, Tag tag) { if(!wayTagSets.ContainsKey(wayId)) wayTagSets.Add(wayId, new HashSet()); HashSet wayTags = wayTagSets[wayId]; if (!wayTags.Any(wayTag => wayTag.key == tag.key)) { wayTags.Add(tag); } } public void AddTag(ulong wayId, KeyValuePair tag) { AddTag(wayId, new Tag(tag.Key, tag.Value)); } public HashSet? GetTagsForWayId(ulong wayId) { return wayTagSets.TryGetValue(wayId, out HashSet? value) ? value : null; } public bool ContainsWay(ulong wayId) { return wayTagSets.ContainsKey(wayId); } }