using System;
using System.Collections;
/// <summary>
/// 심플 리스트
/// </summary>
public class SimpleList : IList
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 객체 배열
/// </summary>
private object[] objectArray = new object[8];
/// <summary>
/// 카운트
/// </summary>
private int count;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
// IList
#region 리스트 고정 크기 여부 - IsFixedSize
/// <summary>
/// 리스트 고정 크기 여부
/// </summary>
public bool IsFixedSize
{
get
{
return true;
}
}
#endregion
// IList
#region 읽기 전용 여부 - IsReadOnly
/// <summary>
/// 읽기 전용 여부
/// </summary>
public bool IsReadOnly
{
get
{
return false;
}
}
#endregion
// IList
#region 인덱서 - this[index]
/// <summary>
/// 인덱서
/// </summary>
/// <param name="index">인덱스</param>
/// <returns>항목</returns>
public object this[int index]
{
get
{
return this.objectArray[index];
}
set
{
this.objectArray[index] = value;
}
}
#endregion
// ICollection
#region 카운트 - Count
/// <summary>
/// 카운트
/// </summary>
public int Count
{
get
{
return this.count;
}
}
#endregion
// ICollection
#region 동기화 여부 - IsSynchronized
/// <summary>
/// 동기화 여부
/// </summary>
public bool IsSynchronized
{
get
{
return false;
}
}
#endregion
// ICollection
#region 동기화 객체 - SyncRoot
/// <summary>
/// 동기화 객체
/// </summary>
public object SyncRoot
{
get
{
return this;
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - SimpleList()
/// <summary>
/// 생성자
/// </summary>
public SimpleList()
{
this.count = 0;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Public
// IList
#region 추가하기 - Add(value)
/// <summary>
/// 추가하기
/// </summary>
/// <param name="value">값</param>
/// <returns>인덱스</returns>
public int Add(object value)
{
if(this.count < this.objectArray.Length)
{
this.objectArray[this.count] = value;
this.count++;
return (this.count - 1);
}
else
{
return -1;
}
}
#endregion
// IList
#region 지우기 - Clear()
/// <summary>
/// 지우기
/// </summary>
public void Clear()
{
this.count = 0;
}
#endregion
// IList
#region 포함 여부 구하기 - Contains(value)
/// <summary>
/// 포함 여부 구하기
/// </summary>
/// <param name="value">값</param>
/// <returns>포함 여부</returns>
public bool Contains(object value)
{
bool inList = false;
for(int i = 0; i < Count; i++)
{
if(this.objectArray[i] == value)
{
inList = true;
break;
}
}
return inList;
}
#endregion
// IList
#region 인덱스 구하기 - IndexOf(value)
/// <summary>
/// 인덱스 구하기
/// </summary>
/// <param name="value">값</param>
/// <returns></returns>
public int IndexOf(object value)
{
int index = -1;
for(int i = 0; i < Count; i++)
{
if(this.objectArray[i] == value)
{
index = i;
break;
}
}
return index;
}
#endregion
// IList
#region 삽입하기 - Insert(index, value)
/// <summary>
/// 삽입하기
/// </summary>
/// <param name="index">인덱스</param>
/// <param name="value">값</param>
public void Insert(int index, object value)
{
if((this.count + 1 <= this.objectArray.Length) && (index < Count) && (index >= 0))
{
this.count++;
for(int i = Count - 1; i > index; i--)
{
this.objectArray[i] = this.objectArray[i - 1];
}
this.objectArray[index] = value;
}
}
#endregion
// IList
#region 제거하기 - Remove(value)
/// <summary>
/// 제거하기
/// </summary>
/// <param name="value">값</param>
public void Remove(object value)
{
RemoveAt(IndexOf(value));
}
#endregion
// IList
#region 제거하기 - RemoveAt(index)
/// <summary>
/// 제거하기
/// </summary>
/// <param name="index">인덱스</param>
public void RemoveAt(int index)
{
if((index >= 0) && (index < Count))
{
for(int i = index; i < Count - 1; i++)
{
this.objectArray[i] = this.objectArray[i + 1];
}
this.count--;
}
}
#endregion
// ICollection
#region 복사하기 - CopyTo(array, index)
/// <summary>
/// 복사하기
/// </summary>
/// <param name="array">배열</param>
/// <param name="index">인덱스</param>
public void CopyTo(Array array, int index)
{
int j = index;
for(int i = 0; i < Count; i++)
{
array.SetValue(this.objectArray[i], j);
j++;
}
}
#endregion
// IEnumerable
#region 열거자 구하기 - GetEnumerator()
/// <summary>
/// 열거자 구하기
/// </summary>
/// <returns>열거자</returns>
public IEnumerator GetEnumerator()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
#region 상태 출력하기 - DisplayStatus()
/// <summary>
/// 상태 출력하기
/// </summary>
public void DisplayStatus()
{
Console.WriteLine("리스트는 {0}개 용량과 현재 {1}개 요소를 갖는다.", this.objectArray.Length, this.count);
Console.Write("리스트 : ");
for(int i = 0; i < Count; i++)
{
Console.Write(" {0}", this.objectArray[i]);
}
Console.WriteLine();
}
#endregion
}