public IteratableTreeNode(T value) { Value = value; Previous = null; Next = null; }
public static void Copy <T, TSize, TInput, TOutput>(IIteratable <T, TSize, TInput> hive, TOutput target) where TInput : struct, IInputIterator <T, TSize, TInput> where TOutput : struct, IOutputIterator <T, TOutput> where TSize : struct, IConvertible { Copy <T, TSize, TInput, TOutput>(hive.Begin, hive.End, target); }
public bool Insert(int position, IIteratable <IteratableTreeNode <T> > iteratableNode) { if (Children == default) { Children = new List <ITreeNode <T> >(); } if (position < 0 || position > Children.Count) { AddChild((ITreeNode <T>)iteratableNode); return(true); } var previous = position > 0 ? (IteratableTreeNode <T>)Children[position - 1] : null; var next = position < Children.Count ? (IteratableTreeNode <T>)Children[position] : null; if (previous != null) { previous.Next = iteratableNode; } if (next != null) { next.Previous = iteratableNode; } iteratableNode.Previous = previous; iteratableNode.Next = next; Children.Add((ITreeNode <T>)iteratableNode); return(true); }
/// <summary> /// Gets the first child of an group. /// </summary> /// <param name="_current">The current child element which is a group.</param> /// <returns> /// The first element of the child group if available; /// otherwise <c>null</c>.</returns> protected static IDialogComponent GetLastOfIIteratableChild(IIteratable _current) { if (_current != null && _current.HasChildren()) { return(_current.GetLast()); } return(null); }
/// <summary> /// Filters objects depending on <paramref name="predicate"/> /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="source"></param> /// <param name="predicate"></param> /// <returns></returns> public static IIteratable <TSource> Where <TSource>(this IIteratable <TSource> source, Func <TSource, bool> predicate) { if (source == null) { throw new ArgumentNullException("source"); } var ret = new WhereEnumerable <TSource>(source, predicate); return(ret); }
/// <summary> /// Uses <paramref name="func"/> on every object in <paramref name="source"/> /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="source"></param> /// <param name="func"></param> /// <returns></returns> public static IIteratable <TSource> Map <TSource>(this IIteratable <TSource> source, Func <TSource, TSource> func) { if (source == null) { throw new ArgumentNullException("source"); } var ret = new MapEnumerable <TSource>(source, func); return(ret); }
public static bool All <T>(this IIteratable <T> source, Func <T, bool> predicate) { foreach (var element in source) { if (!predicate(element)) { return(false); } } return(true); }
internal static void Copy <T, TSize, TInput>(IIteratable <T, TSize, TInput> hive, T[] array, TSize startIndex) where TInput : struct, IInputIterator <T, TSize, TInput> where TSize : struct, IConvertible { long targetIndex = SizeOperations <TSize> .Default.ToInt64(startIndex); for (TInput i = hive.Begin; !i.Equals(hive.End); i.Increment()) { array[targetIndex++] = i.Read(); } }
/// <summary> /// Conerts <typeparamref name="IIteratable"/> <paramref name="source"/> to <typeparamref name="TSource"/> array /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="source"></param> /// <returns></returns> public static TSource[] ToArray <TSource>(this IIteratable <TSource> source) { TSource[] ret = new TSource[source.Count()]; int i = 0; foreach (TSource item in source) { ret[i] = item; i++; } return(ret); }
private void ConnectPreviousAndNextNodes(IIteratable <IteratableTreeNode <T> > previous, IIteratable <IteratableTreeNode <T> > next) { if (previous != null) { previous.Next = next; } if (next != null) { next.Previous = previous; } }
/// <summary> /// Returns first object in <paramref name="source"/> which satisfies the <paramref name="predicate"/> /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="source"></param> /// <param name="predicate"></param> /// <returns></returns> public static TSource FirstOrDefault <TSource>(this IIteratable <TSource> source, Func <TSource, bool> predicate) { if (source == null) { throw new ArgumentNullException("source"); } foreach (TSource item in source) { if (predicate(item)) { return(item); } } return(default);
/// <summary> /// Returns number of objects in <paramref name="source"/> /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="source"></param> /// <returns></returns> public static int Count <TSource>(this IIteratable <TSource> source) { if (source == null) { throw new ArgumentNullException("source"); } int cnt = 0; foreach (TSource item in source) { cnt++; } return(cnt); }
/// <summary> /// Returns true if at least one object in <paramref name="source"/> satisfies the <paramref name="predicate"/> /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="source"></param> /// <param name="predicate"></param> /// <returns></returns> public static bool Some <TSource>(this IIteratable <TSource> source, Func <TSource, bool> predicate) { if (source == null) { throw new ArgumentNullException("source"); } foreach (TSource item in source) { if (predicate(item)) { return(true); } } return(false); }
/// <summary> /// Gets the next child of an group. /// </summary> /// <param name="_current">The current child element which is a group.</param> /// <returns> /// The next element of the child group if available; /// otherwise the first element if available; /// otherwise <c>null</c>.</returns> protected static IDialogComponent GetNextOfIIteratableChild(IIteratable _current) { if (_current != null && _current.HasChildren()) { var next = _current.GetNext(); if (next != null) { return(next); } else { next = _current.GetFirst(); if (next != null) { return(next); } } } return(null); }
/// <summary> /// Gets the previous child of an group. /// </summary> /// <param name="_current">The current child element which is a group.</param> /// <returns> /// The previous element of the child group if available; /// otherwise the last element if available; /// otherwise <c>null</c>.</returns> protected static IDialogComponent GetPreviouseOfIIteratableChild(IIteratable _current) { if (_current != null && _current.HasChildren()) { var prev = _current.GetPrevious(); if (prev != null) { return(prev); } else { prev = _current.GetLast(); if (prev != null) { return(prev); } } } return(null); }
public ConcatEnumerable(IIteratable <TSource> first, IIteratable <TSource> second) { iteratables = new IIteratable <TSource> [2]; iteratables[0] = first; iteratables[1] = second; }
public static Range <T, TSize, TIterator> Enumerate <T, TSize, TIterator>(IIteratable <T, TSize, TIterator> hive) where TIterator : struct, IInputIterator <T, TSize, TIterator> where TSize : struct, IConvertible { return(new Range <T, TSize, TIterator>(hive)); }
public void Add(IIteratable act) { Then = act; }
public MapEnumerator(IIteratable <T> sourceIteratable, Func <T, S> selector) { _sourceIteratable = sourceIteratable; _sourceIEnumerator = sourceIteratable.GetEnumerator(); _selector = selector; }
public ConsoleRadioBoxElement(ConsoleRadioBox parent, string text, ConsoleColor color) { Parent = parent; Text = text; Color = color; }
public static IIteratable <T> Filter <T>(this IIteratable <T> source, Func <T, bool> predicate) { return(new WhereEnumerator <T>(source, predicate)); }
public static IIteratable <S> Map <T, S>(this IIteratable <T> source, Func <T, S> selector) { return(new MapEnumerator <T, S>(source, selector)); }
public void AddRouter(IRouterStatus RouterStatus, IIteratable Iterator) { Routers.Add(RouterStatus); IterableRouters.Add(Iterator); }
public WhereEnumerable(IIteratable <TSource> source, Func <TSource, bool> func) { this.source = source; this.func = func; }
public WhereEnumerator(IIteratable <T> sourceIteratable, Func <T, bool> predicate) { _sourceIteratable = sourceIteratable; _sourceIEnumerator = sourceIteratable.GetEnumerator(); _predicate = predicate; }
public HiveEnumerator(IIteratable <T, TSize, TIterator> hive) : this(hive.Begin, hive.End) { }
public MapEnumerable(IIteratable <TSource> source, Func <TSource, TSource> func) { this.source = source; this.func = func; }
public Range(IIteratable <T, TSize, TIterator> hive) { _begin = hive.Begin; _end = hive.End; }
public void AddRouter(IRouterStatus RouterStatus, IIteratable Iterator) { Routers.Add(RouterStatus); IterableRouters.Add(Iterator); }
public void Add(IIteratable act) { Meths.Add(act); }
public SelectEnumerable(IIteratable <TSource> source, Func <TSource, TRetrun> selector) { this.source = source; this.selector = selector; }