remove ObservableLinkedList
This commit is contained in:
parent
8de22f5ba2
commit
ba4ce7aed1
@ -1,151 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.Specialized;
|
|
||||||
|
|
||||||
namespace ObservableCollections
|
|
||||||
{
|
|
||||||
public sealed partial class ObservableLinkedList<T>
|
|
||||||
{
|
|
||||||
public ISynchronizedView<LinkedListNode<T>, TView> CreateView<TView>(Func<LinkedListNode<T>, TView> transform, bool reverse = false)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed class View<TView> : ISynchronizedView<LinkedListNode<T>, TView>
|
|
||||||
{
|
|
||||||
readonly ObservableLinkedList<T> source;
|
|
||||||
readonly Dictionary<LinkedListNode<T>, LinkedListNode<(LinkedListNode<T>, TView)>> nodeMap;
|
|
||||||
readonly LinkedList<(LinkedListNode<T>, TView)> list;
|
|
||||||
readonly Func<LinkedListNode<T>, TView> selector;
|
|
||||||
|
|
||||||
public View(ObservableLinkedList<T> source)
|
|
||||||
{
|
|
||||||
this.source = source;
|
|
||||||
|
|
||||||
lock (source.SyncRoot)
|
|
||||||
{
|
|
||||||
// TODO:get map
|
|
||||||
source.CollectionChanged += SourceCollectionChanged;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public object SyncRoot => throw new NotImplementedException();
|
|
||||||
public event NotifyCollectionChangedEventHandler<LinkedListNode<T>>? RoutingCollectionChanged;
|
|
||||||
public event Action<NotifyCollectionChangedAction>? CollectionStateChanged;
|
|
||||||
|
|
||||||
|
|
||||||
public int Count => throw new NotImplementedException();
|
|
||||||
|
|
||||||
|
|
||||||
public void AttachFilter(ISynchronizedViewFilter<LinkedListNode<T>, TView> filter)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerator<(LinkedListNode<T> Value, TView View)> GetEnumerator()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResetFilter(Action<LinkedListNode<T>, TView>? resetAction)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public INotifyCollectionChangedSynchronizedView<LinkedListNode<T>, TView> WithINotifyCollectionChanged()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void SourceCollectionChanged(in NotifyCollectionChangedEventArgs<LinkedListNode<T>> e)
|
|
||||||
{
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
// Range operations is not supported.
|
|
||||||
switch (e.Action)
|
|
||||||
{
|
|
||||||
case NotifyCollectionChangedAction.Add:
|
|
||||||
{
|
|
||||||
var view = selector(e.NewItem);
|
|
||||||
var value = (e.NewItem, view);
|
|
||||||
LinkedListNode<(LinkedListNode<T>, TView)>? addNode = null;
|
|
||||||
|
|
||||||
if (e.OldItem == null)
|
|
||||||
{
|
|
||||||
// AddFirst
|
|
||||||
if (e.NewStartingIndex == 0)
|
|
||||||
{
|
|
||||||
addNode = list.AddFirst(value);
|
|
||||||
}
|
|
||||||
// AddLast
|
|
||||||
else
|
|
||||||
{
|
|
||||||
addNode = list.AddLast(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// AddBefore
|
|
||||||
if (e.NewStartingIndex == -1)
|
|
||||||
{
|
|
||||||
if (nodeMap.TryGetValue(e.OldItem, out var node))
|
|
||||||
{
|
|
||||||
addNode = list.AddBefore(node, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// AddAfter
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (nodeMap.TryGetValue(e.OldItem, out var node))
|
|
||||||
{
|
|
||||||
addNode = list.AddAfter(node, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addNode != null)
|
|
||||||
{
|
|
||||||
nodeMap.Add(e.NewItem, addNode);
|
|
||||||
// TODO: filter invoke.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NotifyCollectionChangedAction.Remove:
|
|
||||||
{
|
|
||||||
if (nodeMap.Remove(e.OldItem, out var node))
|
|
||||||
{
|
|
||||||
list.Remove(node);
|
|
||||||
// TODO:filter invoke
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NotifyCollectionChangedAction.Reset:
|
|
||||||
{
|
|
||||||
nodeMap.Clear();
|
|
||||||
list.Clear();
|
|
||||||
|
|
||||||
// TODO:filter invoke
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NotifyCollectionChangedAction.Replace:
|
|
||||||
case NotifyCollectionChangedAction.Move:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,156 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.Specialized;
|
|
||||||
|
|
||||||
namespace ObservableCollections
|
|
||||||
{
|
|
||||||
// TODO:Remove this???
|
|
||||||
public sealed partial class ObservableLinkedList<T> : IReadOnlyCollection<T>, IObservableCollection<LinkedListNode<T>>
|
|
||||||
{
|
|
||||||
readonly LinkedList<T> list;
|
|
||||||
public object SyncRoot { get; } = new object();
|
|
||||||
|
|
||||||
public event NotifyCollectionChangedEventHandler<LinkedListNode<T>>? CollectionChanged;
|
|
||||||
|
|
||||||
public ObservableLinkedList()
|
|
||||||
{
|
|
||||||
this.list = new LinkedList<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObservableLinkedList(IEnumerable<T> collection)
|
|
||||||
{
|
|
||||||
this.list = new LinkedList<T>(collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: First, Last
|
|
||||||
// Find, FindLast
|
|
||||||
|
|
||||||
public int Count
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
return list.Count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public LinkedListNode<T> AddFirst(T item)
|
|
||||||
{
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
var node = list.AddFirst(item);
|
|
||||||
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Add(node, 0));
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public LinkedListNode<T> AddLast(T item)
|
|
||||||
{
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
var index = list.Count;
|
|
||||||
var node = list.AddLast(item);
|
|
||||||
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Add(node, index));
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public LinkedListNode<T> AddBefore(LinkedListNode<T> node, T value)
|
|
||||||
{
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
var newNode = list.AddBefore(node, value);
|
|
||||||
|
|
||||||
// special event, oldItem is target, newStartingIndex:-1 = before
|
|
||||||
var ev = new NotifyCollectionChangedEventArgs<LinkedListNode<T>>(
|
|
||||||
NotifyCollectionChangedAction.Add, isSingleItem: true,
|
|
||||||
newItem: newNode, oldItem: node, newStartingIndex: -1);
|
|
||||||
|
|
||||||
CollectionChanged?.Invoke(ev);
|
|
||||||
return newNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public LinkedListNode<T> AddAfter(LinkedListNode<T> node, T value)
|
|
||||||
{
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
var newNode = list.AddAfter(node, value);
|
|
||||||
|
|
||||||
// special event, oldItem is target, newStartingIndex:1 = after
|
|
||||||
var ev = new NotifyCollectionChangedEventArgs<LinkedListNode<T>>(
|
|
||||||
NotifyCollectionChangedAction.Add, isSingleItem: true,
|
|
||||||
newItem: newNode, oldItem: node, newStartingIndex: 1);
|
|
||||||
|
|
||||||
CollectionChanged?.Invoke(ev);
|
|
||||||
return newNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RemoveLast()
|
|
||||||
{
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
var last = list.Last;
|
|
||||||
list.RemoveLast();
|
|
||||||
if (last != null)
|
|
||||||
{
|
|
||||||
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Remove(last, -1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RemoveFirst()
|
|
||||||
{
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
var first = list.First;
|
|
||||||
list.RemoveFirst();
|
|
||||||
if (first != null)
|
|
||||||
{
|
|
||||||
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Remove(first, -1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Remove(LinkedListNode<T> item)
|
|
||||||
{
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
list.Remove(item);
|
|
||||||
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Remove(item, -1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
lock (SyncRoot)
|
|
||||||
{
|
|
||||||
list.Clear();
|
|
||||||
CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs<LinkedListNode<T>>.Reset());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerator<LinkedListNode<T>> GetEnumerator()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: GetEnumerator
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user