00001 package HuffMan;
00002
00003 import java.util.ArrayList;
00004
00005 import junit.framework.Assert;
00006
00012 public class CodeRetriever {
00013
00014
00021 public static int getAndRemoveOriginal(ArrayList<String> codelist, ArrayList<String> codewords) throws NotEnoughBytesException{
00022
00023 boolean istoegekend=false;
00024 int positie=0;
00025 for(int i =0;i!=codewords.size();i++){
00026 String codeword=codewords.get(i);
00027 if(isHead(codelist,codeword)){
00028 for(int k=0;k!=codeword.length();k++){
00029 codelist.remove(0);
00030 }
00031 positie=i;
00032 istoegekend=true;
00033 break;
00034 }
00035 }
00036 Assert.assertTrue(istoegekend);
00037
00038 return positie;
00039 }
00040
00041
00048 private static boolean isHead(ArrayList<String> codelist,String codeword) throws NotEnoughBytesException{
00049 int lengte=codeword.length();
00050
00051 char[] codewordArray=codeword.toCharArray();
00052 boolean match=true;
00053 try{
00054 for(int i=0;i!=lengte;i++){
00055 if(!codelist.get(i).equals(""+codewordArray[i])){match=false; return false;};
00056 }
00057 }catch(Exception exception){
00058 if(match){
00059
00060
00061
00062 throw new NotEnoughBytesException();
00063 }
00064 }
00065
00066 return true;
00067 }
00068
00069 }