001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.modeshape.schematic.document; 017 018import java.io.Serializable; 019import org.modeshape.schematic.annotation.Immutable; 020 021/** 022 * A {@link Bson.Type#SYMBOL symbol} value for use within a {@link Document BSON Object}. 023 * 024 * @author Randall Hauch <rhauch@redhat.com> (C) 2011 Red Hat Inc. 025 */ 026@Immutable 027public final class Symbol implements Serializable { 028 029 private static final long serialVersionUID = 1L; 030 031 private final String symbol; 032 033 public Symbol( String symbol ) { 034 this.symbol = symbol; 035 assert this.symbol != null; 036 } 037 038 public String getSymbol() { 039 return symbol; 040 } 041 042 @Override 043 public int hashCode() { 044 return symbol.hashCode(); 045 } 046 047 @Override 048 public boolean equals( Object obj ) { 049 if (obj == this) return true; 050 if (obj instanceof Symbol) { 051 Symbol that = (Symbol)obj; 052 return this.getSymbol().equals(that.getSymbol()); 053 } 054 if (obj instanceof String) { 055 String that = (String)obj; 056 return that.equals(this.getSymbol()); 057 } 058 return false; 059 } 060 061 @Override 062 public String toString() { 063 return symbol; 064 } 065}