package com.atlassian.bitbucket.repository;

import com.google.common.collect.ImmutableMap;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.Map;

/**
 * A simple implementation of {@link MetadataMap} which is backed by a map
 */
public class SimpleMetadataMap implements MetadataMap {

    private final Map<String, Object> delegate;

    public SimpleMetadataMap() {
        this.delegate = Collections.emptyMap();
    }

    public SimpleMetadataMap(Map<String, ?> delegate) {
        this.delegate = ImmutableMap.copyOf(delegate);
    }

    @Override
    @Nonnull
    public Map<String, Object> asMap() {
        return delegate;
    }

    @Override
    public boolean contains(@Nonnull String completeModuleKey) {
        return delegate.containsKey(completeModuleKey);
    }

    @Override
    public Object get(@Nonnull String completeModuleKey) {
        return delegate.get(completeModuleKey);
    }

    @Override
    public String toString() {
        return delegate.toString();
    }
}
