00001 package commandline.flatFileToBinaryPackage.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 if(codeword.equalsIgnoreCase("")){
00050 return false;
00051 }
00052 int lengte=codeword.length();
00053
00054 char[] codewordArray=codeword.toCharArray();
00055 boolean match=true;
00056 try{
00057 for(int i=0;i!=lengte;i++){
00058 if(!codelist.get(i).equals(""+codewordArray[i])){match=false; return false;};
00059 }
00060 }catch(Exception exception){
00061 if(match){
00062
00063
00064
00065 throw new NotEnoughBytesException(new CodeRetriever());
00066 }
00067 }
00068
00069 return true;
00070 }
00071
00072 }