2 using System
.Collections
;
6 public class SortedTileList
: IEnumerable
, ICloneable
{
10 public SortedTileList (Search
.SortType sort
) : this (sort
, new ArrayList ()) {}
12 SortedTileList (Search
.SortType sort
, ArrayList tiles
)
18 public int Add (Tiles
.Tile tile
)
20 int index
= tiles
.BinarySearch (tile
, comparer
);
22 throw new ArgumentException ("duplicate");
24 tiles
.Insert (~index
, tile
);
33 public bool Contains (Tiles
.Tile tile
)
35 return tiles
.Contains (tile
);
38 public int IndexOf (Tiles
.Tile tile
)
40 return tiles
.IndexOf (tile
);
43 public void Remove (Tiles
.Tile tile
)
45 int index
= tiles
.BinarySearch (tile
, comparer
);
47 tiles
.RemoveAt (index
);
50 public void RemoveAt (int index
)
52 tiles
.RemoveAt (index
);
55 public Tiles
.Tile
this[int index
] {
57 return (Tiles
.Tile
)tiles
[index
];
67 public IEnumerator
GetEnumerator ()
69 return tiles
.GetEnumerator ();
72 public object Clone ()
74 return new SortedTileList (sort
, (ArrayList
)tiles
.Clone ());
77 public IList
GetRange (int index
, int count
)
79 return tiles
.GetRange (index
, count
);
85 public Search
.SortType Sort
{
92 case SortType
.Relevance
:
94 comparer
= new RelevanceComparer ();
97 comparer
= new NameComparer ();
99 case SortType
.Modified
:
100 comparer
= new DateComparer ();
104 tiles
.Sort (comparer
);
109 abstract class TileComparer
: IComparer
{
110 public int Compare (object x
, object y
)
112 Tiles
.Tile tx
= (Tiles
.Tile
)x
, ty
= (Tiles
.Tile
)y
;
115 ret
= Compare (tx
, ty
);
117 ret
= -tx
.Timestamp
.CompareTo (ty
.Timestamp
);
119 ret
= tx
.GetHashCode ().CompareTo (ty
.GetHashCode ());
123 public abstract int Compare (Tiles
.Tile tx
, Tiles
.Tile ty
);
126 class RelevanceComparer
: TileComparer
{
127 public override int Compare (Tiles
.Tile tx
, Tiles
.Tile ty
)
129 return -tx
.Score
.CompareTo (ty
.Score
);
133 class NameComparer
: TileComparer
{
134 public override int Compare (Tiles
.Tile tx
, Tiles
.Tile ty
)
136 return String
.Compare (tx
.Title
, ty
.Title
, true);
140 class DateComparer
: TileComparer
{
141 public override int Compare (Tiles
.Tile tx
, Tiles
.Tile ty
)
143 return -tx
.Timestamp
.CompareTo (ty
.Timestamp
);