1 2 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 ; 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 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 |