/* INFINITY CODE 2013-2019 */
/* http://www.infinity-code.com */
using System.Collections.Generic;
using System.Linq;
namespace InfinityCode.RealWorldTerrain.OSM
{
///
/// The base class for the Open Street Map objects.
///
public class RealWorldTerrainOSMBase
{
///
/// ID.
///
public string id;
///
/// List of tags.
///
public List tags;
public bool Equals(RealWorldTerrainOSMBase other)
{
if (ReferenceEquals(other, null)) return false;
if (ReferenceEquals(this, other)) return true;
return id == other.id;
}
public override int GetHashCode()
{
return id.GetHashCode();
}
///
/// Gets tag value by key.
///
/// Tag key.
/// Tag value or string.Empty.
public string GetTagValue(string key)
{
List curTags = tags.Where(tag => tag.key == key).ToList();
if (curTags.Count > 0) return curTags[0].value;
return string.Empty;
}
///
/// Checks tag with the specified pair (key, value).
///
/// Tag key.
/// Tag value.
/// True - success, False - otherwise.
public bool HasTag(string key, string value)
{
return tags.Any(t => t.key == key && t.value == value);
}
///
/// Checks whether there is a tag with at least one of the keys.
///
/// Keys
/// True - success, False - otherwise.
public bool HasTagKey(params string[] keys)
{
return keys.Any(key => tags.Any(t => t.key == key));
}
///
/// Checks whether there is a tag with at least one of the values.
///
/// Values
/// True - success, False - otherwise.
public bool HasTagValue(params string[] values)
{
return values.Any(val => tags.Any(t => t.value == val));
}
///
/// Checks whether there is a tag with key and at least one of the values.
///
/// Key
/// Values
/// True - success, False - otherwise.
public bool HasTags(string key, params string[] values)
{
return tags.Any(tag => tag.key == key && values.Any(v => v == tag.value));
}
}
}