Skip to content

Commit

Permalink
11
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelAbleneo authored and ktor committed Oct 27, 2023
1 parent 183bc9a commit 4c758b1
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@

import java.util.ArrayList;
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();
for (int i = 0; i < list.size(); i++) {
Order order = (Order) list.get(i);
boolean found = false;
if (order.getProducts().size() > 0) {
for (int j = 0; j <= order.getProducts().size(); j++) {
Product p2 = (Product) order.getProducts().get(j);
found = (p2 == p);
public List<Order> findOrdersForProduct(Product p, boolean debug) {
List<Order> res = new ArrayList<>();
List<Order> orders = getAllOrders();
for_order: for (Order order : orders) {
List<Product> ps = order.getProducts();
if (ps == null)
continue;
for (Product p2 : ps) {
if (p2.equals(p)) {
res.add(order);
continue for_order;
}
if (found && order != null)
l.add(order);
}
}
return new LinkedList(l);
return res;
}

public ArrayList getAllOrders() {
Expand Down

0 comments on commit 4c758b1

Please sign in to comment.