001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.comparison;
029
030import java.util.Locale;
031
032/**
033 * Comparison of two xml page elements.<p>
034 */
035public class CmsElementComparison extends CmsAttributeComparison implements Comparable<CmsElementComparison> {
036
037    /** The element locale.<p> */
038    private Locale m_locale;
039
040    /**
041     * Creates a new element comparison.<p>
042     *
043     * @param locale the locale of the comparison
044     * @param name the name of the element
045     */
046    public CmsElementComparison(Locale locale, String name) {
047
048        m_locale = locale;
049        setName(name);
050    }
051
052    /**
053     * @see java.lang.Comparable#compareTo(java.lang.Object)
054     */
055    @Override
056    public int compareTo(CmsElementComparison diffItem) {
057
058        if (this == diffItem) {
059            return 0;
060        }
061
062        // first compare by name
063        if (getName().compareTo(diffItem.getName()) != 0) {
064            return getName().compareTo(diffItem.getName());
065        }
066        // then by locale
067        return m_locale.toString().compareTo(diffItem.getLocale().toString());
068    }
069
070    /**
071     *
072     * @see java.lang.Object#equals(java.lang.Object)
073     */
074    @Override
075    public boolean equals(Object o) {
076
077        if (this == o) {
078            return true;
079        }
080        if (!(o instanceof CmsElementComparison)) {
081            return false;
082        }
083        CmsElementComparison diffItem = (CmsElementComparison)o;
084        return getName().equals(diffItem.getName()) && m_locale.equals(diffItem.getLocale());
085    }
086
087    /**
088     * Returns the locale.<p>
089     *
090     * @return the locale
091     */
092    public Locale getLocale() {
093
094        return m_locale;
095    }
096
097    /**
098     *
099     * @see java.lang.Object#hashCode()
100     */
101    @Override
102    public int hashCode() {
103
104        return m_locale.hashCode() + getName().hashCode();
105    }
106
107    /**
108     * Sets the locale.<p>
109     *
110     * @param locale the locale to set
111     */
112    public void setLocale(Locale locale) {
113
114        m_locale = locale;
115    }
116
117}