Commit f82f6b26 authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Implement LinkedHashMap; Use some common methods.

parent 010bcca7
......@@ -41,6 +41,7 @@ More detailed changes:
be within a 1 ulp range, however the test framework only supports
exact values.
* Added the missing _mimemessage_ file for the MIME file decoding test.
* Refactored the test framework to be easier to maintain.
* Programs and Libraries
* `cldc-compact`
* Added a rehash indicator for the internal `__BucketMap__` so that
......@@ -51,6 +52,7 @@ More detailed changes:
* Implemented `java.io.InputStream`.
* Implemented `java.util.EventObject`.
* Implemented `java.util.Hashtable`.
* Implemented `java.util.LinkedHashMap`.
* Implemented `java.util.LinkedList`.
* `demo-hello`
* Made the system properties array `final`.
......
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package util;
import net.multiphasicapps.tac.TestRunnable;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Tests to ensure that the eldest entry removal works correctly.
*
* @since 2019/05/09
*/
public class TestLinkedHashMapEldest
extends TestRunnable
{
/** Maximum entries in the map. */
public static final int MAX_ENTRIES = 10;
/**
* {@inheritDoc}
* @since 2019/05/09
*/
@Override
public void test()
{
Map<Integer, String> map = new EldestMap();
// Add a bunch of values
for (int i = 0; i < MAX_ENTRIES * 5; i++)
map.put(i, "Value" + i);
// Array should be in same order!
this.secondary("ordkeys", map.keySet().toArray());
this.secondary("ordvals", map.values().toArray());
}
/**
* Map which overrides the eldest entry check.
*
* @since 2109/05/09
*/
public final class EldestMap
extends LinkedHashMap<Integer, String>
{
/** Eldest order. */
private int _order;
/**
* {@inheritDoc}
* @since 2019/05/09
*/
@Override
protected boolean removeEldestEntry(Map.Entry<Integer, String> __e)
{
// Used to make sure the order is correct
int order = this._order++;
TestLinkedHashMapEldest.this.secondary(
"eldest" + order + "key", __e.getKey());
TestLinkedHashMapEldest.this.secondary(
"eldest" + order + "val", __e.getValue());
// This comes from the documentation example which specifies that
// a value should be removed
return this.size() > MAX_ENTRIES;
}
}
}
......@@ -491,7 +491,12 @@ public abstract class AbstractList<E>
if (rmdx < 0)
throw new IllegalStateException("ZZ1k");
throw new todo.TODO();
// Remove this index
this._rmdx = -1;
AbstractList.this.remove(rmdx);
// Set new modification count
this._atmod = AbstractList.this.modCount;
}
/**
......
......@@ -117,18 +117,6 @@ public class ArrayList<E>
this.modCount++;
}
@Override
public boolean addAll(Collection<? extends E> __a)
{
throw new todo.TODO();
}
@Override
public boolean addAll(int __a, Collection<? extends E> __b)
{
throw new todo.TODO();
}
/**
* {@inheritDoc}
* @since 2018/10/29
......@@ -159,12 +147,6 @@ public class ArrayList<E>
return new ArrayList<>(this);
}
@Override
public boolean contains(Object __a)
{
throw new todo.TODO();
}
public void ensureCapacity(int __a)
{
throw new todo.TODO();
......@@ -184,30 +166,6 @@ public class ArrayList<E>
return this._elements[__i];
}
@Override
public int indexOf(Object __a)
{
throw new todo.TODO();
}
@Override
public int lastIndexOf(Object __a)
{
throw new todo.TODO();
}
@Override
public ListIterator<E> listIterator(int __a)
{
throw new todo.TODO();
}
@Override
public ListIterator<E> listIterator()
{
throw new todo.TODO();
}
/**
* {@inheritDoc}
* @since 2018/12/12
......
......@@ -10,60 +10,107 @@
package java.util;
/**
* This is a map which is backed by a hash table except that the iterator
* order is in the order of which elements were added first.
*
* Otherwise this class is exactly the same as {@link HashMap}.
*
* @param <K> The key type.
* @param <V> The value type.
* @see HashMap
* @since 2019/05/09
*/
public class LinkedHashMap<K, V>
extends HashMap<K, V>
implements Map<K, V>
{
public LinkedHashMap(int __a, float __b)
/**
* Initializes the set with the given capacity and load factor.
*
* @param __cap The capacity used.
* @param __load The load factor used.
* @throws IllegalArgumentException If the capacity is negative or the
* load factor is not positive.
* @since 2019/05/09
*/
public LinkedHashMap(int __cap, float __load)
throws IllegalArgumentException
{
super(0, 0);
throw new todo.TODO();
super(__cap, __load);
}
public LinkedHashMap(int __a)
/**
* Initializes the set with the given capacity and the default load factor.
*
* @param __initcap The capacity used.
* @throws IllegalArgumentException If the capacity is negative.
* @since 2019/05/09
*/
public LinkedHashMap(int __initcap)
throws IllegalArgumentException
{
super(0, 0);
throw new todo.TODO();
super(__initcap);
}
/**
* Initializes an empty map.
*
* @since 2019/05/09
*/
public LinkedHashMap()
{
super(0, 0);
throw new todo.TODO();
}
public LinkedHashMap(Map<? extends K, ? extends V> __a)
/**
* Initializes a map which is a copy of the other map.
*
* The default load factor is used and the capacity is set to the
* capacity of the input map.
*
* @param __m The map to copy from.
* @throws NullPointerException On null arguments.
* @since 2019/05/09
*/
public LinkedHashMap(Map<? extends K, ? extends V> __m)
throws NullPointerException
{
super(0, 0);
throw new todo.TODO();
super(__m);
}
/**
* Initializes the set with the given capacity and load factor, but the
* may be ordered based on what is first accessed.
*
* @param __cap The capacity used.
* @param __load The load factor used.
* @param __ao If the iterator should always return the same order for
* accesses.
* @throws IllegalArgumentException If the capacity is negative or the
* load factor is not positive.
* @since 2019/05/09
*/
public LinkedHashMap(int __cap, float __load, boolean __ao)
{
super(__cap, __load, __ao);
}
@Override
public void clear()
/**
* After a {@code put} or {@code putAll} operation this will be called with
* the eldest entry to determine if it should be removed or not. This may
* be used for cache purposes.
*
* The default implementation returns {@code false}.
*
* If the implementation of this method modifies the map then this should
* always return {@code null}.
*
* @param __e The entry being
* @since 2019/05/09
*/
protected boolean removeEldestEntry(Map.Entry<K, V> __e)
{
throw new todo.TODO();
}
@Override
public boolean containsValue(Object __a)
{
throw new todo.TODO();
}
@Override
public V get(Object __a)
{
throw new todo.TODO();
}
protected boolean removeEldestEntry(Map.Entry<K, V> __a)
{
throw new todo.TODO();
return false;
}
}
......@@ -34,6 +34,7 @@ public class LinkedHashSet<E>
* @since 2018/11/01
*/
public LinkedHashSet(int __initcap, float __load)
throws IllegalArgumentException
{
super(__initcap, __load);
}
......@@ -46,6 +47,7 @@ public class LinkedHashSet<E>
* @since 2018/11/01
*/
public LinkedHashSet(int __initcap)
throws IllegalArgumentException
{
super(__initcap);
}
......@@ -61,7 +63,7 @@ public class LinkedHashSet<E>
}
/**
* Initializes a set which is a copy of the other map.
* Initializes a set which is a copy of the other set.
*
* The default load factor is used and the capacity is set to the
* capacity of the input set.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment