> For the complete documentation index, see [llms.txt](https://y2kot.gitbook.io/untitled/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://y2kot.gitbook.io/untitled/patterns/structural-patterns/proxy/realizacii-na-kotlin.md).

# Реализации на Kotlin

## Общая реализация на языке Kotlin

{% tabs %}
{% tab title="HashMapProxy" %}
{% code fullWidth="true" %}

```kotlin
class HashMapProxy<K, V>(
    private val hashMap: MutableMap<K, V>
) : MutableMap<K, V> by hashMap {
    override fun get(key: K): V? {
        val result = hashMap[key]
        if (result == null)
            println("No value under this key found.")
        return result
    }

    override fun put(key: K, value: V): V? {
        val result = hashMap.put(key, value)
        if (result == null)
            println("Value successfully added. No previous values under this key.")
        return result
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% code lineNumbers="true" fullWidth="true" %}

```kotlin
private const val TEST_KEY = "Zero"
private const val TEST_EXCEPTION_KEY = "One"
private const val EXCEPTION_DESCRIPTION = "No such key or value under this key"
private const val TEST_VALUE = 56

fun main() {
    val hashMap = mutableMapOf<String, Int>()
    val proxy: MutableMap<String, Int> = HashMapProxy(hashMap)

    println("Is has map empty: ${proxy.isEmpty()}")
    proxy.put(TEST_KEY, TEST_VALUE)

    try {
        println("Trying to get value: ${proxy.get(TEST_EXCEPTION_KEY)}")
    } catch (e: NullPointerException) {
        println(EXCEPTION_DESCRIPTION)
    }

    println("Is hash map contains key = ${TEST_KEY} : ${proxy.containsKey(TEST_KEY)}")
    println("Is hash map contains value = $TEST_VALUE : ${proxy.containsValue(TEST_VALUE)}")
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://y2kot.gitbook.io/untitled/patterns/structural-patterns/proxy/realizacii-na-kotlin.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
