001: /**
002: * Copyright (c) 2003, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.filter;
031:
032: import java.util.HashMap;
033: import java.util.Map;
034:
035: /**
036: * This is the used for the LZWDecode filter.
037: *
038: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
039: * @version $Revision: 1.4 $
040: */
041: class LZWNode {
042: private long code;
043: private Map subNodes = new HashMap();
044:
045: /**
046: * This will get the number of children.
047: *
048: * @return The number of children.
049: */
050: public int childCount() {
051: return subNodes.size();
052: }
053:
054: /**
055: * This will set the node for a particular byte.
056: *
057: * @param b The byte for that node.
058: * @param node The node to add.
059: */
060: public void setNode(byte b, LZWNode node) {
061: subNodes.put(new Byte(b), node);
062: }
063:
064: /**
065: * This will get the node that is a direct sub node of this node.
066: *
067: * @param data The byte code to the node.
068: *
069: * @return The node at that value if it exists.
070: */
071: public LZWNode getNode(byte data) {
072: return (LZWNode) subNodes.get(new Byte(data));
073: }
074:
075: /**
076: * This will traverse the tree until it gets to the sub node.
077: * This will return null if the node does not exist.
078: *
079: * @param data The path to the node.
080: *
081: * @return The node that resides at the data path.
082: */
083: public LZWNode getNode(byte[] data) {
084: LZWNode current = this ;
085: for (int i = 0; i < data.length && current != null; i++) {
086: current = current.getNode(data[i]);
087: }
088: return current;
089: }
090:
091: /** Getter for property code.
092: * @return Value of property code.
093: */
094: public long getCode() {
095: return code;
096: }
097:
098: /** Setter for property code.
099: * @param codeValue New value of property code.
100: */
101: public void setCode(long codeValue) {
102: code = codeValue;
103: }
104:
105: }
|