Make Exported just be SquirrelJMEVendorApi.
[SquirrelJME.git] / modules / cldc-compact / src / main / java / cc / squirreljme / runtime / cldc / util / MapKeySetView.java
blob60bc65384df0fb6247910f77ac6c4847fe133139
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.runtime.cldc.util;
12 import java.util.AbstractSet;
13 import java.util.Iterator;
14 import java.util.Map;
16 /**
17 * This is the key set for an abstract map.
19 * @param <K> The key type.
20 * @param <V> The value stored.
21 * @since 2018/10/10
23 public final class MapKeySetView<K, V>
24 extends AbstractSet<K>
26 /** The backing map. */
27 protected final Map<K, V> map;
29 /** Is adding allowed? */
30 protected final boolean allowAdd;
32 /**
33 * Initializes the set.
35 * @param __map The backing map
36 * @param __allowAdd Is adding allowed in the map?
37 * @throws NullPointerException On null arguments.
38 * @since 2018/11/01
40 public MapKeySetView(Map<K, V> __map, boolean __allowAdd)
41 throws NullPointerException
43 if (__map == null)
44 throw new NullPointerException("NARG");
46 this.map = __map;
47 this.allowAdd = __allowAdd;
50 /**
51 * {@inheritDoc}
52 * @since 2021/11/28
54 @Override
55 public boolean add(K __k)
57 if (!this.allowAdd)
58 throw new UnsupportedOperationException("RORO");
60 // Store a null value here
61 Map<K, V> map = this.map;
62 boolean contained = map.containsKey(__k);
63 map.put(__k, null);
65 // Only if it is actually contained here
66 return !contained;
69 /**
70 * {@inheritDoc}
71 * @since 2018/11/01
73 @SuppressWarnings("SuspiciousMethodCalls")
74 @Override
75 public final boolean contains(Object __o)
77 return this.map.containsKey(__o);
80 /**
81 * {@inheritDoc}
82 * @since 2018/10/10
84 @Override
85 public final Iterator<K> iterator()
87 return new __MapKeySetIterator__<K, V>(this.map.entrySet().iterator());
90 /**
91 * {@inheritDoc}
92 * @since 2021/11/28
94 @SuppressWarnings("SuspiciousMethodCalls")
95 @Override
96 public boolean remove(Object __o)
98 // Remove the item from the map, but check to ensure it has it before
99 // that is actually done
100 Map<K, V> map = this.map;
101 boolean hasKey = map.containsKey(__o);
102 map.remove(__o);
104 return hasKey;
108 * {@inheritDoc}
109 * @since 2018/10/10
111 @Override
112 public final int size()
114 return this.map.size();