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.portlet.dynamicdatamapping;
016    
017    import com.liferay.portal.kernel.util.LocaleUtil;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import java.util.HashMap;
021    import java.util.Locale;
022    import java.util.Map;
023    import java.util.Set;
024    
025    /**
026     * @author Marcellus Tavares
027     */
028    public class UnlocalizedValue implements Value {
029    
030            public UnlocalizedValue(String value) {
031                    _values.put(LocaleUtil.ROOT, value);
032            }
033    
034            public UnlocalizedValue(UnlocalizedValue unlocalizedValue) {
035                    _values.put(
036                            LocaleUtil.ROOT, unlocalizedValue.getString(LocaleUtil.ROOT));
037            }
038    
039            @Override
040            public void addString(Locale locale, String value) {
041                    _values.put(LocaleUtil.ROOT, value);
042            }
043    
044            @Override
045            public boolean equals(Object obj) {
046                    if (this == obj) {
047                            return true;
048                    }
049    
050                    if (!(obj instanceof UnlocalizedValue)) {
051                            return false;
052                    }
053    
054                    UnlocalizedValue unlocalizedValue = (UnlocalizedValue)obj;
055    
056                    if (Validator.equals(_values, unlocalizedValue._values)) {
057                            return true;
058                    }
059    
060                    return false;
061            }
062    
063            @Override
064            public Set<Locale> getAvailableLocales() {
065                    return _values.keySet();
066            }
067    
068            @Override
069            public Locale getDefaultLocale() {
070                    return LocaleUtil.ROOT;
071            }
072    
073            @Override
074            public String getString(Locale locale) {
075                    return _values.get(LocaleUtil.ROOT);
076            }
077    
078            @Override
079            public Map<Locale, String> getValues() {
080                    return _values;
081            }
082    
083            @Override
084            public int hashCode() {
085                    return _values.hashCode();
086            }
087    
088            @Override
089            public boolean isLocalized() {
090                    return false;
091            }
092    
093            @Override
094            public void setDefaultLocale(Locale defaultLocale) {
095                    throw new UnsupportedOperationException();
096            }
097    
098            private final Map<Locale, String> _values = new HashMap<>();
099    
100    }