1 package org.opentrafficsim.core.perception.collections;
2
3 import java.util.Collections;
4 import java.util.NavigableMap;
5 import java.util.NavigableSet;
6
7 import org.opentrafficsim.core.perception.HistoryManager;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public abstract class AbstractHistoricalNavigableMap<K, V, M extends NavigableMap<K, V>>
27 extends AbstractHistoricalSortedMap<K, V, M> implements HistoricalNavigableMap<K, V>
28 {
29
30
31
32
33
34
35 protected AbstractHistoricalNavigableMap(final HistoryManager historyManager, final M map)
36 {
37 super(historyManager, map);
38 }
39
40
41
42
43 @Override
44 public Entry<K, V> pollFirstEntry()
45 {
46 if (getMap().isEmpty())
47 {
48 return null;
49 }
50 Entry<K, V> entry = Collections.unmodifiableNavigableMap(getMap()).firstEntry();
51 remove(entry.getKey());
52 return entry;
53 }
54
55
56 @Override
57 public Entry<K, V> pollLastEntry()
58 {
59 if (getMap().isEmpty())
60 {
61 return null;
62 }
63 Entry<K, V> entry = Collections.unmodifiableNavigableMap(getMap()).lastEntry();
64 remove(entry.getKey());
65 return entry;
66 }
67
68
69
70
71 @Override
72 public Entry<K, V> lowerEntry(final K key)
73 {
74 return Collections.unmodifiableNavigableMap(getMap()).lowerEntry(key);
75 }
76
77
78 @Override
79 public K lowerKey(final K key)
80 {
81 return getMap().lowerKey(key);
82 }
83
84
85 @Override
86 public Entry<K, V> floorEntry(final K key)
87 {
88 return Collections.unmodifiableNavigableMap(getMap()).floorEntry(key);
89 }
90
91
92 @Override
93 public K floorKey(final K key)
94 {
95 return getMap().floorKey(key);
96 }
97
98
99 @Override
100 public Entry<K, V> ceilingEntry(final K key)
101 {
102 return Collections.unmodifiableNavigableMap(getMap()).ceilingEntry(key);
103 }
104
105
106 @Override
107 public K ceilingKey(final K key)
108 {
109 return getMap().ceilingKey(key);
110 }
111
112
113 @Override
114 public Entry<K, V> higherEntry(final K key)
115 {
116 return Collections.unmodifiableNavigableMap(getMap()).higherEntry(key);
117 }
118
119
120 @Override
121 public K higherKey(final K key)
122 {
123 return getMap().higherKey(key);
124 }
125
126
127 @Override
128 public Entry<K, V> firstEntry()
129 {
130 return Collections.unmodifiableNavigableMap(getMap()).firstEntry();
131 }
132
133
134 @Override
135 public Entry<K, V> lastEntry()
136 {
137 return Collections.unmodifiableNavigableMap(getMap()).lastEntry();
138 }
139
140
141 @Override
142 public NavigableMap<K, V> descendingMap()
143 {
144 return Collections.unmodifiableNavigableMap(getMap().descendingMap());
145 }
146
147
148 @Override
149 public NavigableSet<K> navigableKeySet()
150 {
151 return Collections.unmodifiableNavigableSet(getMap().navigableKeySet());
152 }
153
154
155 @Override
156 public NavigableSet<K> descendingKeySet()
157 {
158 return Collections.unmodifiableNavigableSet(getMap().descendingKeySet());
159 }
160
161
162 @Override
163 public NavigableMap<K, V> subMap(final K fromKey, final boolean fromInclusive, final K toKey, final boolean toInclusive)
164 {
165 return Collections.unmodifiableNavigableMap(getMap().subMap(fromKey, fromInclusive, toKey, toInclusive));
166 }
167
168
169 @Override
170 public NavigableMap<K, V> headMap(final K toKey, final boolean inclusive)
171 {
172 return Collections.unmodifiableNavigableMap(getMap().headMap(toKey, inclusive));
173 }
174
175
176 @Override
177 public NavigableMap<K, V> tailMap(final K fromKey, final boolean inclusive)
178 {
179 return Collections.unmodifiableNavigableMap(getMap().tailMap(fromKey, inclusive));
180 }
181
182 }