Home » pdfbox-1.1.0-src » org.apache.pdfbox.filter » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  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   package org.apache.pdfbox.filter;
   18   
   19   import java.util.HashMap;
   20   import java.util.Map;
   21   
   22   /**
   23    * This is the used for the LZWDecode filter.
   24    *
   25    * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
   26    * @version $Revision: 1.4 $
   27    */
   28   class LZWNode
   29   {
   30       private long code;
   31       private Map subNodes = new HashMap();
   32   
   33       /**
   34        * This will get the number of children.
   35        *
   36        * @return The number of children.
   37        */
   38       public int childCount()
   39       {
   40           return subNodes.size();
   41       }
   42   
   43       /**
   44        * This will set the node for a particular byte.
   45        *
   46        * @param b The byte for that node.
   47        * @param node The node to add.
   48        */
   49       public void setNode( byte b, LZWNode node )
   50       {
   51           subNodes.put( new Byte( b ), node );
   52       }
   53   
   54       /**
   55        * This will get the node that is a direct sub node of this node.
   56        *
   57        * @param data The byte code to the node.
   58        *
   59        * @return The node at that value if it exists.
   60        */
   61       public LZWNode getNode( byte data )
   62       {
   63           return (LZWNode)subNodes.get( new Byte( data ) );
   64       }
   65   
   66   
   67       /**
   68        * This will traverse the tree until it gets to the sub node.
   69        * This will return null if the node does not exist.
   70        *
   71        * @param data The path to the node.
   72        *
   73        * @return The node that resides at the data path.
   74        */
   75       public LZWNode getNode( byte[] data )
   76       {
   77           LZWNode current = this;
   78           for( int i=0; i<data.length && current != null; i++ )
   79           {
   80               current = current.getNode( data[i] );
   81           }
   82           return current;
   83       }
   84   
   85       /** Getter for property code.
   86        * @return Value of property code.
   87        */
   88       public long getCode()
   89       {
   90           return code;
   91       }
   92   
   93       /** Setter for property code.
   94        * @param codeValue New value of property code.
   95        */
   96       public void setCode(long codeValue)
   97       {
   98           code = codeValue;
   99       }
  100   
  101   }

Home » pdfbox-1.1.0-src » org.apache.pdfbox.filter » [javadoc | source]