/*************************************************************************************************** Copyright (C) 2025 The Qt Company Ltd. SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only ***************************************************************************************************/ using System.Collections; namespace UserViewLib { public interface IUserList : IEnumerable { int Count { get; } void Add(User user, int index = -1); void RemoveAt(int index); int BinarySearch(User user, IComparer comparer); } public class UserList : IUserList { private List Users { get; set; } = []; public int Count => Users.Count; public void Add(User user, int index = -1) { if (user == null) return; if (index < 0 || index > Users.Count) index = Users.Count; Users.Insert(index, user); } public void RemoveAt(int index) { if (index < 0 || index >= Users.Count) return; Users.RemoveAt(index); } public int BinarySearch(User user, IComparer comparer) { if (user == null) return ~Users.Count; return Users.BinarySearch(user, comparer); } public IEnumerator GetEnumerator() => Users.ToList().GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } }