using System.Collections.Generic; using System.Linq; using MahTweets.Core.Interfaces; using MahTweets.Core.UpdateTypes; namespace MahTweets.Core.Extensions { namespace MahTweets.Core.Extensions { public static class UpdateTypeExtensions { public static bool HasColor(this UpdateType updateType) { return !string.IsNullOrEmpty(updateType.ColorArgb); } public static bool Is(this UpdateType updateType, string compare) { return updateType.Type.Matches(compare); } public static bool Is(this UpdateType updateType, UpdateType update) { if (updateType == null || update == null) { return false; } return updateType.Type.Matches(update.Type); } public static bool Is(this UpdateType updateType, string compare, bool ignoreCase) { return updateType.Type.Matches(compare, ignoreCase); } public static bool HasType(this IList updates, string type) { var found = updates.Where(x => x.Is(type)).FirstOrDefault(); return (found != null); } public static bool HasTypes(this IList updates, params string[] types) { return types.All(t => updates.HasType(t)); } public static bool Matches(this IList updates, UpdateType type) { if (type == null) return false; return updates.Any(t => t.Type == type.Type); } public static bool HasType(this IList updates) where T : UpdateType { return updates.OfType().Any(); } public static void AddUpdate(this IList updates, IMicroblog parent) where T : UpdateType, new() { if (updates != null) if (!updates.OfType().Any()) { updates.Add(new T {Parent = parent}); } } } } }