~ubuntu-branches/ubuntu/trusty/libjcommon-java/trusty

« back to all changes in this revision

Viewing changes to source/org/jfree/util/UnitType.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-10-01 14:12:07 UTC
  • mfrom: (1.1.2 upstream) (2.1.2 edgy)
  • Revision ID: james.westby@ubuntu.com-20061001141207-2aipqlhpmn45t3ng
Tags: 1.0.6-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ========================================================================
 
2
 * JCommon : a free general purpose class library for the Java(tm) platform
 
3
 * ========================================================================
 
4
 *
 
5
 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
 
6
 * 
 
7
 * Project Info:  http://www.jfree.org/jcommon/index.html
 
8
 *
 
9
 * This library is free software; you can redistribute it and/or modify it 
 
10
 * under the terms of the GNU Lesser General Public License as published by 
 
11
 * the Free Software Foundation; either version 2.1 of the License, or 
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This library is distributed in the hope that it will be useful, but 
 
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 
16
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 
17
 * License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public
 
20
 * License along with this library; if not, write to the Free Software
 
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 
22
 * USA.  
 
23
 *
 
24
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 
25
 * in the United States and other countries.]
 
26
 * 
 
27
 * -------------
 
28
 * UnitType.java
 
29
 * -------------
 
30
 * (C) Copyright 2004, 2005, by Object Refinery Limited.
 
31
 *
 
32
 * Original Author:  David Gilbert (for Object Refinery Limited);
 
33
 * Contributor(s):   -;
 
34
 *
 
35
 * $Id: UnitType.java,v 1.7 2005/10/18 13:24:19 mungady Exp $
 
36
 *
 
37
 * Changes:
 
38
 * --------
 
39
 * 11-Feb-2004 : Version 1 (DG);
 
40
 * 
 
41
 */
 
42
 
 
43
package org.jfree.util;
 
44
 
 
45
import java.io.ObjectStreamException;
 
46
import java.io.Serializable;
 
47
 
 
48
/**
 
49
 * Used to indicate absolute or relative units.
 
50
 *
 
51
 * @author David Gilbert
 
52
 */
 
53
public final class UnitType implements Serializable {
 
54
 
 
55
    /** For serialization. */
 
56
    private static final long serialVersionUID = 6531925392288519884L;    
 
57
    
 
58
    /** Absolute. */
 
59
    public static final UnitType ABSOLUTE = new UnitType("UnitType.ABSOLUTE");
 
60
 
 
61
    /** Relative. */
 
62
    public static final UnitType RELATIVE = new UnitType("UnitType.RELATIVE");
 
63
 
 
64
    /** The name. */
 
65
    private String name;
 
66
 
 
67
    /**
 
68
     * Private constructor.
 
69
     *
 
70
     * @param name  the name.
 
71
     */
 
72
    private UnitType(final String name) {
 
73
        this.name = name;
 
74
    }
 
75
 
 
76
    /**
 
77
     * Returns a string representing the object.
 
78
     *
 
79
     * @return The string.
 
80
     */
 
81
    public String toString() {
 
82
        return this.name;
 
83
    }
 
84
 
 
85
    /**
 
86
     * Returns <code>true</code> if this object is equal to the specified 
 
87
     * object, and <code>false</code> otherwise.
 
88
     *
 
89
     * @param obj  the other object.
 
90
     *
 
91
     * @return A boolean.
 
92
     */
 
93
    public boolean equals(final Object obj) {
 
94
        if (obj == this) {
 
95
            return true;
 
96
        }
 
97
        if (!(obj instanceof UnitType)) {
 
98
            return false;
 
99
        }
 
100
        final UnitType that = (UnitType) obj;
 
101
        if (!this.name.equals(that.name)) {
 
102
            return false;
 
103
        }
 
104
        return true;
 
105
    }
 
106
 
 
107
    /**
 
108
     * Returns a hash code value for the object.
 
109
     *
 
110
     * @return The hashcode
 
111
     */
 
112
    public int hashCode() {
 
113
        return this.name.hashCode();
 
114
    }
 
115
 
 
116
    /**
 
117
     * Ensures that serialization returns the unique instances.
 
118
     * 
 
119
     * @return The object.
 
120
     * 
 
121
     * @throws ObjectStreamException if there is a problem.
 
122
     */
 
123
    private Object readResolve() throws ObjectStreamException {
 
124
        if (this.equals(UnitType.ABSOLUTE)) {
 
125
            return UnitType.ABSOLUTE;
 
126
        }
 
127
        else if (this.equals(UnitType.RELATIVE)) {
 
128
            return UnitType.RELATIVE;
 
129
        }
 
130
        return null;
 
131
    }
 
132
    
 
133
}