diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..974de2a
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
index 69a4283..9b53612 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
+/bin/
diff --git a/.project b/.project
new file mode 100644
index 0000000..aab6146
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ CodeSmells
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/src/com/directi/training/codesmells/duplicatecode/RStatistics.java b/src/com/directi/training/codesmells/duplicatecode/RStatistics.java
new file mode 100644
index 0000000..9324868
--- /dev/null
+++ b/src/com/directi/training/codesmells/duplicatecode/RStatistics.java
@@ -0,0 +1,31 @@
+package com.directi.training.codesmells.duplicatecode;
+
+public class RStatistics {
+
+ private double getAverage(double[] array) {
+ double cont = 0;
+ for (double element : array) {
+ cont += element;
+ }
+ return cont / array.length;
+ }
+
+ public double calculateSampleVariance(double[] elements) {
+ double average = getAverage(elements);
+ double count = 0.0;
+ for (double e : elements) {
+ count += Math.pow(e - average, 2);
+ }
+ return count / (elements.length - 1);
+ }
+
+ public double calculateDifferenceOfAverage(double[] array1, double[] array2) {
+ return Math.abs(getAverage(array1) - getAverage(array2));
+ }
+
+}
+
+
+
+
+
diff --git a/src/com/directi/training/codesmells/duplicatecode/Statistics.java b/src/com/directi/training/codesmells/duplicatecode/Statistics.java
index aba408f..d7c0c9c 100644
--- a/src/com/directi/training/codesmells/duplicatecode/Statistics.java
+++ b/src/com/directi/training/codesmells/duplicatecode/Statistics.java
@@ -38,4 +38,4 @@ public double calculateSampleVariance(double[] elements)
return temp / (elements.length - 1);
}
-}
\ No newline at end of file
+}
diff --git a/src/com/directi/training/codesmells/featureenvy/Address.java b/src/com/directi/training/codesmells/featureenvy/Address.java
index 8f61bdd..0c55a30 100644
--- a/src/com/directi/training/codesmells/featureenvy/Address.java
+++ b/src/com/directi/training/codesmells/featureenvy/Address.java
@@ -1,53 +1,50 @@
package com.directi.training.codesmells.featureenvy;
-public class Address
-{
-
- private String _addressLine1;
+public class Address {
+ private String _addressLine1;
private String _addressLine2;
private String _city;
private String _state;
private String _country;
private String _postalCode;
- public Address(String addressLine1, String addressLine2, String city, String state,
- String country, String postalCode)
- {
- _addressLine1 = addressLine1;
- _addressLine2 = addressLine2;
- _city = city;
- _state = state;
- _country = country;
- _postalCode = postalCode;
- }
-
- public String getAddressLine1()
- {
- return _addressLine1;
- }
-
- public String getAddressLine2()
- {
- return _addressLine2;
- }
-
- public String getCity()
- {
- return _city;
- }
-
- public String getState()
- {
- return _state;
- }
-
- public String getCountry()
- {
- return _country;
- }
-
- public String getPostalCode()
- {
- return _postalCode;
- }
+ public Address(String addressLine1, String addressLine2, String city, String state, String country,
+ String postalCode) {
+ _addressLine1 = addressLine1;
+ _addressLine2 = addressLine2;
+ _city = city;
+ _state = state;
+ _country = country;
+ _postalCode = postalCode;
+ }
+
+ public String getAddressLine1() {
+ return _addressLine1;
+ }
+
+ public String getAddressLine2() {
+ return _addressLine2;
+ }
+
+
+
+ public String getCity() {
+ return _city;
+ }
+
+ public String getState() {
+ return _state;
+ }
+
+ public String getCountry() {
+ return _country;
+ }
+
+ public String getPostalCode() {
+ return _postalCode;
+ }
+
+
+
+
}
diff --git a/src/com/directi/training/codesmells/featureenvy/Customer.java b/src/com/directi/training/codesmells/featureenvy/Customer.java
index 4c7ee85..f88624e 100644
--- a/src/com/directi/training/codesmells/featureenvy/Customer.java
+++ b/src/com/directi/training/codesmells/featureenvy/Customer.java
@@ -1,24 +1,17 @@
package com.directi.training.codesmells.featureenvy;
-public class Customer
-{
- private String _name;
- private Address _currentAddress;
+public class Customer {
+ private String _name;
+ private Address _currentAddress;
- public Customer(String name, Address address)
- {
- _name = name;
- _currentAddress = address;
- }
+ public Customer(String name, Address address) {
+ _name = name;
+ _currentAddress = address;
+ }
- public void printAddress()
- {
- System.out.println(
- _currentAddress.getAddressLine1() + "\n" + _currentAddress.getAddressLine2() + "\n" +
- _currentAddress.getCity() + ", " + _currentAddress.getState() + "\n" +
- _currentAddress.getPostalCode());
- }
-
- //other methods related to customer class.....
+ public void printAddress() {
+ System.out.println(_currentAddress);
+ }
}
+
diff --git a/src/com/directi/training/codesmells/featureenvy/RAddress.java b/src/com/directi/training/codesmells/featureenvy/RAddress.java
new file mode 100644
index 0000000..263ee97
--- /dev/null
+++ b/src/com/directi/training/codesmells/featureenvy/RAddress.java
@@ -0,0 +1,103 @@
+package com.directi.training.codesmells.featureenvy;
+
+public class RAddress {
+
+ private String _addressLine1;
+ private String _addressLine2;
+ private String _city;
+ private String _state;
+ private String _country;
+ private String _postalCode;
+
+ public RAddress(String _addressLine1, String _addressLine2, String _city, String _state, String _country,
+ String _postalCode) {
+ super();
+ this._addressLine1 = _addressLine1;
+ this._addressLine2 = _addressLine2;
+ this._city = _city;
+ this._state = _state;
+ this._country = _country;
+ this._postalCode = _postalCode;
+ }
+
+
+
+ public String get_addressLine1() {
+ return _addressLine1;
+ }
+
+
+
+ public void set_addressLine1(String _addressLine1) {
+ this._addressLine1 = _addressLine1;
+ }
+
+
+
+ public String get_addressLine2() {
+ return _addressLine2;
+ }
+
+
+
+ public void set_addressLine2(String _addressLine2) {
+ this._addressLine2 = _addressLine2;
+ }
+
+
+
+ public String get_city() {
+ return _city;
+ }
+
+
+
+ public void set_city(String _city) {
+ this._city = _city;
+ }
+
+
+
+ public String get_state() {
+ return _state;
+ }
+
+
+
+ public void set_state(String _state) {
+ this._state = _state;
+ }
+
+
+
+ public String get_country() {
+ return _country;
+ }
+
+
+
+ public void set_country(String _country) {
+ this._country = _country;
+ }
+
+
+
+ public String get_postalCode() {
+ return _postalCode;
+ }
+
+
+
+ public void set_postalCode(String _postalCode) {
+ this._postalCode = _postalCode;
+ }
+
+ @Override
+ public String toString() {
+ return "Address [_addressLine1=" + _addressLine1 + ", _addressLine2=" + _addressLine2 + ", _city=" + _city
+ + ", _state=" + _state + ", _country=" + _country + ", _postalCode=" + _postalCode + "]";
+ }
+
+
+
+}
diff --git a/src/com/directi/training/codesmells/featureenvy/RCustomer.java b/src/com/directi/training/codesmells/featureenvy/RCustomer.java
new file mode 100644
index 0000000..1dd90d2
--- /dev/null
+++ b/src/com/directi/training/codesmells/featureenvy/RCustomer.java
@@ -0,0 +1,5 @@
+package com.directi.training.codesmells.featureenvy;
+
+public class RCustomer {
+
+}
diff --git a/src/com/directi/training/codesmells/largeclass/Employee.java b/src/com/directi/training/codesmells/largeclass/Employee.java
index 54138a0..87dda42 100644
--- a/src/com/directi/training/codesmells/largeclass/Employee.java
+++ b/src/com/directi/training/codesmells/largeclass/Employee.java
@@ -25,4 +25,7 @@ public String getName()
{
return _name;
}
-}
\ No newline at end of file
+}
+
+
+
diff --git a/src/com/directi/training/codesmells/largeclass/InformationEmployee.java b/src/com/directi/training/codesmells/largeclass/InformationEmployee.java
new file mode 100644
index 0000000..8083f50
--- /dev/null
+++ b/src/com/directi/training/codesmells/largeclass/InformationEmployee.java
@@ -0,0 +1,24 @@
+package com.directi.training.codesmells.largeclass;
+
+public class InformationEmployee {
+
+ private final String _officeAreaCode;
+ private final String _officeNumber;
+ private final String _officeExtensionNumber;
+
+ public InformationEmployee(String _officeAreaCode, String _officeNumber, String _officeExtensionNumber) {
+ super();
+ this._officeAreaCode = _officeAreaCode;
+ this._officeNumber = _officeNumber;
+ this._officeExtensionNumber = _officeExtensionNumber;
+ }
+
+ @Override
+ public String toString() {
+ return "InformationEmployee [_officeAreaCode=" + _officeAreaCode + ", _officeNumber=" + _officeNumber
+ + ", _officeExtensionNumber=" + _officeExtensionNumber + "]";
+ }
+
+}
+
+
diff --git a/src/com/directi/training/codesmells/largeclass/REmployee.java b/src/com/directi/training/codesmells/largeclass/REmployee.java
new file mode 100644
index 0000000..c2c40d8
--- /dev/null
+++ b/src/com/directi/training/codesmells/largeclass/REmployee.java
@@ -0,0 +1,24 @@
+package com.directi.training.codesmells.largeclass;
+
+public class REmployee {
+
+ private final String _name;
+ private final InformationEmployee informationEmployee;
+
+ public REmployee(String _name, InformationEmployee informationEmployee) {
+ super();
+ this._name = _name;
+ this.informationEmployee = informationEmployee;
+ }
+
+ public String get_name() {
+ return _name;
+ }
+
+ public InformationEmployee getInformationEmployee() {
+ return informationEmployee;
+ }
+
+
+
+}
diff --git a/src/com/directi/training/codesmells/longmethod/Foo.java b/src/com/directi/training/codesmells/longmethod/Foo.java
index bab14eb..e5d7782 100644
--- a/src/com/directi/training/codesmells/longmethod/Foo.java
+++ b/src/com/directi/training/codesmells/longmethod/Foo.java
@@ -3,28 +3,27 @@
import java.util.ArrayList;
import java.util.List;
-public class Foo
-{
- private String _name = "bar";
- private List _orders = new ArrayList<>();
-
- public void printOwing()
- {
- double outStanding = 0.0;
-
- // Print Banner
- System.out.println("***************************");
- System.out.println("****** Customer Owes ******");
- System.out.println("***************************");
-
- // Calculate outstanding
- for (Order order : _orders) {
- outStanding += order.getAmount();
- }
-
- // Print Details
- System.out.println("Name: " + _name);
- System.out.println("Amount: " + outStanding);
- }
-
-}
\ No newline at end of file
+public class Foo {
+ private String _name = "bar";
+ private List _orders = new ArrayList<>();
+
+ public void printOwing() {
+ double outStanding = 0.0;
+
+ // Print Banner
+ System.out.println("***************************");
+ System.out.println("****** Customer Owes ******");
+ System.out.println("***************************");
+
+ // Calculate outstanding
+ for (Order order : _orders) {
+ outStanding += order.getAmount();
+ }
+
+ // Print Details
+ System.out.println("Name: " + _name);
+ System.out.println("Amount: " + outStanding);
+ }
+
+}
+
diff --git a/src/com/directi/training/codesmells/longmethod/RFoo.java b/src/com/directi/training/codesmells/longmethod/RFoo.java
new file mode 100644
index 0000000..b6baf0f
--- /dev/null
+++ b/src/com/directi/training/codesmells/longmethod/RFoo.java
@@ -0,0 +1,31 @@
+package com.directi.training.codesmells.longmethod;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RFoo {
+
+ private String _name = "Bar";
+ private List _orders = new ArrayList<>();
+
+ public void printOwing() {
+ printBanner();
+ printDetails(getOutstanding());
+ }
+
+ private double getOutstanding() {
+ return _orders.stream().mapToDouble(o -> o.getAmount()).sum();
+ }
+
+ private void printDetails(double outstanding) {
+ System.out.println("Name: " + _name);
+ System.out.println("Amount: " + outstanding);
+ }
+
+ private void printBanner() {
+ System.out.println("***************************");
+ System.out.println("****** Customer Owes ******");
+ System.out.println("***************************");
+ }
+
+}
diff --git a/test/com/directi/training/codesmells/duplicatecode/StatisticsTest.java b/test/com/directi/training/codesmells/duplicatecode/StatisticsTest.java
deleted file mode 100644
index 2af51c7..0000000
--- a/test/com/directi/training/codesmells/duplicatecode/StatisticsTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.directi.training.codesmells.duplicatecode;
-
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public class StatisticsTest
-{
- @Test
- public void testCalculateDifferenceOfAverage()
- {
- Statistics statistics = new Statistics();
- double[] array1 = {1, 2, 3, 4, 5};
- double[] array2 = {11, 12, 13, 14, 15};
- double actualValue = statistics.calculateDifferenceOfAverage(array1, array2);
- assertThat(actualValue, is(10.0));
- }
-
- @Test
- public void testCalculateSampleVariance()
- {
- Statistics statistics = new Statistics();
- double[] elements = {1, 2, 3, 4, 5};
- double actualSampleVariance = statistics.calculateSampleVariance(elements);
- assertThat(actualSampleVariance, is(2.5));
- }
-}
diff --git a/test/com/directi/training/codesmells/duplicatecode/acrossclasses/AddEmployeeCmdTest.java b/test/com/directi/training/codesmells/duplicatecode/acrossclasses/AddEmployeeCmdTest.java
deleted file mode 100644
index 1152c82..0000000
--- a/test/com/directi/training/codesmells/duplicatecode/acrossclasses/AddEmployeeCmdTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.directi.training.codesmells.duplicatecode.acrossclasses;
-
-import org.junit.Test;
-
-import java.io.OutputStream;
-
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-public class AddEmployeeCmdTest
-{
- @Test
- public void testWrite() throws Exception
- {
- String name = "Smith";
- String address = "DirectI Plex";
- String city = "Mumbai";
- String state = "Maharashtra";
- String annualSalary = "10000000";
- AddEmployeeCmd addEmployeeCmd = new AddEmployeeCmd(name, address, city, state,
- annualSalary);
- OutputStream outputStream = mock(OutputStream.class);
- addEmployeeCmd.write(outputStream);
- verify(outputStream).write(AddEmployeeCmd.header);
- verify(outputStream).write(53);
- verify(outputStream).write(AddEmployeeCmd.commandChar);
- verify(outputStream).write(name.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(address.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(city.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(state.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(annualSalary.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(AddEmployeeCmd.footer);
- }
-}
diff --git a/test/com/directi/training/codesmells/duplicatecode/acrossclasses/LoginCommandTest.java b/test/com/directi/training/codesmells/duplicatecode/acrossclasses/LoginCommandTest.java
deleted file mode 100644
index ebdf959..0000000
--- a/test/com/directi/training/codesmells/duplicatecode/acrossclasses/LoginCommandTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.directi.training.codesmells.duplicatecode.acrossclasses;
-
-import org.junit.Test;
-
-import java.io.OutputStream;
-
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-public class LoginCommandTest
-{
- @Test
- public void testWrite() throws Exception
- {
- String userName = "Smith";
- String passwd = "qwedsa";
- LoginCommand loginCommand = new LoginCommand(userName, passwd);
- OutputStream outputStream = mock(OutputStream.class);
- loginCommand.write(outputStream);
- verify(outputStream).write(LoginCommand.header);
- verify(outputStream).write(19);
- verify(outputStream).write(LoginCommand.commandChar);
- verify(outputStream).write(userName.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(passwd.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(LoginCommand.footer);
- }
-}
diff --git a/test/com/directi/training/codesmells_refactored/duplicatecode/StatisticsTest.java b/test/com/directi/training/codesmells_refactored/duplicatecode/StatisticsTest.java
deleted file mode 100644
index abcedcf..0000000
--- a/test/com/directi/training/codesmells_refactored/duplicatecode/StatisticsTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.directi.training.codesmells_refactored.duplicatecode;
-
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public class StatisticsTest
-{
- @Test
- public void testCalculateDifferenceOfAverage()
- {
- Statistics statistics = new Statistics();
- double[] array1 = {1, 2, 3, 4, 5};
- double[] array2 = {11, 12, 13, 14, 15};
- double actualValue = statistics.calculateDifferenceOfAverage(array1, array2);
- assertThat(actualValue, is(10.0));
- }
-
- @Test
- public void testCalculateSampleVariance()
- {
- Statistics statistics = new Statistics();
- double[] elements = {1, 2, 3, 4, 5};
- double actualSampleVariance = statistics.calculateSampleVariance(elements);
- assertThat(actualSampleVariance, is(2.5));
- }
-}
diff --git a/test/com/directi/training/codesmells_refactored/duplicatecode/acrossclasses/AddEmployeeCmdTest.java b/test/com/directi/training/codesmells_refactored/duplicatecode/acrossclasses/AddEmployeeCmdTest.java
deleted file mode 100644
index f9048a5..0000000
--- a/test/com/directi/training/codesmells_refactored/duplicatecode/acrossclasses/AddEmployeeCmdTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.directi.training.codesmells_refactored.duplicatecode.acrossclasses;
-
-import org.junit.Test;
-
-import java.io.OutputStream;
-
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-public class AddEmployeeCmdTest
-{
- @Test
- public void testWrite() throws Exception
- {
- String name = "Smith";
- String address = "DirectI Plex";
- String city = "Mumbai";
- String state = "Maharashtra";
- String annualSalary = "10000000";
- AddEmployeeCmd addEmployeeCmd = new AddEmployeeCmd(name, address, city, state,
- annualSalary);
- OutputStream outputStream = mock(OutputStream.class);
- addEmployeeCmd.write(outputStream);
- verify(outputStream).write(AddEmployeeCmd.header);
- verify(outputStream).write(53);
- verify(outputStream).write(AddEmployeeCmd.commandChar);
- verify(outputStream).write(name.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(address.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(city.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(state.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(annualSalary.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(AddEmployeeCmd.footer);
- }
-}
diff --git a/test/com/directi/training/codesmells_refactored/duplicatecode/acrossclasses/LoginCommandTest.java b/test/com/directi/training/codesmells_refactored/duplicatecode/acrossclasses/LoginCommandTest.java
deleted file mode 100644
index 9df844d..0000000
--- a/test/com/directi/training/codesmells_refactored/duplicatecode/acrossclasses/LoginCommandTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.directi.training.codesmells_refactored.duplicatecode.acrossclasses;
-
-import org.junit.Test;
-
-import java.io.OutputStream;
-
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-public class LoginCommandTest
-{
- @Test
- public void testWrite() throws Exception
- {
- String userName = "Smith";
- String passwd = "qwedsa";
- LoginCommand loginCommand = new LoginCommand(userName, passwd);
- OutputStream outputStream = mock(OutputStream.class);
- loginCommand.write(outputStream);
- verify(outputStream).write(Command.header);
- verify(outputStream).write(19);
- verify(outputStream).write(Command.commandChar);
- verify(outputStream).write(userName.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(passwd.getBytes());
- verify(outputStream, atLeastOnce()).write(0x00);
- verify(outputStream).write(Command.footer);
- }
-}