001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2012-2012 Pentaho and others 008// All Rights Reserved. 009*/ 010package mondrian.util; 011 012/** 013 * Type-safe value that contains an immutable string. Two instances are 014 * the same if they have identical type and contain equal strings. 015 */ 016public abstract class StringKey { 017 private String value; 018 019 /** Creates a StringKey. */ 020 public StringKey(String value) { 021 assert value != null; 022 this.value = value; 023 } 024 025 @Override 026 public String toString() { 027 return value; 028 } 029 030 @Override 031 public int hashCode() { 032 return value.hashCode(); 033 } 034 035 @Override 036 public boolean equals(Object obj) { 037 if (obj == this) { 038 return true; 039 } 040 // Class must be identical (different subclasses of StringHolder not 041 // OK). 042 return obj.getClass() == getClass() 043 && value.equals(((StringKey) obj).value); 044 } 045} 046 047// End StringKey.java