001: //$Id: SimpleTypeSafeEnum.java 131 2005-04-06 22:33:47Z jg_hamburg $
002: /********************************************************************************
003: * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
004: * Copyright (c) 2004, Joerg and Kai Gellien
005: * All rights reserved.
006: *
007: * The Software is provided under the terms of the Common Public License 1.0
008: * as provided with the distribution of DDTUnit in the file cpl-v10.html.
009: * Redistribution and use in source and binary forms, with or without
010: * modification, are permitted provided that the following conditions
011: * are met:
012: *
013: * + Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * + Redistributions in binary form must reproduce the above
017: * copyright notice, this list of conditions and the following
018: * disclaimer in the documentation and/or other materials provided
019: * with the distribution.
020: *
021: * + Neither the name of the authors or DDTUnit, nor the
022: * names of its contributors may be used to endorse or promote
023: * products derived from this software without specific prior
024: * written permission.
025: *
026: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
027: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
028: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
029: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
030: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
031: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
032: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
033: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
036: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037: ********************************************************************************/package junitx.ddtunit.resources;
038:
039: /**
040: * Class represents a typesafe enumeration class example for test purposes.
041: *
042: * @author jg
043: */
044: public class SimpleTypeSafeEnum {
045: private String text;
046:
047: public final static SimpleTypeSafeEnum FIRST_ENUM = new SimpleTypeSafeEnum(
048: "first");
049:
050: public final static SimpleTypeSafeEnum SECOND_ENUM = new SimpleTypeSafeEnum(
051: "second");
052:
053: public final static SimpleTypeSafeEnum THIRD_ENUM = new SimpleTypeSafeEnum(
054: "third");
055:
056: private SimpleTypeSafeEnum() {
057: // no special init
058: }
059:
060: private SimpleTypeSafeEnum(String text) {
061: this .text = text;
062: }
063:
064: /**
065: * Returns <code>true</code> if this <code>SimpleTypeSafeEnum</code> is
066: * the same as the o argument.
067: *
068: * @return <code>true</code> if this <code>SimpleTypeSafeEnum</code> is
069: * the same as the o argument.
070: */
071: public boolean equals(Object o) {
072: if (this == o) {
073: return true;
074: }
075: if (o == null) {
076: return false;
077: }
078: if (o.getClass() != getClass()) {
079: return false;
080: }
081: SimpleTypeSafeEnum castedObj = (SimpleTypeSafeEnum) o;
082: return ((this .text == null ? castedObj.text == null : this .text
083: .equals(castedObj.text)));
084: }
085:
086: /**
087: * Override hashCode.
088: *
089: * @return the Objects hashcode.
090: */
091: public int hashCode() {
092: int hashCode = 1;
093: hashCode = 31 * hashCode + (text == null ? 0 : text.hashCode());
094: return hashCode;
095: }
096:
097: public String toString() {
098: StringBuffer buffer = new StringBuffer();
099: buffer.append("SimpleTypeSafeEnum: ");
100: buffer.append(text);
101: return buffer.toString();
102: }
103: }
|