package ru.dbotthepony.mc.otm.core.util

import java.lang.ref.ReferenceQueue
import java.lang.ref.WeakReference

/**
 * [WeakReference], but with [hashCode] overridden with hash of referent object
 */
@Suppress("EqualsOrHashCode")
class HashedWeakReference<T : Any> : WeakReference<T> {
	constructor(value: T) : super(value) {
		hash = value.hashCode()
	}

	constructor(value: T, queue: ReferenceQueue<T>) : super(value, queue) {
		hash = value.hashCode()
	}

	private val hash: Int

	override fun hashCode(): Int {
		return hash
	}

	override fun toString(): String {
		return "HashedWeakReference[hash=$hash]"
	}
}
