/*
 * 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);
    }
}

@@ -933,16 +933,84 @@
 %0A%0A/**%0A *
+ Concrete implementation of Interface 'Repository' to store objects.
 %0A */%0Apub
@@ -1094,32 +1094,76 @@
 %7B%0A    /**%0A     *
+ The identity the object is associated with.
 %0A     */%0A    pri
@@ -1199,32 +1199,53 @@
 %0A%0A    /**%0A     *
+ map to store objects
 %0A     */%0A    pri
@@ -1620,22 +1620,85 @@
   * 
-@param element
+Adds a new element to repository.%0A     *%0A     * @param element element to add
 %0A   
@@ -1952,34 +1952,102 @@
  /**%0A     * 
-@param key
+Removes an element from repository.%0A     *%0A     * @param key element to remove
 %0A     */%0A   
@@ -2204,187 +2204,520 @@
   * 
-@param key%0A     * @return%0A     */%0A    @Override%0A    public boolean contains(String key) %7B%0A        return this.map.containsKey(key);%0A    %7D%0A%0A    /**%0A     * @param key%0A     * @return
+Checks whether the repository contains an element with given name or not.%0A     *%0A     * @param key name of module%0A     * @return Returns %3Ctt%3Etrue%3C/tt%3E if repository contains the element; Otherwise %3Ctt%3Efalse%3C/tt%3E.%0A     */%0A    @Override%0A    public boolean contains(String key) %7B%0A        return this.map.containsKey(key);%0A    %7D%0A%0A    /**%0A     * Returns an element from repository.%0A     *%0A     * @param key name of element%0A     * @return Returns the element if repository contains the object; Otherwise %3Ctt%3Enull%3C/tt%3E.
 %0A   
@@ -2813,32 +2813,70 @@
 %0A%0A    /**%0A     *
+ Removes all elements from repository.
 %0A     */%0A    @Ov
@@ -2959,143 +2959,420 @@
    *
-%0A     */%0A    @Override%0A    public List%3CT%3E elements() %7B%0A        return new ArrayList%3C%3E(this.map.values());%0A    %7D%0A%0A    /**%0A     * @return
+ Returns a collection with all elements stored in this object.%0A     *%0A     * @return Returns a collection with all elements stored in this object.%0A     */%0A    @Override%0A    public List%3CT%3E elements() %7B%0A        return new ArrayList%3C%3E(this.map.values());%0A    %7D%0A%0A    /**%0A     * Returns a map with all elements stored in this object.%0A     *%0A     * @return Returns a collection with all elements stored in this object.
 %0A   

add documentation to DefaultRepository class