VCollections.src.org.violetlib.collections.impl.WeakMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vcollections Show documentation
Show all versions of vcollections Show documentation
Java Immutable Collections
The newest version!
/*
* Copyright (c) 2023 Alan Snyder.
* All rights reserved.
*
* You may not use, copy or modify this file, except in compliance with the license agreement. For details see
* accompanying license terms.
*/
package org.violetlib.collections.impl;
import java.util.Map;
import java.util.WeakHashMap;
import org.violetlib.collections.Binding;
import org.violetlib.collections.IIterator;
import org.violetlib.collections.IMap;
import org.violetlib.collections.ISet;
import org.violetlib.util.Extensions;
import org.violetlib.util.VObjects;
import org.jetbrains.annotations.*;
import org.violetlib.annotations.Immutable;
/**
A simple implementation of an immutable map using weak references for the keys. Null keys and values are not
permitted.
*/
public @Immutable class WeakMap
implements IMap
{
public static @NotNull WeakMap empty()
{
return (WeakMap) EMPTY;
}
public static @NotNull WeakMap from(@NotNull Map extends K,? extends V> map)
{
return new WeakMap<>(map);
}
private static final @NotNull WeakMap