KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > model > ListFormatOverrideLevel


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

17         
18
19 package org.apache.poi.hwpf.model;
20
21 import org.apache.poi.util.LittleEndian;
22 import org.apache.poi.util.BitField;
23
24 import java.util.Arrays JavaDoc;
25
26 public class ListFormatOverrideLevel
27 {
28   private static final int BASE_SIZE = 8;
29
30   int _iStartAt;
31   byte _info;
32    private static BitField _ilvl = new BitField(0xf);
33    private static BitField _fStartAt = new BitField(0x10);
34    private static BitField _fFormatting = new BitField(0x20);
35   byte[] _reserved = new byte[3];
36   ListLevel _lvl;
37
38   public ListFormatOverrideLevel(byte[] buf, int offset)
39   {
40     _iStartAt = LittleEndian.getInt(buf, offset);
41     offset += LittleEndian.INT_SIZE;
42     _info = buf[offset++];
43     System.arraycopy(buf, offset, _reserved, 0, _reserved.length);
44     offset += _reserved.length;
45
46     if (_fFormatting.getValue(_info) > 0)
47     {
48       _lvl = new ListLevel(buf, offset);
49     }
50   }
51
52   public ListLevel getLevel()
53   {
54     return _lvl;
55   }
56
57   public int getLevelNum()
58   {
59     return _ilvl.getValue(_info);
60   }
61
62   public boolean isFormatting()
63   {
64     return _fFormatting.getValue(_info) != 0;
65   }
66
67   public boolean isStartAt()
68   {
69     return _fStartAt.getValue(_info) != 0;
70   }
71
72   public int getSizeInBytes()
73   {
74     return (_lvl == null ? BASE_SIZE : BASE_SIZE + _lvl.getSizeInBytes());
75   }
76
77   public boolean equals(Object JavaDoc obj)
78   {
79     if (obj == null)
80     {
81       return false;
82     }
83     ListFormatOverrideLevel lfolvl = (ListFormatOverrideLevel)obj;
84     boolean lvlEquality = false;
85     if (_lvl != null)
86     {
87       lvlEquality = _lvl.equals(lfolvl._lvl);
88     }
89     else
90     {
91       lvlEquality = lfolvl._lvl == null;
92     }
93
94     return lvlEquality && lfolvl._iStartAt == _iStartAt && lfolvl._info == _info &&
95       Arrays.equals(lfolvl._reserved, _reserved);
96   }
97
98   public byte[] toByteArray()
99   {
100     byte[] buf = new byte[getSizeInBytes()];
101
102     int offset = 0;
103     LittleEndian.putInt(buf, _iStartAt);
104     offset += LittleEndian.INT_SIZE;
105     buf[offset++] = _info;
106     System.arraycopy(_reserved, 0, buf, offset, 3);
107     offset += 3;
108
109     if (_lvl != null)
110     {
111       byte[] levelBuf = _lvl.toByteArray();
112       System.arraycopy(levelBuf, 0, buf, offset, levelBuf.length);
113     }
114
115     return buf;
116   }
117 }
118
Popular Tags