// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tools.DotNETCommon
{
///
/// Wrapper around the HashSet container that only allows read operations
///
/// Type of element for the hashset
public class ReadOnlyHashSet : IReadOnlyCollection
{
///
/// The mutable hashset
///
HashSet Inner;
///
/// Constructor
///
/// The mutable hashset
public ReadOnlyHashSet(HashSet Inner)
{
this.Inner = Inner;
}
///
/// Constructor
///
/// Elements for the hash set
public ReadOnlyHashSet(IEnumerable Elements)
{
this.Inner = new HashSet(Elements);
}
///
/// Constructor
///
/// Elements for the hash set
/// Comparer for elements in the set
public ReadOnlyHashSet(IEnumerable Elements, IEqualityComparer Comparer)
{
this.Inner = new HashSet(Elements, Comparer);
}
///
/// Number of elements in the set
///
public int Count
{
get { return Inner.Count; }
}
///
/// The comparer for elements in the set
///
public IEqualityComparer Comparer
{
get { return Inner.Comparer; }
}
///
/// Tests whether a given item is in the set
///
/// Item to check for
/// True if the item is in the set
public bool Contains(T Item)
{
return Inner.Contains(Item);
}
///
/// Gets an enumerator for set elements
///
/// Enumerator instance
public IEnumerator GetEnumerator()
{
return Inner.GetEnumerator();
}
///
/// Gets an enumerator for set elements
///
/// Enumerator instance
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)Inner).GetEnumerator();
}
}
}