KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > util > RKUtil


1 /* ====================================================================
2    Copyright 2002-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hssf.util;
18
19 /**
20  * Utility class for helping convert RK numbers.
21  *
22  * @author Andrew C. Oliver (acoliver at apache dot org)
23  * @author Glen Stampoultzis (glens at apache.org)
24  * @author Rolf-Jürgen Moll
25  *
26  * @see org.apache.poi.hssf.record.MulRKRecord
27  * @see org.apache.poi.hssf.record.RKRecord
28  */

29 public class RKUtil
30 {
31     private RKUtil()
32     {
33     }
34
35     /**
36      * Do the dirty work of decoding; made a private static method to
37      * facilitate testing the algorithm
38      */

39
40     public static double decodeNumber(int number)
41     {
42         long raw_number = number;
43
44         // mask off the two low-order bits, 'cause they're not part of
45
// the number
46
raw_number = raw_number >> 2;
47         double rvalue = 0;
48
49         if ((number & 0x02) == 0x02)
50         {
51             // ok, it's just a plain ol' int; we can handle this
52
// trivially by casting
53
rvalue = ( double ) (raw_number);
54         }
55         else
56         {
57
58             // also trivial, but not as obvious ... left shift the
59
// bits high and use that clever static method in Double
60
// to convert the resulting bit image to a double
61
rvalue = Double.longBitsToDouble(raw_number << 34);
62         }
63         if ((number & 0x01) == 0x01)
64         {
65
66             // low-order bit says divide by 100, and so we do. Why?
67
// 'cause that's what the algorithm says. Can't fight city
68
// hall, especially if it's the city of Redmond
69
rvalue /= 100;
70         }
71
72         return rvalue;
73     }
74
75 }
76
Popular Tags