-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
- Loading branch information
0 parents
commit b989b47
Showing
3 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
*/ | ||
} |