Skip to content

Commit

Permalink
Challenge_2_commit from Browser
Browse files Browse the repository at this point in the history
add
  • Loading branch information
rhagee authored Oct 12, 2019
0 parents commit b989b47
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Challenge_2_git/FilePair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Second_Challenge;

import java.io.File;

public class FilePair
{
File first;
File second;

public FilePair(File first,File second)
{
this.first=first;
this.second=second;
}
}
47 changes: 47 additions & 0 deletions Challenge_2_git/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package Second_Challenge;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Main
{
public static void main(String[] args) throws Exception
{
File folder = new File("src/Second_Challenge/files");
File[] list = folder.listFiles();
List<FilePair> FileList = new ArrayList();
List<myThread> Compare = new ArrayList();
for (int i = 0; i < list.length-1;i++)
{
char[] a = list[i].getName().toCharArray();
char[] b = list[i+1].getName().toCharArray();
String new1="";
String new2="";
int lun = (a.length<b.length) ? a.length : b.length;
boolean exit=false;
for(int j=0;j<lun && !exit;j++)
{
if(b[j]!='.')
{
new1+=a[j];
new2+=b[j];
}
else
{
exit=true;
}
}
if(new1.equals(new2))
{
FileList.add(new FilePair(list[i],list[i+1]));
}
}
for(int i=0;i<FileList.size();i++)
{
myThread tr = new myThread(FileList.get(i).first,FileList.get(i).second);
tr.start();
Compare.add(tr);
}
}
}
101 changes: 101 additions & 0 deletions Challenge_2_git/myThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package Second_Challenge;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.lang.Object;
import java.lang.*;
import org.apache.commons.lang3.StringUtils;

public class myThread extends Thread
{
public File first;
public File second;
String diff1;
String diff2;
public myThread(File first, File second)
{
this.first=first;
this.second=second;
diff1="";
diff2="";
}
@Override
public void run()
{
List<String> a = readFile(first);
List<String> b = readFile(second);
}



/*
OLD VERSION
@Override
public void run() {
List<String> flines = null;
try {
flines = getLines(first);
} catch (Exception e) {
e.printStackTrace();
}
List<String> slines = null;
try {
slines = getLines(second);
} catch (Exception e) {
e.printStackTrace();
}
int ln = flines.size()<slines.size() ? flines.size() : slines.size();
for(int i=0;i<ln;i++)
{
String a = flines.get(i);
String b = slines.get(i);
diff1+=compareLine(a,b);
diff2+=compareLine(b,a);
}
System.out.println("Diff 1 : "+diff1);
System.out.println("Diff 2 : "+diff2);
try {
BufferedWriter wr = new BufferedWriter(new FileWriter("src/Second_Challenge/"+first.getName()+"(0).txt"));
wr.write(diff1);
wr = new BufferedWriter(new FileWriter("src/Second_Challenge/"+first.getName()+"(1).txt"));
wr.write(diff2);
wr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private String compareLine(String a, String b)
{
String res = "";
char[] arr_a = a.toCharArray();
char[] arr_b = b.toCharArray();
int len = (arr_a.length<arr_b.length) ? arr_a.length : arr_b.length;
for(int i=0;i<len;i++)
{
if(arr_a[i]!=arr_b[i])
{
res+=arr_a[i];
}
}
return res;
}
public List<String> getLines(File file) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(file));
List<String> lines= new ArrayList();
String line="";
while((line=reader.readLine())!=null)
{
lines.add(line);
}
reader.close();
return lines;
}
*/
}

0 comments on commit b989b47

Please sign in to comment.