Added streams.
This commit is contained in:
28
streams/.project
Normal file
28
streams/.project
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>streams</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
<filteredResources>
|
||||||
|
<filter>
|
||||||
|
<id>1742997445640</id>
|
||||||
|
<name></name>
|
||||||
|
<type>30</type>
|
||||||
|
<matcher>
|
||||||
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
|
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
|
</matcher>
|
||||||
|
</filter>
|
||||||
|
</filteredResources>
|
||||||
|
</projectDescription>
|
2
streams/.settings/org.eclipse.core.resources.prefs
Normal file
2
streams/.settings/org.eclipse.core.resources.prefs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
11
streams/.settings/org.eclipse.jdt.core.prefs
Normal file
11
streams/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -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
|
95
streams/src/streams/Main.java
Normal file
95
streams/src/streams/Main.java
Normal file
@@ -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<LineItem> lineItems;
|
||||||
|
private final int customerIdOfPurchaser;
|
||||||
|
private final int numberOfDaysAgo;
|
||||||
|
|
||||||
|
public Purchase(
|
||||||
|
int id, List<LineItem> 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<LineItem> 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<Customer> getCustomerById(int id);
|
||||||
|
List<Customer> getAllCustomers();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface InventoryDB {
|
||||||
|
Optional<Inventory> getInventoryById(int id);
|
||||||
|
List<Inventory> getAllInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PurchaseDB {
|
||||||
|
Optional<Purchase> getPurchaseById(int id);
|
||||||
|
// get purchases made numberOfDaysAgo, numberOfDaysAgo - 1... today
|
||||||
|
List<Purchase> getPurchasesSince(int numberOfDaysAgo);
|
||||||
|
List<Purchase> getPurchasesFor(int customerId);
|
||||||
|
List<Purchase> getPurchasesFor(List<Integer> customerIds);
|
||||||
|
List<Purchase> getPurchasesForSince(int customerId, int numberOfDaysAgo);
|
||||||
|
List<Purchase>
|
||||||
|
getPurchasesForSince(List<Integer> customerIds, int numberOfDaysAgo);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Examples {}
|
Reference in New Issue
Block a user