[rfc][icedtea-web] TimedHashMap

Omair Majid omajid at redhat.com
Fri May 9 20:52:12 UTC 2014


* Andrew Azores <aazores at redhat.com> [2014-05-09 16:16]:
> +++ b/netx/net/sourceforge/jnlp/util/TimedHashMap.java

> +public class TimedHashMap<K, V> implements Map<K, V> {
>  
> +    private class TimedEntry<T> {

Can you make this class static? Otherwise, every instance of this class
will hold a reference to the parent TimedHashMap instance.

> +    private static final long DEFAULT_TIMEOUT = 10000000000L; // 10 seconds

A slightly easier-to-read version of this is to use the TimeUnit class:

    private static final long DEFAULT_TIMEOUT_NANOS = TimeUnit.SECONDS.toNanos(10);

> +    public TimedHashMap(final long timeout) {

> +    public void setTimeout(final long timeout) {

Please make a note of the unit (either in javadocs or in the parameter
name). Really nice would be using two separate parameters: value (long) and unit
(TimeUnit).

> +            if ((entry.value == null && value == null) || entry.value.equals(value)) {

Objects.equals(entry.value, value) does this check in a smaller amount
of code.

> +    public V remove(final Object key) {
> +        return actualMap.remove(key).value;

Does this throw a NullPointerException if the map is empty or the map
does not contain the key/value?

Thanks,
Omair

-- 
PGP Key: 66484681 (http://pgp.mit.edu/)
Fingerprint = F072 555B 0A17 3957 4E95  0056 F286 F14F 6648 4681


More information about the distro-pkg-dev mailing list