UnsafeStaticFloatFieldAccessorImpl.java revision 14176:8606d027b2c2
138889Sjdp/*
238889Sjdp * Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
3218822Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4218822Sdim *
5218822Sdim * This code is free software; you can redistribute it and/or modify it
6218822Sdim * under the terms of the GNU General Public License version 2 only, as
7218822Sdim * published by the Free Software Foundation.  Oracle designates this
8218822Sdim * particular file as subject to the "Classpath" exception as provided
938889Sjdp * by Oracle in the LICENSE file that accompanied this code.
1038889Sjdp *
1138889Sjdp * This code is distributed in the hope that it will be useful, but WITHOUT
1238889Sjdp * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1338889Sjdp * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1438889Sjdp * version 2 for more details (a copy is included in the LICENSE file that
1538889Sjdp * accompanied this code).
1638889Sjdp *
1738889Sjdp * You should have received a copy of the GNU General Public License version
1838889Sjdp * 2 along with this work; if not, write to the Free Software Foundation,
1938889Sjdp * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2038889Sjdp *
2138889Sjdp * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2238889Sjdp * or visit www.oracle.com if you need additional information or have any
23218822Sdim * questions.
24218822Sdim */
2538889Sjdp
26218822Sdimpackage jdk.internal.reflect;
27218822Sdim
28218822Sdimimport java.lang.reflect.Field;
29218822Sdim
3038889Sjdpclass UnsafeStaticFloatFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
31218822Sdim    UnsafeStaticFloatFieldAccessorImpl(Field field) {
32218822Sdim        super(field);
33218822Sdim    }
34218822Sdim
35218822Sdim    public Object get(Object obj) throws IllegalArgumentException {
36218822Sdim        return Float.valueOf(getFloat(obj));
37218822Sdim    }
38218822Sdim
39218822Sdim    public boolean getBoolean(Object obj) throws IllegalArgumentException {
40218822Sdim        throw newGetBooleanIllegalArgumentException();
41218822Sdim    }
42218822Sdim
43218822Sdim    public byte getByte(Object obj) throws IllegalArgumentException {
44218822Sdim        throw newGetByteIllegalArgumentException();
45218822Sdim    }
46218822Sdim
47218822Sdim    public char getChar(Object obj) throws IllegalArgumentException {
48218822Sdim        throw newGetCharIllegalArgumentException();
49218822Sdim    }
50218822Sdim
51218822Sdim    public short getShort(Object obj) throws IllegalArgumentException {
52218822Sdim        throw newGetShortIllegalArgumentException();
53218822Sdim    }
54218822Sdim
55218822Sdim    public int getInt(Object obj) throws IllegalArgumentException {
56218822Sdim        throw newGetIntIllegalArgumentException();
57218822Sdim    }
58218822Sdim
59218822Sdim    public long getLong(Object obj) throws IllegalArgumentException {
60218822Sdim        throw newGetLongIllegalArgumentException();
61218822Sdim    }
62218822Sdim
63218822Sdim    public float getFloat(Object obj) throws IllegalArgumentException {
64218822Sdim        return unsafe.getFloat(base, fieldOffset);
65218822Sdim    }
6638889Sjdp
6738889Sjdp    public double getDouble(Object obj) throws IllegalArgumentException {
68218822Sdim        return getFloat(obj);
6938889Sjdp    }
7038889Sjdp
7138889Sjdp    public void set(Object obj, Object value)
7238889Sjdp        throws IllegalArgumentException, IllegalAccessException
73218822Sdim    {
7438889Sjdp        if (isFinal) {
7538889Sjdp            throwFinalFieldIllegalAccessException(value);
76218822Sdim        }
77218822Sdim        if (value == null) {
7838889Sjdp            throwSetIllegalArgumentException(value);
7938889Sjdp        }
8038889Sjdp        if (value instanceof Byte) {
8138889Sjdp            unsafe.putFloat(base, fieldOffset, ((Byte) value).byteValue());
8238889Sjdp            return;
8338889Sjdp        }
84218822Sdim        if (value instanceof Short) {
85218822Sdim            unsafe.putFloat(base, fieldOffset, ((Short) value).shortValue());
86218822Sdim            return;
87218822Sdim        }
88218822Sdim        if (value instanceof Character) {
89218822Sdim            unsafe.putFloat(base, fieldOffset, ((Character) value).charValue());
9038889Sjdp            return;
9138889Sjdp        }
92218822Sdim        if (value instanceof Integer) {
93218822Sdim            unsafe.putFloat(base, fieldOffset, ((Integer) value).intValue());
94218822Sdim            return;
95218822Sdim        }
96218822Sdim        if (value instanceof Long) {
97218822Sdim            unsafe.putFloat(base, fieldOffset, ((Long) value).longValue());
98218822Sdim            return;
99218822Sdim        }
100218822Sdim        if (value instanceof Float) {
10138889Sjdp            unsafe.putFloat(base, fieldOffset, ((Float) value).floatValue());
10238889Sjdp            return;
10338889Sjdp        }
10438889Sjdp        throwSetIllegalArgumentException(value);
10538889Sjdp    }
10638889Sjdp
10738889Sjdp    public void setBoolean(Object obj, boolean z)
108218822Sdim        throws IllegalArgumentException, IllegalAccessException
109218822Sdim    {
110218822Sdim        throwSetIllegalArgumentException(z);
111218822Sdim    }
11260484Sobrien
113218822Sdim    public void setByte(Object obj, byte b)
11438889Sjdp        throws IllegalArgumentException, IllegalAccessException
115218822Sdim    {
116218822Sdim        setFloat(obj, b);
117218822Sdim    }
118218822Sdim
119218822Sdim    public void setChar(Object obj, char c)
120218822Sdim        throws IllegalArgumentException, IllegalAccessException
121218822Sdim    {
122218822Sdim        setFloat(obj, c);
123218822Sdim    }
124218822Sdim
125218822Sdim    public void setShort(Object obj, short s)
126218822Sdim        throws IllegalArgumentException, IllegalAccessException
127218822Sdim    {
128218822Sdim        setFloat(obj, s);
129218822Sdim    }
130218822Sdim
131218822Sdim    public void setInt(Object obj, int i)
132218822Sdim        throws IllegalArgumentException, IllegalAccessException
133218822Sdim    {
134218822Sdim        setFloat(obj, i);
135218822Sdim    }
136218822Sdim
137218822Sdim    public void setLong(Object obj, long l)
138218822Sdim        throws IllegalArgumentException, IllegalAccessException
13938889Sjdp    {
140218822Sdim        setFloat(obj, l);
141218822Sdim    }
142218822Sdim
14338889Sjdp    public void setFloat(Object obj, float f)
144218822Sdim        throws IllegalArgumentException, IllegalAccessException
145218822Sdim    {
146218822Sdim        if (isFinal) {
147218822Sdim            throwFinalFieldIllegalAccessException(f);
148218822Sdim        }
149218822Sdim        unsafe.putFloat(base, fieldOffset, f);
150218822Sdim    }
151218822Sdim
152218822Sdim    public void setDouble(Object obj, double d)
153218822Sdim        throws IllegalArgumentException, IllegalAccessException
154218822Sdim    {
155218822Sdim        throwSetIllegalArgumentException(d);
156218822Sdim    }
157218822Sdim}
158218822Sdim