-
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
Pull_request_1 #918
base: master
Are you sure you want to change the base?
Pull_request_1 #918
Changes from all commits
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,11 +5,39 @@ | |
* Do not remove no-args constructor | ||
*/ | ||
public class Bulldozer extends Machine { | ||
private int bladeWidth; | ||
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 |
||
private int operatingWeight; | ||
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 |
||
private String engineType; | ||
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() { | ||
} | ||
|
||
@Override | ||
public void doWork() { | ||
System.out.println("Bulldozer started to work"); | ||
} | ||
|
||
public int getBladeWidth() { | ||
return bladeWidth; | ||
} | ||
|
||
public void setBladeWidth(int bladeWidth) { | ||
this.bladeWidth = bladeWidth; | ||
} | ||
|
||
public int getOperatingWeight() { | ||
return operatingWeight; | ||
} | ||
|
||
public void setOperatingWeight(int operatingWeight) { | ||
this.operatingWeight = operatingWeight; | ||
} | ||
|
||
public String getEngineType() { | ||
return engineType; | ||
} | ||
|
||
public void setEngineType(String engineType) { | ||
this.engineType = engineType; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,39 @@ | |
* 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. Don't forget about access modifiers for your custom fields in |
||
private int cargoCapacity; | ||
private int numberOfAxles; | ||
private String fuelType; | ||
|
||
public Truck() { | ||
} | ||
|
||
@Override | ||
public void doWork() { | ||
System.out.println("Truck started to work"); | ||
} | ||
|
||
public int getCargoCapacity() { | ||
return cargoCapacity; | ||
} | ||
|
||
public void setCargoCapacity(int cargoCapacity) { | ||
this.cargoCapacity = cargoCapacity; | ||
} | ||
|
||
public int getNumberOfAxles() { | ||
return numberOfAxles; | ||
} | ||
|
||
public void setNumberOfAxles(int numberOfAxles) { | ||
this.numberOfAxles = numberOfAxles; | ||
} | ||
|
||
public String getFuelType() { | ||
return fuelType; | ||
} | ||
|
||
public void setFuelType(String fuelType) { | ||
this.fuelType = fuelType; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package core.mate.academy.service; | ||
|
||
import core.mate.academy.model.Bulldozer; | ||
import java.util.List; | ||
|
||
public class BulldozerProducer implements MachineProducer<Bulldozer> { | ||
|
||
@Override | ||
public List<Bulldozer> get() { | ||
return List.of(new Bulldozer(), new Bulldozer(), new Bulldozer()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package core.mate.academy.service; | ||
|
||
import core.mate.academy.model.Excavator; | ||
import java.util.List; | ||
|
||
public class ExcavatorProducer implements MachineProducer<Excavator> { | ||
|
||
@Override | ||
public List<Excavator> get() { | ||
return List.of(new Excavator(), new Excavator(), new Excavator()); | ||
} | ||
} |
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; | ||
|
||
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
/** | ||
* Parameterize this service and add its implementation in a separate class. | ||
*/ | ||
public interface MachineService { | ||
public interface MachineService<T> { | ||
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 interface or method implementation with an empty line. |
||
|
||
/** | ||
* Return the list of machines. | ||
|
@@ -16,7 +16,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<T> getAll(Class<? extends T> type); | ||
|
||
/** | ||
* Fill the machines list with passed value | ||
|
@@ -26,13 +26,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); | ||
|
||
/** | ||
* 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 T> machines); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,46 @@ | ||
package core.mate.academy.service; | ||
|
||
import core.mate.academy.model.Bulldozer; | ||
import core.mate.academy.model.Excavator; | ||
import core.mate.academy.model.Machine; | ||
import core.mate.academy.model.Truck; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Your implementation of MachineService. | ||
*/ | ||
public class MachineServiceImpl { | ||
public class MachineServiceImpl implements MachineService<Machine> { | ||
@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 |
||
List<Machine> machineList = new ArrayList<>(); | ||
|
||
if (type == Bulldozer.class) { | ||
BulldozerProducer bulldozerProducer = new BulldozerProducer(); | ||
machineList.addAll(bulldozerProducer.get()); | ||
} | ||
|
||
if (type == Excavator.class) { | ||
ExcavatorProducer excavatorProducer = new ExcavatorProducer(); | ||
machineList.addAll(excavatorProducer.get()); | ||
} | ||
|
||
if (type == Truck.class) { | ||
TruckProducer truckProducer = new TruckProducer(); | ||
machineList.addAll(truckProducer.get()); | ||
} | ||
return machineList; | ||
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. Keep if else constructions simple. Here, since each 'if' block contains a return statement, the subsequent 'if' statements can be changed to 'else if' to prevent unnecessary checks once a match is found. |
||
} | ||
|
||
@Override | ||
public void fill(List<? super Machine> machines, Machine value) { | ||
Collections.fill(machines, 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 size of a list passed to |
||
|
||
@Override | ||
public void startWorking(List<? extends Machine> machines) { | ||
machines.forEach(Machine::doWork); | ||
|
||
} | ||
} | ||
Comment on lines
+14
to
46
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 (lines 11-13). It would be better to remove these to comply with the checklist. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package core.mate.academy.service; | ||
|
||
import core.mate.academy.model.Truck; | ||
import java.util.List; | ||
|
||
public class TruckProducer implements MachineProducer<Truck> { | ||
|
||
@Override | ||
public List<Truck> get() { | ||
return List.of(new Truck(), new Truck(), new Truck()); | ||
} | ||
} |
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 an empty line. Please remove the unnecessary empty lines (lines 3-6) to comply with the checklist.