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, 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.ade.configuration.formatters; 029 030import java.util.Objects; 031 032import org.apache.commons.lang3.builder.HashCodeBuilder; 033 034/** 035 * A pair consisting of the include name of a setting definition and the formatter key (possibly null) for which the setting should be used, 036 * for use as a map key in a map of setting definitions. 037 * 038 * <p> 039 * Shared settings can either be defined generally, or just for a specific list of formatter keys in a setting definition file. In the first case, 040 * this corresponds to a single map key with the formatter key set to null, in the second case to a set of map keys with the same include name but 041 * different formatter keys pointing to the same setting definition data. 042 */ 043public class CmsSharedSettingKey { 044 045 /** The formatter key (may be null). */ 046 private String m_formatterKey; 047 048 /** The stored hash code. */ 049 private int m_hashCode; 050 051 /** The include name of a setting definition. */ 052 private String m_name; 053 054 /** 055 * Creates a new instance. 056 * 057 * @param name the include name of the setting definition 058 * 059 * @param formatterKey the formatter key (may be null) 060 */ 061 public CmsSharedSettingKey(String name, String formatterKey) { 062 063 m_name = name; 064 m_formatterKey = formatterKey; 065 HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(); 066 m_hashCode = hashCodeBuilder.append(name).append(formatterKey).toHashCode(); 067 } 068 069 /** 070 * @see java.lang.Object#equals(java.lang.Object) 071 */ 072 @Override 073 public boolean equals(Object obj) { 074 075 if (!(obj instanceof CmsSharedSettingKey)) { 076 return false; 077 } 078 CmsSharedSettingKey other = (CmsSharedSettingKey)obj; 079 return Objects.equals(this.m_name, other.m_name) && Objects.equals(this.m_formatterKey, other.m_formatterKey); 080 } 081 082 /** 083 * @see java.lang.Object#hashCode() 084 */ 085 @Override 086 public int hashCode() { 087 088 return m_hashCode; 089 090 } 091 092 /** 093 * @see java.lang.Object#toString() 094 */ 095 @Override 096 public String toString() { 097 098 return "(" + m_name + "," + m_formatterKey + ")"; 099 100 } 101 102}