mostafanageeb -6 Newbie Poster

I am Making an implementation to the lz77 compression algorithm, but I couldn't calculate the offset,
pleasei f someone can help tell me,

public class Main3 
{


	public static void main(String[] args) 
	{
		StringBuffer input = new StringBuffer("ADABRARRARRAD");
		StringBuffer toBe = new StringBuffer(input);
		StringBuffer done = new StringBuffer("");
		String find="";
		String tag="";
		String offset="";
		String temp ="";
		int off=0;
		int diff=0;
		char x;
		
		while (toBe.length()!=0)
		{
			
			find=find+toBe.charAt(0);
			x=toBe.charAt(0);
			toBe.deleteCharAt(0);
			///////////////////////////////////////////////////////////////////////////
			///////////////////////////////////////////////////////////////////////////
			if (toBe.length()==0 && done.length()==input.length()-1)
			{
				if (done.indexOf(find)==-1)
				{
					System.out.println(done);
					System.out.println(find);
					tag = "Offset " + (find.length()-1)+" "+ find.charAt((find.length()-1));
					System.out.println(tag);
				}
				else if (done.indexOf(find)>-1)
				{
					System.out.println(done);
					System.out.println(find);
					offset = done.substring(0, done.length()-find.length());
					System.out.println(offset);
					tag = "Offset " + find.length()+" "+ "NULL";
					System.out.println(tag);
				}
				break;
			}
			///////////////////////////////////////////////////////////////////////////
			///////////////////////////////////////////////////////////////////////////
			else
			{
				if (done.indexOf(find)==-1)
				{
					//System.out.println(done.indexOf(find));
					System.out.println(done);
					done.append(x);
					System.out.println(find);
					//System.out.println(find.length()+" "+done.length()+" "+toBe.length());
					//System.out.println(done.length());
					//diff = done.length()-find.length();
					//temp = find.substring(0,find.length()-2);
					//System.out.println(temp);
					
					
					tag +="Offset= "+off+ " Length= "+(find.length()-1)+" Next =" + x;
					System.out.println(tag);
					tag="";
					find="";
				}
				else if (done.indexOf(find)>-1)
				{
					//ind=done.indexOf(find);
					//System.out.println(find);
					done.append(x);		
				}
			}
		}
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.