summaryrefslogtreecommitdiff
path: root/src/library/scala/runtime/BoxedChar.java
blob: 3e153f199b3d946a3956f09f80ec66cd22cfe068 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2002-2007, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id$


package scala.runtime;


public class BoxedChar extends BoxedNumber
    implements java.io.Serializable
{

    private static final int MinHashed = 0;
    private static final int MaxHashed = 255;
    private static final BoxedChar[] canonical = new BoxedChar[MaxHashed - MinHashed + 1];

    static {
        for (int i = MinHashed; i <= MaxHashed; i++)
            canonical[i - MinHashed] = new BoxedChar((char)i);
    }

    public static BoxedChar box(char value) {
        if (MinHashed <= value && value <= MaxHashed) return canonical[value - MinHashed];
        else return new BoxedChar(value);
    }

    public final char value;

    private BoxedChar(char value) { this.value = value; }

    public byte byteValue() { return (byte)value; }
    public short shortValue() { return (short)value; }
    public char charValue() { return (char)value; }
    public int intValue() { return (int)value; }
    public long longValue() { return (long)value; }
    public float floatValue() { return (float)value; }
    public double doubleValue() { return (double)value; }

    public boolean equals(java.lang.Object other) {
        return other instanceof BoxedNumber &&
            value == ((BoxedNumber) other).charValue();
    }

    public int hashCode() {
        return value;
    }

    public String toString() {
        return String.valueOf(value);
    }

}