📍Use lombok, reformat, and optimize the code (#1560)

* Use lombok, reformat, and optimize the code

* Fix merge conflicts and some sonar issues

Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
va1m
2021-03-13 13:19:21 +01:00
committed by GitHub
parent 0e26a6adb5
commit 5cf2fe009b
681 changed files with 2472 additions and 4966 deletions

View File

@ -24,8 +24,7 @@
package com.iluwatar.collectionpipeline;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* In imperative-style programming, it is common to use for and while loops for most kinds of data
@ -35,10 +34,9 @@ import org.slf4j.LoggerFactory;
* create sophisticated programs where data flow from upstream to downstream and is passed through a
* series of transformations.
*/
@Slf4j
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point.
*

View File

@ -23,86 +23,20 @@
package com.iluwatar.collectionpipeline;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* A Car class that has the properties of make, model, year and category.
*/
@Getter
@EqualsAndHashCode
@RequiredArgsConstructor
public class Car {
private final String make;
private final String model;
private final int year;
private final Category category;
/**
* Constructor to create an instance of car.
*
* @param make the make of the car
* @param model the model of the car
* @param yearOfMake the year of built of the car
* @param category the {@link Category} of the car
*/
public Car(String make, String model, int yearOfMake, Category category) {
this.make = make;
this.model = model;
this.year = yearOfMake;
this.category = category;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((category == null) ? 0 : category.hashCode());
result = prime * result + ((make == null) ? 0 : make.hashCode());
result = prime * result + ((model == null) ? 0 : model.hashCode());
result = prime * result + year;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Car other = (Car) obj;
if (category != other.category) {
return false;
}
if (make == null) {
if (other.make != null) {
return false;
}
} else if (!make.equals(other.make)) {
return false;
}
if (model == null) {
if (other.model != null) {
return false;
}
} else if (!model.equals(other.model)) {
return false;
}
return year == other.year;
}
public String getMake() {
return make;
}
public String getModel() {
return model;
}
public int getYear() {
return year;
}
public Category getCategory() {
return category;
}
}

View File

@ -27,5 +27,7 @@ package com.iluwatar.collectionpipeline;
* Enum for the category of car.
*/
public enum Category {
JEEP, SEDAN, CONVERTIBLE
JEEP,
SEDAN,
CONVERTIBLE
}

View File

@ -24,23 +24,16 @@
package com.iluwatar.collectionpipeline;
import java.util.List;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* A Person class that has the list of cars that the person owns and use.
*/
@Getter
@RequiredArgsConstructor
public class Person {
private final List<Car> cars;
/**
* Constructor to create an instance of person.
*
* @param cars the list of cars owned
*/
public Person(List<Car> cars) {
this.cars = cars;
}
public List<Car> getCars() {
return cars;
}
}

View File

@ -27,32 +27,31 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Tests that Collection Pipeline methods work as expected.
*/
public class AppTest {
private static final Logger LOGGER = LoggerFactory.getLogger(AppTest.class);
@Slf4j
class AppTest {
private final List<Car> cars = CarFactory.createCars();
@Test
public void testGetModelsAfter2000UsingFor() {
void testGetModelsAfter2000UsingFor() {
var models = ImperativeProgramming.getModelsAfter2000(cars);
assertEquals(List.of("Avenger", "Wrangler", "Focus", "Cascada"), models);
}
@Test
public void testGetModelsAfter2000UsingPipeline() {
void testGetModelsAfter2000UsingPipeline() {
var models = FunctionalProgramming.getModelsAfter2000(cars);
assertEquals(List.of("Avenger", "Wrangler", "Focus", "Cascada"), models);
}
@Test
public void testGetGroupingOfCarsByCategory() {
void testGetGroupingOfCarsByCategory() {
var modelsExpected = Map.of(
Category.CONVERTIBLE, List.of(
new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
@ -74,7 +73,7 @@ public class AppTest {
}
@Test
public void testGetSedanCarsOwnedSortedByDate() {
void testGetSedanCarsOwnedSortedByDate() {
var john = new Person(cars);
var modelsExpected = List.of(
new Car("Dodge", "Avenger", 2010, Category.SEDAN),