Update Changelog
[profile/ivi/libgee.git] / gee / readonlysortedset.vala
1 /* readonlysortedset.vala
2  *
3  * Copyright (C) 2009  Didier Villevalois, Maciej Piechotka
4  * Copyright (C) 2011  Maciej Piechotka
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19  *
20  * Author:
21  *      Maciej Piechotka <uzytkownik2@gmail.com>
22  */
23
24 /**
25  * Read-only view for {@link SortedSet} collections.
26  *
27  * This class decorates any class which implements the {@link SortedSet} interface
28  * by making it read only. Any method which normally modify data will throw an
29  * error.
30  *
31  * @see SortedSet
32  */
33 internal class Gee.ReadOnlySortedSet<G> : ReadOnlySet<G>, SortedSet<G> {
34         /**
35          * Constructs a read-only set that mirrors the content of the specified set.
36          *
37          * @param set the set to decorate.
38          */
39         public ReadOnlySortedSet (SortedSet<G> set) {
40                 base (set);
41         }
42
43         /**
44          * {@inheritDoc}
45          */
46         public G first () {
47                 return (_collection as SortedSet<G>).first ();
48         }
49
50         /**
51          * {@inheritDoc}
52          */
53         public G last () {
54                 return (_collection as SortedSet<G>).last ();
55         }
56
57         /**
58          * {@inheritDoc}
59          */
60         public Gee.Iterator<G>? iterator_at (G element) {
61                 var iter = (_collection as SortedSet<G>).iterator_at (element);
62                 return (iter != null) ? new Iterator<G> (iter) : null;
63         }
64
65         /**
66          * {@inheritDoc}
67          */
68         public G? lower (G element) {
69                 return (_collection as SortedSet<G>).lower (element);
70         }
71
72         /**
73          * {@inheritDoc}
74          */
75         public G? higher (G element) {
76                 return (_collection as SortedSet<G>).higher (element);
77         }
78
79         /**
80          * {@inheritDoc}
81          */
82         public G? floor (G element) {
83                 return (_collection as SortedSet<G>).floor (element);
84         }
85
86         /**
87          * {@inheritDoc}
88          */
89         public G? ceil (G element) {
90                 return (_collection as SortedSet<G>).ceil (element);
91         }
92
93         /**
94          * {@inheritDoc}
95          */
96         public SortedSet<G> head_set (G before) {
97                 return (_collection as SortedSet<G>).head_set (before).read_only_view;
98         }
99
100         /**
101          * {@inheritDoc}
102          */
103         public SortedSet<G> tail_set (G after) {
104                 return(_collection as SortedSet<G>).tail_set (after).read_only_view;
105         }
106
107         /**
108          * {@inheritDoc}
109          */
110         public SortedSet<G> sub_set (G from, G to) {
111                 return (_collection as SortedSet<G>).sub_set (from, to).read_only_view;
112         }
113
114         /**
115          * {@inheritDoc}
116          */
117         public new SortedSet<G> read_only_view {
118                 owned get {
119                         return this;
120                 }
121         }
122 }
123