<commit_before>/*
 * Copyright 2016 PantherCode
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.panthercode.arctic.core.repository;

import org.panthercode.arctic.core.arguments.ArgumentUtils;
import org.panthercode.arctic.core.helper.identity.Identifiable;
import org.panthercode.arctic.core.helper.identity.Identity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
public class DefaultRepository<T extends Identifiable> implements Repository<T> {
    /**
     *
     */
    private final Identity identity;

    /**
     *
     */
    private Map<String, T> map = new HashMap<>();

    /**
     * @param identity
     */
    public DefaultRepository(Identity identity) {
        ArgumentUtils.assertNotNull(identity, "identity");

        this.identity = identity;
    }

    /**
     * @return
     */
    @Override
    public Identity identity() {
        return this.identity.clone();
    }

    /**
     * @param element
     */
    @Override
    public synchronized void store(T element) {
        if (element != null) {
            if (element.identity() != null) {
                this.map.put(element.identity().getName(), element);
            }
        }
    }

    /**
     * @param key
     */
    @Override
    public synchronized void delete(String key) {
        if (key != null) {
            this.map.remove(key);
        }
    }

    /**
     * @param key
     * @return
     */
    @Override
    public boolean contains(String key) {
        return this.map.containsKey(key);
    }

    /**
     * @param key
     * @return
     */
    @Override
    public T get(String key) {
        return this.map.get(key);
    }

    /**
     *
     */
    @Override
    public void clear() {
        this.map.clear();
    }

    /**
     *
     */
    @Override
    public List<T> elements() {
        return new ArrayList<>(this.map.values());
    }

    /**
     * @return
     */
    @Override
    public Map<String, T> asMap() {
        return new HashMap<>(this.map);
    }
}<commit_msg>add documentation to DefaultRepository class<commit_after>/*
 * Copyright 2016 PantherCode
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.panthercode.arctic.core.repository;

import org.panthercode.arctic.core.arguments.ArgumentUtils;
import org.panthercode.arctic.core.helper.identity.Identifiable;
import org.panthercode.arctic.core.helper.identity.Identity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Concrete implementation of Interface 'Repository' to store objects.
 */
public class DefaultRepository<T extends Identifiable> implements Repository<T> {
    /**
     * The identity the object is associated with.
     */
    private final Identity identity;

    /**
     * map to store objects
     */
    private Map<String, T> map = new HashMap<>();

    /**
     * @param identity
     */
    public DefaultRepository(Identity identity) {
        ArgumentUtils.assertNotNull(identity, "identity");

        this.identity = identity;
    }

    /**
     * @return
     */
    @Override
    public Identity identity() {
        return this.identity.clone();
    }

    /**
     * Adds a new element to repository.
     *
     * @param element element to add
     */
    @Override
    public synchronized void store(T element) {
        if (element != null) {
            if (element.identity() != null) {
                this.map.put(element.identity().getName(), element);
            }
        }
    }

    /**
     * Removes an element from repository.
     *
     * @param key element to remove
     */
    @Override
    public synchronized void delete(String key) {
        if (key != null) {
            this.map.remove(key);
        }
    }

    /**
     * Checks whether the repository contains an element with given name or not.
     *
     * @param key name of module
     * @return Returns <tt>true</tt> if repository contains the element; Otherwise <tt>false</tt>.
     */
    @Override
    public boolean contains(String key) {
        return this.map.containsKey(key);
    }

    /**
     * Returns an element from repository.
     *
     * @param key name of element
     * @return Returns the element if repository contains the object; Otherwise <tt>null</tt>.
     */
    @Override
    public T get(String key) {
        return this.map.get(key);
    }

    /**
     * Removes all elements from repository.
     */
    @Override
    public void clear() {
        this.map.clear();
    }

    /**
     * Returns a collection with all elements stored in this object.
     *
     * @return Returns a collection with all elements stored in this object.
     */
    @Override
    public List<T> elements() {
        return new ArrayList<>(this.map.values());
    }

    /**
     * Returns a map with all elements stored in this object.
     *
     * @return Returns a collection with all elements stored in this object.
     */
    @Override
    public Map<String, T> asMap() {
        return new HashMap<>(this.map);
    }
}
{'fraction_non_alphanumeric': 0.10908201532691994, 'fraction_numerical': 0.0026088374368172184, 'mean_word_length': 2.267980820458178, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6205111', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1671, 'n_words': 528}