// This code is distributed under MIT license.
// Copyright (c) 2010-2018 George Mamaladze
// See license.txt or https://mit-license.org/
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Gma.System.MouseKeyHook
{
///
/// Describes a sequence of generic objects.
///
///
public abstract class SequenceBase : IEnumerable
{
private readonly T[] _elements;
///
/// Creates an instance of sequnce from sequnce elements.
///
///
protected SequenceBase(params T[] elements)
{
_elements = elements;
}
///
/// Number of elements in the sequnce.
///
public int Length
{
get { return _elements.Length; }
}
///
public IEnumerator GetEnumerator()
{
return _elements.Cast().GetEnumerator();
}
///
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
///
public override string ToString()
{
return string.Join(",", _elements);
}
///
protected bool Equals(SequenceBase other)
{
if (_elements.Length != other._elements.Length) return false;
return _elements.SequenceEqual(other._elements);
}
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((SequenceBase) obj);
}
///
public override int GetHashCode()
{
unchecked
{
return (_elements.Length + 13) ^
((_elements.Length != 0
? _elements[0].GetHashCode() ^ _elements[_elements.Length - 1].GetHashCode()
: 0) * 397);
}
}
}
}