public Mail this[ulong id] => CollectionExtensions.GetValueOrDefault(_mails, id);
public Player Get(ulong accountId) { return(CollectionExtensions.GetValueOrDefault(_players, accountId)); }
private PropertyOverwrite GetPropertyOverwrite(Property property) { return(CollectionExtensions.GetValueOrDefault(_overwrite.PropertyOverwrites, $"{property.DataClass.Name}.{property.Name}", defaultValue: null)); }
private TaskOverwrite GetTaskOverwrite(Task task) { var overwriteName = task.Postfix == null ? string.Empty : char.ToLower(task.Postfix[index: 0]) + task.Postfix.Substring(startIndex: 1); return(CollectionExtensions.GetValueOrDefault(_overwrite.TaskOverwrites, overwriteName, defaultValue: null)); }
/// <summary> /// Returns the license or null if the license does not exist /// </summary> public License GetLicense(ItemLicense license) { return(CollectionExtensions.GetValueOrDefault(_licenses, license)); }
public Deny this[ulong accountId] => CollectionExtensions.GetValueOrDefault(_denies, accountId);
public Friend this[ulong accountId] => CollectionExtensions.GetValueOrDefault(_friends, accountId);
public static TType GetValueOrDefault <TType>(this Dictionary <string, object> dictionary, string key) { var value = CollectionExtensions.GetValueOrDefault(dictionary, key); return((TType)value); }
/// <summary> /// Converts a dictionary of <see cref="ReturnsSymbolData"/> keyed by <see cref="Symbol"/> into a matrix /// </summary> /// <param name="symbolData">Dictionary of <see cref="ReturnsSymbolData"/> keyed by <see cref="Symbol"/> to be converted into a matrix</param> /// <param name="symbols">List of <see cref="Symbol"/> to be included in the matrix</param> public static double[,] FormReturnsMatrix(this Dictionary <Symbol, ReturnsSymbolData> symbolData, IEnumerable <Symbol> symbols) { var returnsByDate = (from s in symbols join sd in symbolData on s equals sd.Key select sd.Value.Returns).ToList(); // Consolidate by date var alldates = returnsByDate.SelectMany(r => r.Keys).Distinct().ToList(); var max = symbolData.Count == 0 ? 0 : symbolData.Max(kvp => kvp.Value.Returns.Count); // Perfect match between the dates in the ReturnsSymbolData objects if (max == alldates.Count) { return(Accord.Math.Matrix.Create(alldates // if a return date isn't found for a symbol we use 'double.NaN' #if NETCORE .Select(d => returnsByDate.Select(s => CollectionExtensions.GetValueOrDefault(s, d, double.NaN)).ToArray()) #else .Select(d => returnsByDate.Select(s => s.GetValueOrDefault(d, double.NaN)).ToArray()) #endif .Where(r => !r.Select(Math.Abs).Sum().IsNaNOrZero()) // remove empty rows .ToArray())); } // If it is not a match, we assume that each index correspond to the same point in time var returnsByIndex = returnsByDate.Select((doubles, i) => doubles.Values.ToArray()); return(Accord.Math.Matrix.Create(Enumerable.Range(0, max) // there is no guarantee that all symbols have the same amount of returns so we need to check range and use 'double.NaN' if required as above .Select(d => returnsByIndex.Select(s => s.Length < (d + 1) ? double.NaN : s[d]).ToArray()) .Where(r => !r.Select(Math.Abs).Sum().IsNaNOrZero()) // remove empty rows .ToArray())); }