abstractmultiset.vala \
abstractqueue.vala \
abstractset.vala \
+ abstractsortedmap.vala \
abstractsortedset.vala \
arraylist.vala \
bidiriterator.vala \
readonlylist.vala \
readonlymap.vala \
readonlyset.vala \
+ readonlysortedmap.vala \
readonlysortedset.vala \
set.vala \
sortedmap.vala \
* {@inheritDoc}
*/
public abstract SortedSet<K> ascending_keys { owned get; }
+
/**
* {@inheritDoc}
*/
public abstract SortedSet<Map.Entry<K,V>> ascending_entries { owned get; }
+
/**
* {@inheritDoc}
*/
}
}
- private Map<K,V> _map;
+ protected Map<K,V> _map;
/**
* Constructs a read-only map that mirrors the content of the specified map.
--- /dev/null
+/* readonlysortedmap.vala
+ *
+ * Copyright (C) 2009-2011 Maciej Piechotka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Maciej Piechotka <uzytkownik2@gmail.com>
+ */
+
+/**
+ * Read-only view for {@link SortedMap} collections.
+ *
+ * This class decorates any class which implements the {@link SortedMap} interface
+ * by making it read only. Any method which normally modify data will throw an
+ * error.
+ *
+ * @see SortedMap
+ */
+internal class Gee.ReadOnlySortedMap<K,V> : ReadOnlyMap<K,V>, SortedMap<K,V> {
+ /**
+ * Constructs a read-only map that mirrors the content of the specified map.
+ *
+ * @param map the map to decorate.
+ */
+ public ReadOnlySortedMap (Map<K,V> map) {
+ base (map);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SortedMap<K,V> head_map (K before) {
+ return (_map as SortedMap<K,V>).head_map (before).read_only_view;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SortedMap<K,V> tail_map (K after) {
+ return (_map as SortedMap<K,V>).tail_map (after).read_only_view;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SortedMap<K,V> sub_map (K from, K to) {
+ return (_map as SortedMap<K,V>).sub_map (from, to).read_only_view;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SortedSet<K> ascending_keys {
+ owned get {
+ return (_map as SortedMap<K,V>).ascending_keys.read_only_view;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SortedSet<Map.Entry<K,V>> ascending_entries {
+ owned get {
+ return (_map as SortedMap<K,V>).ascending_entries.read_only_view;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Gee.BidirMapIterator<K,V> bidir_map_iterator () {
+ return new BidirMapIterator<K,V> ((_map as SortedMap<K,V>).bidir_map_iterator ());
+ }
+
+ protected class BidirMapIterator<K,V> : Gee.ReadOnlyMap.MapIterator<K,V>, Gee.BidirMapIterator<K,V> {
+ public BidirMapIterator (Gee.BidirMapIterator<K,V> iterator) {
+ base (iterator);
+ }
+
+ public bool first () {
+ return (_iter as Gee.BidirMapIterator<K,V>).first ();
+ }
+
+ public bool previous () {
+ return (_iter as Gee.BidirMapIterator<K,V>).previous ();
+ }
+
+ public bool has_previous () {
+ return (_iter as Gee.BidirMapIterator<K,V>).has_previous ();
+ }
+
+ public bool last () {
+ return (_iter as Gee.BidirMapIterator<K,V>).last ();
+ }
+ }
+}
+
* @return a bi-directional map iterator
*/
public abstract BidirMapIterator<K,V> bidir_map_iterator ();
+
+ /**
+ * The read-only view this map.
+ */
+ public new abstract SortedMap<K,V> read_only_view { owned get; }
+
+ /**
+ * Returns an immutable empty map.
+ *
+ * @return an immutable empty map
+ */
+ public static Map<K,V> empty<K,V> () {
+ return new TreeMap<K,V> ().read_only_view;
+ }
}
*
* @see HashMap
*/
-public class Gee.TreeMap<K,V> : Gee.AbstractMap<K,V>, SortedMap<K,V> {
+public class Gee.TreeMap<K,V> : Gee.AbstractSortedMap<K,V> {
/**
* {@inheritDoc}
*/
/**
* {@inheritDoc}
*/
- public SortedMap<K,V> head_map (K before) {
+ public override SortedMap<K,V> head_map (K before) {
return new SubMap<K,V> (this, new Range<K,V>.head (this, before));
}
/**
* {@inheritDoc}
*/
- public SortedMap<K,V> tail_map (K after) {
+ public override SortedMap<K,V> tail_map (K after) {
return new SubMap<K,V> (this, new Range<K,V>.tail (this, after));
}
/**
* {@inheritDoc}
*/
- public SortedMap<K,V> sub_map (K after, K before) {
+ public override SortedMap<K,V> sub_map (K after, K before) {
return new SubMap<K,V> (this, new Range<K,V> (this, after, before));
}
/**
* {@inheritDoc}
*/
- public SortedSet<K> ascending_keys {
+ public override SortedSet<K> ascending_keys {
owned get {
var keys = _keys;
if (_keys == null) {
/**
* @inheritDoc
*/
- public SortedSet<Map.Entry<K,V>> ascending_entries {
+ public override SortedSet<Map.Entry<K,V>> ascending_entries {
owned get {
var entries = _entries;
if (_entries == null) {
/**
* @inheritDoc
*/
- public Gee.BidirMapIterator<K,V> bidir_map_iterator () {
+ public override Gee.BidirMapIterator<K,V> bidir_map_iterator () {
return new MapIterator<K,V> (this);
}
BOUNDED
}
- private class SubMap<K,V> : AbstractMap<K,V>, SortedMap<K,V> {
+ private class SubMap<K,V> : AbstractSortedMap<K,V> {
public override int size { get { return keys.size; } }
public override bool is_empty { get { return keys.is_empty; } }
return new SubMapIterator<K,V> (map, range);
}
- public BidirMapIterator<K,V> bidir_map_iterator () {
+ public override BidirMapIterator<K,V> bidir_map_iterator () {
return new SubMapIterator<K,V> (map, range);
}
- public SortedMap<K,V> head_map (K before) {
+ public override SortedMap<K,V> head_map (K before) {
return new SubMap<K,V> (map, range.cut_tail (before));
}
- public SortedMap<K,V> tail_map (K after) {
+ public override SortedMap<K,V> tail_map (K after) {
return new SubMap<K,V> (map, range.cut_head (after));
}
- public SortedMap<K,V> sub_map (K after, K before) {
+ public override SortedMap<K,V> sub_map (K after, K before) {
return new SubMap<K,V> (map, range.cut (after, before));
}
- public SortedSet<K> ascending_keys {
+ public override SortedSet<K> ascending_keys {
owned get {
var keys = _keys;
if (_keys == null) {
}
}
- public SortedSet<K> ascending_entries {
+ public override SortedSet<K> ascending_entries {
owned get {
var entries = _entries;
if (_entries == null) {