package example.domain.services;

import com.google.common.collect.Maps;
import example.domain.Document;
import example.domain.DocumentRepository;
import example.framework.Identity;

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

public class HashMapDocumentRepository implements DocumentRepository {

    private final Map<Identity, Document> repository = Maps.newConcurrentMap();

    public Document get(Identity documentId) {
        Document document = repository.get(documentId);
        if (document == null) {
            document = new Document(documentId);
        }
        return document;
    }

    public void set(Document document) {
        Identity identity = document.getId();
        if (identity.isNew()) {
            throw new IllegalArgumentException("Cannot save document with '" + identity + "' identity");
        }
        repository.put(identity, document);
    }

    public List<Document> getAll() {
        return new ArrayList<Document>(repository.values());
    }
}

@@ -27,16 +27,56 @@
 vices;%0A%0A
+import com.google.common.collect.Lists;%0A
 import c
@@ -220,36 +220,8 @@
 y;%0A%0A
-import java.util.ArrayList;%0A
 impo
@@ -978,20 +978,25 @@
  return 
+Lists.
 new
- 
 ArrayLis
@@ -996,26 +996,16 @@
 rrayList
-%3CDocument%3E
 (reposit

stop angle bracket tax