001 /* 002 // $Id: //open/mondrian/src/main/mondrian/olap/OlapElementBase.java#20 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2001-2002 Kana Software, Inc. 007 // Copyright (C) 2001-2007 Julian Hyde and others 008 // All Rights Reserved. 009 // You must accept the terms of that agreement to use this software. 010 // 011 // jhyde, 6 August, 2001 012 */ 013 014 package mondrian.olap; 015 016 import org.apache.log4j.Logger; 017 018 /** 019 * <code>OlapElementBase</code> is an abstract base class for implementations of 020 * {@link OlapElement}. 021 * 022 * @author jhyde 023 * @version $Id: //open/mondrian/src/main/mondrian/olap/OlapElementBase.java#20 $ 024 * @since 6 August, 2001 025 */ 026 public abstract class OlapElementBase 027 implements OlapElement { 028 029 protected String caption = null; 030 031 // cache hash-code because it is often used and elements are immutable 032 private int hash; 033 034 protected OlapElementBase() { 035 } 036 037 protected abstract Logger getLogger(); 038 039 public boolean equals(Object o) { 040 return (o == this) || 041 ((o instanceof OlapElement) && equals((OlapElement) o)); 042 } 043 044 public boolean equals(OlapElement mdxElement) { 045 return mdxElement != null && 046 getClass() == mdxElement.getClass() && 047 getUniqueName().equalsIgnoreCase(mdxElement.getUniqueName()); 048 } 049 050 public int hashCode() { 051 if (hash == 0) { 052 hash = computeHashCode(); 053 } 054 return hash; 055 } 056 057 /** 058 * Computes this object's hash code. Called at most once. 059 * 060 * @return hash code 061 */ 062 protected int computeHashCode() { 063 return (getClass().hashCode() << 8) ^ getUniqueName().hashCode(); 064 } 065 066 public String toString() { 067 return getUniqueName(); 068 } 069 070 public Object clone() { 071 return this; 072 } 073 074 /** 075 * Returns the display name of this catalog element. 076 * If no caption is defined, the name is returned. 077 */ 078 public String getCaption() { 079 if (caption != null) { 080 return caption; 081 } else { 082 return getName(); 083 } 084 } 085 086 /** 087 * Sets the display name of this catalog element. 088 */ 089 public void setCaption(String caption) { 090 this.caption = caption; 091 } 092 } 093 094 // End OlapElementBase.java