Skip to content

4 #5

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

4 #5

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@
import sk.ableneo.openslava2023.donotfix.Product;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

// TODO: fix the class
public class BalloonChallenge {

public LinkedList findOrdersForProduct(Product p, boolean debug) {
ArrayList l = new ArrayList();
ArrayList list = getAllOrders();
public List<Order> findOrdersForProduct(Product p, boolean debug) {
List<Order> l = new ArrayList();
List<Order> list = getAllOrders();

for (int i = 0; i < list.size(); i++) {
Order order = (Order) list.get(i);
Order order = list.get(i);
boolean found = false;
if (order.getProducts().size() > 0) {
for (int j = 0; j <= order.getProducts().size(); j++) {
List<Product> products = order.getProducts();
if (products.size() > 0) {
for (int j = 0; j < order.getProducts().size(); j++) {
Product p2 = (Product) order.getProducts().get(j);
found = (p2 == p);
found = p2.equals(p);
}
if (found && order != null)
l.add(order);
}
}
return new LinkedList(l);
return l;
}

public ArrayList getAllOrders() {
return new ArrayList<Object>(OrderRepository.getAllOrders());
public List<Order> getAllOrders() {
return new ArrayList<Order>(OrderRepository.getAllOrders());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BalloonChallengeTest {
@BeforeEach
void setUp() {
when(balloonChallenge.getAllOrders()).thenReturn(
new ArrayList<Object>(Arrays.asList(
new ArrayList<Order>(Arrays.asList(
new Order(new ArrayList<>(Arrays.asList(new Product("hot air balloon")))),
new Order(new ArrayList<>(Arrays.asList(new Product("gas balloon")))),
new Order(new ArrayList<>(Arrays.asList(new Product("gas balloon"))))
Expand Down