Update Changelog
[profile/ivi/libgee.git] / gee / readonlybidirsortedset.vala
1 /* readonlybidirsortedset.vala
2  *
3  * Copyright (C) 2012  Maciej Piechotka
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18  *
19  * Author:
20  *      Maciej Piechotka <uzytkownik2@gmail.com>
21  */
22
23 /**
24  * Read-only view for {@link BidirSortedSet} collections.
25  *
26  * This class decorates any class which implements the {@link BidirSortedSet}
27  * interface by making it read only. Any method which normally modify data will
28  * throw an error.
29  *
30  * @see BidirSortedSet
31  */
32 internal class Gee.ReadOnlyBidirSortedSet<G> : ReadOnlySortedSet<G>, BidirSortedSet<G> {
33         /**
34          * Constructs a read-only set that mirrors the content of the specified set.
35          *
36          * @param set the set to decorate.
37          */
38         public ReadOnlyBidirSortedSet (BidirSortedSet<G> set) {
39                 base (set);
40         }
41
42         /**
43          * {@inheritDoc}
44          */
45         public Gee.BidirIterator<G> bidir_iterator () {
46                 return new BidirIterator<G> ((_collection as BidirSortedSet<G>).bidir_iterator ());
47         }
48
49         protected class BidirIterator<G> : Gee.ReadOnlyCollection.Iterator<G>, Gee.BidirIterator<G> {
50                 public BidirIterator (Gee.BidirIterator<G> iterator) {
51                         base (iterator);
52                 }
53
54                 public bool first () {
55                         return (_iter as Gee.BidirIterator<G>).first ();
56                 }
57
58                 public bool previous () {
59                         return (_iter as Gee.BidirIterator<G>).previous ();
60                 }
61
62                 public bool has_previous () {
63                         return (_iter as Gee.BidirIterator<G>).has_previous ();
64                 }
65
66                 public bool last () {
67                         return (_iter as Gee.BidirIterator<G>).last ();
68                 }
69         }
70 }
71