001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hwpf.model;
019:
020: import org.apache.poi.util.LittleEndian;
021:
022: import java.util.Arrays;
023:
024: public class ListFormatOverride {
025: int _lsid;
026: int _reserved1;
027: int _reserved2;
028: byte _clfolvl;
029: byte[] _reserved3 = new byte[3];
030: ListFormatOverrideLevel[] _levelOverrides;
031:
032: public ListFormatOverride(int lsid) {
033: _lsid = lsid;
034: _levelOverrides = new ListFormatOverrideLevel[0];
035: }
036:
037: public ListFormatOverride(byte[] buf, int offset) {
038: _lsid = LittleEndian.getInt(buf, offset);
039: offset += LittleEndian.INT_SIZE;
040: _reserved1 = LittleEndian.getInt(buf, offset);
041: offset += LittleEndian.INT_SIZE;
042: _reserved2 = LittleEndian.getInt(buf, offset);
043: offset += LittleEndian.INT_SIZE;
044: _clfolvl = buf[offset++];
045: System.arraycopy(buf, offset, _reserved3, 0, _reserved3.length);
046: _levelOverrides = new ListFormatOverrideLevel[_clfolvl];
047: }
048:
049: public int numOverrides() {
050: return _clfolvl;
051: }
052:
053: public int getLsid() {
054: return _lsid;
055: }
056:
057: void setLsid(int lsid) {
058: _lsid = lsid;
059: }
060:
061: public ListFormatOverrideLevel[] getLevelOverrides() {
062: return _levelOverrides;
063: }
064:
065: public void setOverride(int index, ListFormatOverrideLevel lfolvl) {
066: _levelOverrides[index] = lfolvl;
067: }
068:
069: public ListFormatOverrideLevel getOverrideLevel(int level) {
070:
071: ListFormatOverrideLevel retLevel = null;
072:
073: for (int x = 0; x < _levelOverrides.length; x++) {
074: if (_levelOverrides[x].getLevelNum() == level) {
075: retLevel = _levelOverrides[x];
076: }
077: }
078: return retLevel;
079: }
080:
081: public boolean equals(Object obj) {
082: if (obj == null) {
083: return false;
084: }
085:
086: ListFormatOverride lfo = (ListFormatOverride) obj;
087: return lfo._clfolvl == _clfolvl && lfo._lsid == _lsid
088: && lfo._reserved1 == _reserved1
089: && lfo._reserved2 == _reserved2
090: && Arrays.equals(lfo._reserved3, _reserved3)
091: && Arrays.equals(lfo._levelOverrides, _levelOverrides);
092: }
093:
094: public byte[] toByteArray() {
095: byte[] buf = new byte[16];
096: int offset = 0;
097: LittleEndian.putInt(buf, offset, _lsid);
098: offset += LittleEndian.INT_SIZE;
099: LittleEndian.putInt(buf, offset, _reserved1);
100: offset += LittleEndian.INT_SIZE;
101: LittleEndian.putInt(buf, offset, _reserved2);
102: offset += LittleEndian.INT_SIZE;
103: buf[offset++] = _clfolvl;
104: System.arraycopy(_reserved3, 0, buf, offset, 3);
105:
106: return buf;
107: }
108: }
|