001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.settings;
016    
017    import java.util.Collection;
018    import java.util.HashMap;
019    import java.util.HashSet;
020    import java.util.Map;
021    
022    /**
023     * @author Iv??n Zaera
024     */
025    public class MemorySettings extends BaseModifiableSettings {
026    
027            public MemorySettings() {
028            }
029    
030            public MemorySettings(Settings parentSettings) {
031                    super(parentSettings);
032            }
033    
034            @Override
035            public Collection<String> getModifiedKeys() {
036                    return new HashSet<>(_map.keySet());
037            }
038    
039            @Override
040            public void reset(String key) {
041                    _map.remove(key);
042            }
043    
044            @Override
045            public ModifiableSettings setValue(String key, String value) {
046                    _map.put(key, new String[] { value });
047    
048                    return this;
049            }
050    
051            @Override
052            public ModifiableSettings setValues(String key, String[] values) {
053                    _map.put(key, values);
054    
055                    return this;
056            }
057    
058            @Override
059            public void store() {
060            }
061    
062            @Override
063            protected String doGetValue(String key) {
064                    String[] values = doGetValues(key);
065    
066                    if (values == null) {
067                            return null;
068                    }
069    
070                    return values[0];
071            }
072    
073            @Override
074            protected String[] doGetValues(String key) {
075                    return _map.get(key);
076            }
077    
078            private final Map<String, String[]> _map = new HashMap<>();
079    
080    }