001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.schematic.internal;
017
018import java.io.Serializable;
019import java.util.concurrent.ConcurrentHashMap;
020import java.util.concurrent.ConcurrentMap;
021import org.modeshape.schematic.DocumentLibrary;
022import org.modeshape.schematic.document.Document;
023
024public class InMemoryDocumentLibrary implements DocumentLibrary, Serializable {
025
026    private static final long serialVersionUID = 1L;
027
028    private final String name;
029    private final ConcurrentMap<String, Document> documents = new ConcurrentHashMap<>();
030
031    public InMemoryDocumentLibrary( String name ) {
032        this.name = name;
033    }
034
035    @Override
036    public String getName() {
037        return name;
038    }
039
040    @Override
041    public Document get( String key ) {
042        return documents.get(key);
043    }
044
045    @Override
046    public Document put( String key,
047                         Document document ) {
048        return documents.put(key, document);
049    }
050
051    @Override
052    public Document putIfAbsent( String key,
053                                 Document document ) {
054        return documents.putIfAbsent(key, document);
055    }
056
057    @Override
058    public Document replace( String key,
059                             Document document ) {
060        return documents.replace(key, document);
061    }
062
063    @Override
064    public Document remove( String key ) {
065        return documents.remove(key);
066    }
067}