001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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, please see the
018 * company website: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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.db.storage;
029
030import org.opencms.file.CmsResource;
031import org.opencms.util.CmsUUID;
032
033/**
034 * Cache key for stored content info entries.<p>
035 */
036public final class CmsStoredContentInfoCacheKey {
037
038    /** The content date. */
039    private final long m_dateContent;
040
041    /** The project id. */
042    private final CmsUUID m_projectId;
043
044    /** The resource id. */
045    private final CmsUUID m_resourceId;
046
047    /** The resource version. */
048    private final int m_version;
049
050    /**
051     * Creates a new cache key.<p>
052     *
053     * @param projectId the project id
054     * @param resource the resource
055     */
056    public CmsStoredContentInfoCacheKey(CmsUUID projectId, CmsResource resource) {
057
058        m_projectId = projectId;
059        m_resourceId = resource.getResourceId();
060        m_version = resource.getVersion();
061        m_dateContent = resource.getDateContent();
062    }
063
064    /**
065     * @see java.lang.Object#equals(java.lang.Object)
066     */
067    @Override
068    public boolean equals(Object obj) {
069
070        if (this == obj) {
071            return true;
072        }
073        if (!(obj instanceof CmsStoredContentInfoCacheKey)) {
074            return false;
075        }
076        CmsStoredContentInfoCacheKey other = (CmsStoredContentInfoCacheKey)obj;
077        return m_dateContent == other.m_dateContent
078            && m_version == other.m_version
079            && m_projectId.equals(other.m_projectId)
080            && m_resourceId.equals(other.m_resourceId);
081    }
082
083    /**
084     * @see java.lang.Object#hashCode()
085     */
086    @Override
087    public int hashCode() {
088
089        int result = m_projectId.hashCode();
090        result = (31 * result) + m_resourceId.hashCode();
091        result = (31 * result) + m_version;
092        result = (31 * result) + (int)(m_dateContent ^ (m_dateContent >>> 32));
093        return result;
094    }
095}