Skip to content

Commit 1de1e96

Browse files
committed
Graph.py and PyInterpreter.java added
1 parent 11d3604 commit 1de1e96

34 files changed

+62
-248
lines changed

.idea/.gitignore

-8
This file was deleted.

.idea/inspectionProfiles/Project_Default.xml

-23
This file was deleted.

.idea/misc.xml

-6
This file was deleted.

.idea/modules.xml

-8
This file was deleted.

.idea/runConfigurations.xml

-10
This file was deleted.

.idea/uiDesigner.xml

-124
This file was deleted.

.idea/vcs.xml

-6
This file was deleted.

src/App.java App.java

+27-31
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import BuilderPattern.*;
33
import CustomerPackage.GreatCustomer;
44
import CustomerPackage.StandartCustomer;
5+
import Python.PyInterpreter;
56
import SimpleFactoryPattern.CustomerSimpleFactory;
67
import CustomerPackage.ACustomer;
78

@@ -14,81 +15,76 @@ public class App {
1415
public static void main(String[] args) throws CloneNotSupportedException {
1516
Random r = new Random();
1617
int x;
18+
1719
//None Pattern
18-
for (int i=0; i<10; i++){
20+
Long startTime = System.currentTimeMillis();
21+
for (int i=0; i<1000000; i++){
1922
x=r.nextInt(2);
2023
if (x==0) {
21-
Long startTime = System.currentTimeMillis();
2224
ACustomer c = new StandartCustomer("" + i, "" + i, "" + i, "" + i, 'X');
23-
Long stopTime = System.currentTimeMillis();
24-
calculateTime(startTime,stopTime, "NonePattern");
2525
}
2626
else {
27-
Long startTime = System.currentTimeMillis();
2827
ACustomer c = new GreatCustomer("" + i, "" + i, "" + i, "" + i, 'X');
29-
Long stopTime = System.currentTimeMillis();
30-
calculateTime(startTime,stopTime, "NonePattern");
3128
}
3229
}
30+
Long stopTime = System.currentTimeMillis();
31+
calculateTime(startTime,stopTime, "NonePattern");
32+
3333
sb = new StringBuilder();
3434

3535
//Builder
36-
for (int i=0; i<10; i++) {
36+
Long startTime2 = System.currentTimeMillis();
37+
for (int i=0; i<1000000; i++) {
3738
x = r.nextInt(2);
3839
if (x==0) {
39-
Long startTime = System.currentTimeMillis();
40-
ACustomer cus = CustomerBuilder.createCustomer("A", "B", "14342859028", "5855748487", 'E')
40+
ACustomer cus = CustomerBuilder.createCustomer("" + i, "" + i, "" + i, "" + i, 'X')
4141
.buildCustomer();
42-
Long stopTime = System.currentTimeMillis();
43-
calculateTime(startTime,stopTime, "Builder");
4442
}
4543
else{
46-
Long startTime = System.currentTimeMillis();
47-
ACustomer cus = CustomerBuilder.createGreatCustomer("A", "B", "14342859028", "5855748487", 'E')
44+
ACustomer cus = CustomerBuilder.createGreatCustomer("" + i, "" + i, "" + i, "" + i, 'X')
4845
.buildCustomer();
49-
Long stopTime = System.currentTimeMillis();
50-
calculateTime(startTime,stopTime, "Builder" );
5146
}
5247
}
48+
Long stopTime2 = System.currentTimeMillis();
49+
calculateTime(startTime2,stopTime2, "Builder" );
5350
sb = new StringBuilder();
5451

5552
// Prototype
5653
ACustomer c = new StandartCustomer("Kerem", "Tan","11","999-999-99-99",'X');
57-
for (int i=0; i<10; i++) {
54+
Long startTime3 = System.currentTimeMillis();
55+
for (int i=0; i<1000000; i++) {
5856
x=r.nextInt(2);
59-
Long startTime = System.currentTimeMillis();
6057
ACustomer c2 = c.clone(x);
61-
Long stopTime = System.currentTimeMillis();
62-
calculateTime(startTime,stopTime, "Prototype");
6358
}
59+
Long stopTime3 = System.currentTimeMillis();
60+
calculateTime(startTime3,stopTime3, "Prototype");
6461
sb = new StringBuilder();
6562

6663
// Abstract Factory
67-
for(int i=0; i<10; i++) {
64+
Long startTime4 = System.currentTimeMillis();
65+
for(int i=0; i<1000000; i++) {
6866
x=r.nextInt(2);
6967
if(x==0) {
70-
Long startTime = System.currentTimeMillis();
7168
ACustomer cusOC = new StandartCustomerFactory().creatCustomer("" + i, "" + i, "" + i, "" + i, 'X');
72-
Long stopTime = System.currentTimeMillis();
73-
calculateTime(startTime,stopTime, "Abstract_Factory");
7469
}
7570
else {
76-
Long startTime2 = System.currentTimeMillis();
7771
ACustomer cusGC = new GreatCustomerFactory().creatCustomer("" + i, "" + i, "" + i, "" + i, 'X');
78-
Long stopTime = System.currentTimeMillis();
79-
calculateTime(startTime2,stopTime,"Abstract_Factory");
8072
}
8173
}
74+
Long stopTime4 = System.currentTimeMillis();
75+
calculateTime(startTime4,stopTime4,"Abstract_Factory");
8276
sb = new StringBuilder();
8377

8478
// Simple Factory
85-
for(int i=0; i<10; i++) {
79+
Long startTime5 = System.currentTimeMillis();
80+
for(int i=0; i<1000000; i++) {
8681
x=r.nextInt(2);
87-
Long startTime = System.currentTimeMillis();
8882
ACustomer cus = new CustomerSimpleFactory().createCustomer(x, "" + i, "" + i, "" + i, "" + i, 'X');
89-
Long stopTime = System.currentTimeMillis();
90-
calculateTime(startTime,stopTime, "Simple_Factory");
9183
}
84+
Long stopTime5 = System.currentTimeMillis();
85+
calculateTime(startTime5,stopTime5, "Simple_Factory");
86+
87+
new PyInterpreter().execPy();
9288
}
9389

9490
private static void calculateTime(Long startTime, Long stopTime, String pattern) {
File renamed without changes.

CretaionalPatterns.iml

-11
This file was deleted.
File renamed without changes.

CustomerPackage/EmptyCustomer.java

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package CustomerPackage;
2+
3+
public class EmptyCustomer extends ACustomer{
4+
public EmptyCustomer() {
5+
}
6+
}

src/CustomerPackage/GreatCustomer.java CustomerPackage/GreatCustomer.java

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
public class GreatCustomer extends ACustomer{
44
public GreatCustomer(String firstName, String lastName, String tcId, String phoneNumber, char gender) {
5-
try {
6-
Thread.sleep(20);
7-
} catch (InterruptedException e) {
8-
e.printStackTrace();
9-
}
105
super.setFirstName(firstName);
116
super.setLastName(lastName);
127
super.setTcId(tcId);

src/CustomerPackage/StandartCustomer.java CustomerPackage/StandartCustomer.java

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
public class StandartCustomer extends ACustomer{
44
public StandartCustomer(String firstName, String lastName, String tcId, String phoneNumber, char gender) {
5-
try {
6-
Thread.sleep(20);
7-
} catch (InterruptedException e) {
8-
e.printStackTrace();
9-
}
105
super.setFirstName(firstName);
116
super.setLastName(lastName);
127
super.setTcId(tcId);

Python/PyInterpreter.java

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package Python;
2+
3+
import java.io.*;
4+
5+
public class PyInterpreter {
6+
public void execPy(){
7+
try {
8+
String command = "cmd /c python "+System.getProperty("user.dir")+"\\src\\main\\resources\\Graph.py";
9+
Process p = Runtime.getRuntime().exec(command);
10+
p.waitFor();
11+
BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
12+
BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
13+
String line;
14+
while ((line = bri.readLine()) != null) {
15+
System.out.println(line);
16+
}
17+
bri.close();
18+
while ((line = bre.readLine()) != null) {
19+
System.out.println(line);
20+
}
21+
bre.close();
22+
p.waitFor();
23+
System.out.println("Done.");
24+
25+
p.destroy();
26+
}
27+
catch (Exception e){}
28+
}
29+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
-4.91 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/CustomerPackage/EmptyCustomer.java

-11
This file was deleted.

0 commit comments

Comments
 (0)