1/* 2Copyright (c) 2011 Stanislav Vitvitskiy 3 4Permission is hereby granted, free of charge, to any person obtaining a copy of this 5software and associated documentation files (the "Software"), to deal in the Software 6without restriction, including without limitation the rights to use, copy, modify, 7merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 8permit persons to whom the Software is furnished to do so, subject to the following 9conditions: 10 11The above copyright notice and this permission notice shall be included in all copies or 12substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 16PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 17FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 18TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 19OR OTHER DEALINGS IN THE SOFTWARE. 20*/ 21package com.googlecode.mp4parser.h264; 22 23 24/** 25 * Simple BTree implementation needed for haffman tables 26 * 27 * @author Stanislav Vitvitskiy 28 */ 29public class BTree { 30 private BTree zero; 31 private BTree one; 32 private Object value; 33 34 /** 35 * Adds a leaf value to a binary path specified by path 36 * 37 * @param str 38 * @param value 39 */ 40 public void addString(String path, Object value) { 41 if (path.length() == 0) { 42 this.value = value; 43 return; 44 } 45 char charAt = path.charAt(0); 46 BTree branch; 47 if (charAt == '0') { 48 if (zero == null) 49 zero = new BTree(); 50 branch = zero; 51 } else { 52 if (one == null) 53 one = new BTree(); 54 branch = one; 55 } 56 branch.addString(path.substring(1), value); 57 } 58 59 public BTree down(int b) { 60 if (b == 0) 61 return zero; 62 else 63 return one; 64 } 65 66 public Object getValue() { 67 return value; 68 } 69}