From 3fb6413becc388c5c3592319d6ecf5df1c23dd7d Mon Sep 17 00:00:00 2001 From: Jacob Signorovitch Date: Wed, 26 Mar 2025 10:01:31 -0400 Subject: [PATCH] Added streams. --- streams/.project | 28 ++++++ .../org.eclipse.core.resources.prefs | 2 + streams/.settings/org.eclipse.jdt.core.prefs | 11 +++ streams/src/streams/Main.java | 95 +++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 streams/.project create mode 100644 streams/.settings/org.eclipse.core.resources.prefs create mode 100644 streams/.settings/org.eclipse.jdt.core.prefs create mode 100644 streams/src/streams/Main.java diff --git a/streams/.project b/streams/.project new file mode 100644 index 0000000..ed1c7c2 --- /dev/null +++ b/streams/.project @@ -0,0 +1,28 @@ + + + streams + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + + + 1742997445640 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/streams/.settings/org.eclipse.core.resources.prefs b/streams/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/streams/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/streams/.settings/org.eclipse.jdt.core.prefs b/streams/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9a7984b --- /dev/null +++ b/streams/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=21 diff --git a/streams/src/streams/Main.java b/streams/src/streams/Main.java new file mode 100644 index 0000000..6ea1657 --- /dev/null +++ b/streams/src/streams/Main.java @@ -0,0 +1,95 @@ +package streams; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import tester.Tester; + +class Customer { + private final int id; + private final String name; + + public Customer(int id, String name) { + this.id = id; + this.name = name; + } + + public int getId() { return this.id; } + public String getName() { return this.name; } +} + +class Inventory { + private final int id; + private final String description; + private final int costPerUnit; + + public Inventory(int id, String description, int costPerUnit) { + this.id = id; + this.description = description; + this.costPerUnit = costPerUnit; + } + + public int getId() { return this.id; } + public String getDescription() { return this.description; } + public int getCostPerUnit() { return this.costPerUnit; } +} + +class Purchase { + private final int id; + private final List lineItems; + private final int customerIdOfPurchaser; + private final int numberOfDaysAgo; + + public Purchase( + int id, List lineItems, int customerIdOfPurchaser, + int numberOfDaysAgo + ) { + this.id = id; + this.lineItems = new ArrayList<>(lineItems); + this.customerIdOfPurchaser = customerIdOfPurchaser; + this.numberOfDaysAgo = numberOfDaysAgo; + } + + public int getId() { return this.id; } + public List getLineItems() { return this.lineItems; } + public int getCustomerIdOfPurchaser() { return this.customerIdOfPurchaser; } + public int getNumberOfDaysAgo() { return this.numberOfDaysAgo; } +} + +class LineItem { + private final int inventoryId; + private final int numberOfItemsPurchased; + + public LineItem(int inventoryId, int numberOfItemsPurchased) { + this.inventoryId = inventoryId; + this.numberOfItemsPurchased = numberOfItemsPurchased; + } + + public int getInventoryId() { return this.inventoryId; } + public int getNumberOfItemsPurchased() { + return this.numberOfItemsPurchased; + } +} + +interface CustomerDB { + Optional getCustomerById(int id); + List getAllCustomers(); +} + +interface InventoryDB { + Optional getInventoryById(int id); + List getAllInventory(); +} + +interface PurchaseDB { + Optional getPurchaseById(int id); + // get purchases made numberOfDaysAgo, numberOfDaysAgo - 1... today + List getPurchasesSince(int numberOfDaysAgo); + List getPurchasesFor(int customerId); + List getPurchasesFor(List customerIds); + List getPurchasesForSince(int customerId, int numberOfDaysAgo); + List + getPurchasesForSince(List customerIds, int numberOfDaysAgo); +} + +class Examples {}