-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created nessesery classes, changed Objects to PECS. #901
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,10 @@ | |
* Do not remove no-args constructor | ||
*/ | ||
public class Bulldozer extends Machine { | ||
private int fuelConsuptionPerHour; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget about access modifiers for your custom fields in |
||
|
||
public Bulldozer() { | ||
this.fuelConsuptionPerHour = 40; | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package core.mate.academy.model; | ||
|
||
import core.mate.academy.service.MachineProducer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class BulldozerProducer implements MachineProducer<Bulldozer> { | ||
|
||
@Override | ||
public List<Bulldozer> get() { | ||
List<Bulldozer> bulldozer = new ArrayList<>(); | ||
|
||
bulldozer.add(new Bulldozer()); | ||
bulldozer.add(new Bulldozer()); | ||
bulldozer.add(new Bulldozer()); | ||
|
||
return bulldozer; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,10 @@ | |
* Do not remove no-args constructor | ||
*/ | ||
public class Excavator extends Machine { | ||
private int shovelSize; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget about access modifiers for your custom fields in |
||
|
||
public Excavator() { | ||
this.shovelSize = 10; | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package core.mate.academy.model; | ||
|
||
import core.mate.academy.service.MachineProducer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ExcavatorProducer implements MachineProducer<Excavator> { | ||
|
||
@Override | ||
public List<Excavator> get() { | ||
List<Excavator> excavator = new ArrayList<>(); | ||
|
||
excavator.add(new Excavator()); | ||
excavator.add(new Excavator()); | ||
excavator.add(new Excavator()); | ||
|
||
return excavator; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,10 @@ | |
* Do not remove no-field constructor | ||
*/ | ||
public class Truck extends Machine { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the checklist, you should never want to expose the object fields directly. They should be accessed through special methods (getters and setters). Please add getter and setter methods for the |
||
private int maxCapacity; | ||
|
||
public Truck() { | ||
this.maxCapacity = 5000; | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package core.mate.academy.model; | ||
|
||
import core.mate.academy.service.MachineProducer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TruckProducer implements MachineProducer<Truck> { | ||
|
||
@Override | ||
public List<Truck> get() { | ||
List<Truck> truck = new ArrayList<>(); | ||
|
||
truck.add(new Truck()); | ||
truck.add(new Truck()); | ||
truck.add(new Truck()); | ||
|
||
return truck; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package core.mate.academy.service; | ||
|
||
import core.mate.academy.model.Machine; | ||
import java.util.List; | ||
|
||
public interface MachineProducer { | ||
public interface MachineProducer<T extends Machine> { | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't begin class or method implementation with an empty line. |
||
* In your implementations - create 2-3 models, add them to the list and return | ||
* | ||
* @return - the list of models | ||
*/ | ||
List<Object> get(); | ||
List<T> get(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package core.mate.academy.service; | ||
|
||
import core.mate.academy.model.Machine; | ||
import java.util.List; | ||
|
||
/** | ||
* Parameterize this service and add its implementation in a separate class. | ||
*/ | ||
public interface MachineService { | ||
public interface MachineService<T extends Machine> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't begin class or method implementation with empty lines. Remove the unnecessary empty lines before the interface declaration. |
||
|
||
/** | ||
* Return the list of machines. | ||
|
@@ -16,7 +17,7 @@ public interface MachineService { | |
* @param type - any class of Machine sub class. For example: Truck.class or Bulldozer.class | ||
* @return the list of machines | ||
*/ | ||
List<Object> getAll(Class type); | ||
List<Machine> getAll(Class<? extends Machine> type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not use raw types. You should parameterize the return type of |
||
|
||
/** | ||
* Fill the machines list with passed value | ||
|
@@ -26,13 +27,13 @@ public interface MachineService { | |
* @param machines - list of machines to be filled with value | ||
* @param value - any object of machine sub class | ||
*/ | ||
void fill(List<Object> machines, Object value); | ||
void fill(List<? super T> machines, T value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
/** | ||
* Call the method doWork() from each machine. | ||
* This method should be able to accept a list of bulldozers as well as list of trucks. | ||
* | ||
* @param machines - the list of machines | ||
*/ | ||
void startWorking(List<Object> machines); | ||
void startWorking(List<? extends Machine> machines); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,50 @@ | ||
package core.mate.academy.service; | ||
|
||
import core.mate.academy.model.Bulldozer; | ||
import core.mate.academy.model.BulldozerProducer; | ||
import core.mate.academy.model.Excavator; | ||
import core.mate.academy.model.ExcavatorProducer; | ||
import core.mate.academy.model.Machine; | ||
import core.mate.academy.model.Truck; | ||
import core.mate.academy.model.TruckProducer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Your implementation of MachineService. | ||
*/ | ||
public class MachineServiceImpl { | ||
public class MachineServiceImpl implements MachineService<Machine> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't begin class or method implementation with empty lines. There are unnecessary empty lines at the start of the class implementation. |
||
|
||
@Override | ||
public List<Machine> getAll(Class<? extends Machine> type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider creating a local variable in your implementation of |
||
MachineProducer<? extends Machine> producer; | ||
|
||
if (type == Bulldozer.class) { | ||
producer = new BulldozerProducer(); | ||
} else if (type == Excavator.class) { | ||
producer = new ExcavatorProducer(); | ||
} else if (type == Truck.class) { | ||
producer = new TruckProducer(); | ||
} else { | ||
return new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't return null or specific type List in |
||
} | ||
|
||
List<? extends Machine> specifyMachines = producer.get(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to have a separate variable |
||
List<Machine> allMachines = new ArrayList<>(specifyMachines); | ||
return allMachines; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable |
||
} | ||
|
||
@Override | ||
public void fill(List<? super Machine> machines, Machine value) { | ||
for (int i = 0; i < machines.size(); i++) { | ||
machines.set(i, value); | ||
} | ||
} | ||
|
||
@Override | ||
public void startWorking(List<? extends Machine> machines) { | ||
for (Machine element : machines) { | ||
element.doWork(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't begin class or method implementation with empty lines. Remove the unnecessary empty lines between the package declaration and the class declaration.