modelit 0.2.4__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. modelit-0.2.5/MANIFEST.in +1 -0
  2. {modelit-0.2.4 → modelit-0.2.5}/PKG-INFO +7 -1
  3. {modelit-0.2.4 → modelit-0.2.5}/README.md +6 -0
  4. {modelit-0.2.4 → modelit-0.2.5}/modelit/registry.py +29 -9
  5. modelit-0.2.5/modelit/templates/abstract_factory_pattern/template.java +44 -0
  6. modelit-0.2.5/modelit/templates/adapter_pattern/template.java +25 -0
  7. modelit-0.2.5/modelit/templates/bridge_pattern/template.java +54 -0
  8. modelit-0.2.5/modelit/templates/builder_pattern/template.java +58 -0
  9. modelit-0.2.5/modelit/templates/command_pattern/template.java +58 -0
  10. modelit-0.2.5/modelit/templates/composite_pattern/template.java +53 -0
  11. modelit-0.2.5/modelit/templates/decorator_pattern/template.java +39 -0
  12. modelit-0.2.5/modelit/templates/facade_pattern/template.java +42 -0
  13. modelit-0.2.5/modelit/templates/factory_pattern/template.java +36 -0
  14. modelit-0.2.5/modelit/templates/flyweight_pattern/template.java +47 -0
  15. modelit-0.2.5/modelit/templates/interpreter_pattern/template.java +36 -0
  16. modelit-0.2.5/modelit/templates/mediator_pattern/template.java +62 -0
  17. modelit-0.2.5/modelit/templates/memento_pattern/template.java +50 -0
  18. modelit-0.2.5/modelit/templates/observer_pattern/template.java +47 -0
  19. modelit-0.2.5/modelit/templates/prototype_pattern/template.java +38 -0
  20. modelit-0.2.5/modelit/templates/proxy_pattern/template.java +48 -0
  21. modelit-0.2.5/modelit/templates/state_pattern/template.java +40 -0
  22. modelit-0.2.5/modelit/templates/template_pattern/template.java +40 -0
  23. modelit-0.2.5/modelit/templates/visitor_pattern/template.java +42 -0
  24. {modelit-0.2.4 → modelit-0.2.5}/modelit.egg-info/PKG-INFO +7 -1
  25. modelit-0.2.5/modelit.egg-info/SOURCES.txt +39 -0
  26. {modelit-0.2.4 → modelit-0.2.5}/pyproject.toml +1 -1
  27. modelit-0.2.4/MANIFEST.in +0 -1
  28. modelit-0.2.4/modelit.egg-info/SOURCES.txt +0 -20
  29. {modelit-0.2.4 → modelit-0.2.5}/.github/workflows/publish.yml +0 -0
  30. {modelit-0.2.4 → modelit-0.2.5}/.github/workflows/test.yml +0 -0
  31. {modelit-0.2.4 → modelit-0.2.5}/.gitignore +0 -0
  32. {modelit-0.2.4 → modelit-0.2.5}/CONTRIBUTING.md +0 -0
  33. {modelit-0.2.4 → modelit-0.2.5}/LICENSE +0 -0
  34. {modelit-0.2.4 → modelit-0.2.5}/modelit/__init__.py +0 -0
  35. {modelit-0.2.4 → modelit-0.2.5}/modelit/__main__.py +0 -0
  36. {modelit-0.2.4 → modelit-0.2.5}/modelit/cli.py +0 -0
  37. {modelit-0.2.4 → modelit-0.2.5}/modelit/templates/backpropagation/template.py +0 -0
  38. {modelit-0.2.4 → modelit-0.2.5}/modelit/templates/cnn/template.py +0 -0
  39. {modelit-0.2.4 → modelit-0.2.5}/modelit/templates/perceptron/template.py +0 -0
  40. {modelit-0.2.4 → modelit-0.2.5}/modelit.egg-info/dependency_links.txt +0 -0
  41. {modelit-0.2.4 → modelit-0.2.5}/modelit.egg-info/entry_points.txt +0 -0
  42. {modelit-0.2.4 → modelit-0.2.5}/modelit.egg-info/top_level.txt +0 -0
  43. {modelit-0.2.4 → modelit-0.2.5}/setup.cfg +0 -0
@@ -0,0 +1 @@
1
+ recursive-include modelit/templates *.py *.java *.json
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modelit
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: Local-first ML starter templates you can print or save
5
5
  Author: Yashsmith
6
6
  License-Expression: MIT
@@ -86,6 +86,12 @@ modelit/templates/mycode/
86
86
  modelit/templates/mycode/template.py
87
87
  ```
88
88
 
89
+ For Java, use:
90
+
91
+ ```text
92
+ modelit/templates/mycode/template.java
93
+ ```
94
+
89
95
  3. Done. The folder name becomes the function name.
90
96
 
91
97
  That means this will work automatically:
@@ -66,6 +66,12 @@ modelit/templates/mycode/
66
66
  modelit/templates/mycode/template.py
67
67
  ```
68
68
 
69
+ For Java, use:
70
+
71
+ ```text
72
+ modelit/templates/mycode/template.java
73
+ ```
74
+
69
75
  3. Done. The folder name becomes the function name.
70
76
 
71
77
  That means this will work automatically:
@@ -9,7 +9,6 @@ from pathlib import Path
9
9
 
10
10
  PACKAGE_NAME = "modelit"
11
11
  TEMPLATES_DIR = "templates"
12
- TEMPLATE_FILENAME = "template.py"
13
12
 
14
13
 
15
14
  @dataclass(frozen=True)
@@ -25,6 +24,19 @@ def _template_dir(name: str):
25
24
  return _templates_root().joinpath(name)
26
25
 
27
26
 
27
+ def _get_template_file(name_or_dir):
28
+ target_dir = _template_dir(name_or_dir) if isinstance(name_or_dir, str) else name_or_dir
29
+
30
+ if not target_dir.is_dir():
31
+ return None
32
+
33
+ for child in target_dir.iterdir():
34
+ if child.is_file() and child.name.startswith("template."):
35
+ return child
36
+
37
+ return None
38
+
39
+
28
40
  def available_models() -> tuple[str, ...]:
29
41
  root = _templates_root()
30
42
  if not root.is_dir():
@@ -32,7 +44,7 @@ def available_models() -> tuple[str, ...]:
32
44
 
33
45
  names: list[str] = []
34
46
  for child in root.iterdir():
35
- if child.is_dir() and child.joinpath(TEMPLATE_FILENAME).is_file():
47
+ if child.is_dir() and _get_template_file(child) is not None:
36
48
  names.append(child.name)
37
49
  return tuple(sorted(names))
38
50
 
@@ -41,17 +53,25 @@ def load_metadata(name: str) -> TemplateInfo:
41
53
  return TemplateInfo(name=name)
42
54
 
43
55
 
44
- def load_source(name: str) -> str:
45
- source_path = _template_dir(name).joinpath(TEMPLATE_FILENAME)
46
- if not source_path.is_file():
56
+ def load_source_and_ext(name: str) -> tuple[str, str]:
57
+ template_file = _get_template_file(name)
58
+ if template_file is None:
47
59
  raise FileNotFoundError(f"Missing template source for {name!r}")
48
- return source_path.read_text(encoding="utf-8")
60
+
61
+ ext = Path(template_file.name).suffix
62
+ return template_file.read_text(encoding="utf-8"), ext
63
+
64
+
65
+ def load_source(name: str) -> str:
66
+ source, _ = load_source_and_ext(name)
67
+ return source
49
68
 
50
69
 
51
70
  def build_template_callable(name: str):
52
- source = load_source(name)
71
+ source, ext = load_source_and_ext(name)
53
72
  info = load_metadata(name)
54
- output_file = f"{name}.py"
73
+
74
+ output_file = f"{name}{ext}"
55
75
 
56
76
  def runner(output: str | None = None) -> None:
57
77
  if output:
@@ -71,4 +91,4 @@ def build_template_callable(name: str):
71
91
  runner.__doc__ = f"Print or save the {name} template."
72
92
  runner.output_file = output_file # type: ignore[attr-defined]
73
93
  runner.template_info = info # type: ignore[attr-defined]
74
- return runner
94
+ return runner
@@ -0,0 +1,44 @@
1
+ interface Button { void render(); }
2
+ interface Checkbox { void render(); }
3
+
4
+ class WinButton implements Button {
5
+ public void render() { System.out.println("Rendering Windows Button"); }
6
+ }
7
+ class MacButton implements Button {
8
+ public void render() { System.out.println("Rendering macOS Button"); }
9
+ }
10
+
11
+ class WinCheckbox implements Checkbox {
12
+ public void render() { System.out.println("Rendering Windows Checkbox"); }
13
+ }
14
+ class MacCheckbox implements Checkbox {
15
+ public void render() { System.out.println("Rendering macOS Checkbox"); }
16
+ }
17
+
18
+ interface GUIFactory {
19
+ Button createButton();
20
+ Checkbox createCheckbox();
21
+ }
22
+
23
+ class WindowsFactory implements GUIFactory {
24
+ public Button createButton() { return new WinButton(); }
25
+ public Checkbox createCheckbox() { return new WinCheckbox(); }
26
+ }
27
+
28
+ class MacOSFactory implements GUIFactory {
29
+ public Button createButton() { return new MacButton(); }
30
+ public Checkbox createCheckbox() { return new MacCheckbox(); }
31
+ }
32
+
33
+ public class AbstractFactoryDemo {
34
+ public static void main(String[] args) {
35
+ String os = "Mac";
36
+ GUIFactory factory = os.equals("Mac") ? new MacOSFactory() : new WindowsFactory();
37
+
38
+ Button button = factory.createButton();
39
+ Checkbox checkbox = factory.createCheckbox();
40
+
41
+ button.render();
42
+ checkbox.render();
43
+ }
44
+ }
@@ -0,0 +1,25 @@
1
+ interface PaymentProcessor {
2
+ void processPayment(double amount);
3
+ }
4
+
5
+ class StripeService {
6
+ public void makePayment(double amountInCents) {
7
+ System.out.println("Stripe: Processing payment of " + amountInCents + " cents successfully.");
8
+ }
9
+ }
10
+
11
+ class StripeAdapter implements PaymentProcessor {
12
+ private StripeService stripeService = new StripeService();
13
+
14
+ public void processPayment(double amount) {
15
+ double amountInCents = amount * 100;
16
+ stripeService.makePayment(amountInCents);
17
+ }
18
+ }
19
+
20
+ public class AdapterDemo {
21
+ public static void main(String[] args) {
22
+ PaymentProcessor processor = new StripeAdapter();
23
+ processor.processPayment(50.00);
24
+ }
25
+ }
@@ -0,0 +1,54 @@
1
+ interface Device {
2
+ void turnOn();
3
+ void turnOff();
4
+ void setVolume(int percent);
5
+ }
6
+
7
+ class SmartTV implements Device {
8
+ private int volume = 30;
9
+ public void turnOn() { System.out.println("Smart TV is ON"); }
10
+ public void turnOff() { System.out.println("Smart TV is OFF"); }
11
+ public void setVolume(int percent) {
12
+ volume = percent;
13
+ System.out.println("Smart TV Volume set to " + volume);
14
+ }
15
+ }
16
+
17
+ abstract class RemoteControl {
18
+ protected Device device;
19
+ public RemoteControl(Device device) { this.device = device; }
20
+ public abstract void togglePower();
21
+ }
22
+
23
+ class BasicRemote extends RemoteControl {
24
+ public BasicRemote(Device device) { super(device); }
25
+ public void togglePower() {
26
+ System.out.println("\n[Basic Remote Used]");
27
+ device.turnOn();
28
+ }
29
+ }
30
+
31
+ class AdvancedRemote extends RemoteControl {
32
+ public AdvancedRemote(Device device) { super(device); }
33
+ public void togglePower() {
34
+ System.out.println("\n[Advanced Remote Used]");
35
+ device.turnOn();
36
+ }
37
+ public void mute() {
38
+ System.out.println("Muting Device...");
39
+ device.setVolume(0);
40
+ }
41
+ }
42
+
43
+ public class BridgeDemo {
44
+ public static void main(String[] args) {
45
+ Device tv = new SmartTV();
46
+
47
+ BasicRemote basicRemote = new BasicRemote(tv);
48
+ basicRemote.togglePower();
49
+
50
+ AdvancedRemote advancedRemote = new AdvancedRemote(tv);
51
+ advancedRemote.togglePower();
52
+ advancedRemote.mute();
53
+ }
54
+ }
@@ -0,0 +1,58 @@
1
+ class UserProfile {
2
+ private final String username;
3
+ private final String email;
4
+ private final int age;
5
+ private final String phone;
6
+
7
+ private UserProfile(Builder builder) {
8
+ this.username = builder.username;
9
+ this.email = builder.email;
10
+ this.age = builder.age;
11
+ this.phone = builder.phone;
12
+ }
13
+
14
+ public void showProfile() {
15
+ System.out.println("User: " + username + " | Email: " + email + " | Age: " + age + " | Phone: " + phone);
16
+ }
17
+
18
+ static class Builder {
19
+ private String username;
20
+ private String email;
21
+ private int age = 0;
22
+ private String phone = "N/A";
23
+
24
+ public Builder(String username, String email) {
25
+ this.username = username;
26
+ this.email = email;
27
+ }
28
+
29
+ public Builder setAge(int age) {
30
+ this.age = age;
31
+ return this;
32
+ }
33
+
34
+ public Builder setPhone(String phone) {
35
+ this.phone = phone;
36
+ return this;
37
+ }
38
+
39
+ public UserProfile build() {
40
+ return new UserProfile(this);
41
+ }
42
+ }
43
+ }
44
+
45
+ public class BuilderDemo {
46
+ public static void main(String[] args) {
47
+ UserProfile user1 = new UserProfile.Builder("user", "user@example.com")
48
+ .setAge(21)
49
+ .build();
50
+
51
+ UserProfile user2 = new UserProfile.Builder("admin_user", "admin@sys.com")
52
+ .setPhone("+91-9876543210")
53
+ .build();
54
+
55
+ user1.showProfile();
56
+ user2.showProfile();
57
+ }
58
+ }
@@ -0,0 +1,58 @@
1
+ import java.util.Stack;
2
+
3
+ class BankAccount {
4
+ private int balance = 1000;
5
+ public void deposit(int amount) {
6
+ balance += amount;
7
+ System.out.println("Deposited $" + amount + ". Current Balance: $" + balance);
8
+ }
9
+ public void withdraw(int amount) {
10
+ balance -= amount;
11
+ System.out.println("Withdrew $" + amount + ". Current Balance: $" + balance);
12
+ }
13
+ }
14
+
15
+ interface TransactionCommand {
16
+ void execute();
17
+ void undo();
18
+ }
19
+
20
+ class DepositCommand implements TransactionCommand {
21
+ private BankAccount account;
22
+ private int amount;
23
+
24
+ public DepositCommand(BankAccount account, int amount) {
25
+ this.account = account;
26
+ this.amount = amount;
27
+ }
28
+ public void execute() { account.deposit(amount); }
29
+ public void undo() { account.withdraw(amount); }
30
+ }
31
+
32
+ class TransactionManager {
33
+ private Stack<TransactionCommand> history = new Stack<>();
34
+
35
+ public void executeTransaction(TransactionCommand command) {
36
+ command.execute();
37
+ history.push(command);
38
+ }
39
+ public void undoLastTransaction() {
40
+ if (!history.isEmpty()) {
41
+ System.out.print("Undoing last transaction... ");
42
+ TransactionCommand lastCommand = history.pop();
43
+ lastCommand.undo();
44
+ }
45
+ }
46
+ }
47
+
48
+ public class CommandDemo {
49
+ public static void main(String[] args) {
50
+ BankAccount myAccount = new BankAccount();
51
+ TransactionManager manager = new TransactionManager();
52
+
53
+ manager.executeTransaction(new DepositCommand(myAccount, 500));
54
+ manager.executeTransaction(new DepositCommand(myAccount, 200));
55
+
56
+ manager.undoLastTransaction();
57
+ }
58
+ }
@@ -0,0 +1,53 @@
1
+ import java.util.ArrayList;
2
+ import java.util.List;
3
+
4
+ interface FileSystemComponent {
5
+ void showDetails();
6
+ int getSize();
7
+ }
8
+
9
+ class File implements FileSystemComponent {
10
+ private String name;
11
+ private int size;
12
+
13
+ public File(String name, int size) { this.name = name; this.size = size; }
14
+ public void showDetails() { System.out.println(" File: " + name + " (" + size + " KB)"); }
15
+ public int getSize() { return size; }
16
+ }
17
+
18
+ class Directory implements FileSystemComponent {
19
+ private String name;
20
+ private List<FileSystemComponent> components = new ArrayList<>();
21
+
22
+ public Directory(String name) { this.name = name; }
23
+ public void addComponent(FileSystemComponent component) { components.add(component); }
24
+
25
+ public void showDetails() {
26
+ System.out.println("Directory: " + name + " | Total Size: " + getSize() + " KB");
27
+ for (FileSystemComponent component : components) {
28
+ component.showDetails();
29
+ }
30
+ }
31
+
32
+ public int getSize() {
33
+ return components.stream().mapToInt(FileSystemComponent::getSize).sum();
34
+ }
35
+ }
36
+
37
+ public class CompositeDemo {
38
+ public static void main(String[] args) {
39
+ File file1 = new File("resume.pdf", 500);
40
+ File file2 = new File("photo.png", 1500);
41
+ File file3 = new File("system_config.txt", 15);
42
+
43
+ Directory personalDir = new Directory("Personal Files");
44
+ personalDir.addComponent(file1);
45
+ personalDir.addComponent(file2);
46
+
47
+ Directory rootDir = new Directory("Root");
48
+ rootDir.addComponent(personalDir);
49
+ rootDir.addComponent(file3);
50
+
51
+ rootDir.showDetails();
52
+ }
53
+ }
@@ -0,0 +1,39 @@
1
+ interface Coffee {
2
+ String getDescription();
3
+ double getCost();
4
+ }
5
+
6
+ class Espresso implements Coffee {
7
+ public String getDescription() { return "Espresso"; }
8
+ public double getCost() { return 150.0; }
9
+ }
10
+
11
+ abstract class CoffeeDecorator implements Coffee {
12
+ protected Coffee decoratedCoffee;
13
+ public CoffeeDecorator(Coffee coffee) { this.decoratedCoffee = coffee; }
14
+ public String getDescription() { return decoratedCoffee.getDescription(); }
15
+ public double getCost() { return decoratedCoffee.getCost(); }
16
+ }
17
+
18
+ class MilkDecorator extends CoffeeDecorator {
19
+ public MilkDecorator(Coffee coffee) { super(coffee); }
20
+ public String getDescription() { return super.getDescription() + ", Steamed Milk"; }
21
+ public double getCost() { return super.getCost() + 30.0; }
22
+ }
23
+
24
+ class CaramelDecorator extends CoffeeDecorator {
25
+ public CaramelDecorator(Coffee coffee) { super(coffee); }
26
+ public String getDescription() { return super.getDescription() + ", Caramel Syrup"; }
27
+ public double getCost() { return super.getCost() + 45.0; }
28
+ }
29
+
30
+ public class DecoratorDemo {
31
+ public static void main(String[] args) {
32
+ Coffee myOrder = new Espresso();
33
+ myOrder = new MilkDecorator(myOrder);
34
+ myOrder = new CaramelDecorator(myOrder);
35
+
36
+ System.out.println("Order Details: " + myOrder.getDescription());
37
+ System.out.println("Total Cost: ₹" + myOrder.getCost());
38
+ }
39
+ }
@@ -0,0 +1,42 @@
1
+ class LightingSystem {
2
+ void turnOn() { System.out.println("Lights: ON (Dimming to 50%)"); }
3
+ void turnOff() { System.out.println("Lights: OFF"); }
4
+ }
5
+
6
+ class CoolingSystem {
7
+ void setTemp(int temp) { System.out.println("AC: ON & Set to " + temp + "°C"); }
8
+ void turnOff() { System.out.println("AC: OFF"); }
9
+ }
10
+
11
+ class SecuritySystem {
12
+ void arm() { System.out.println("Security: ARMED"); }
13
+ void disarm() { System.out.println("Security: DISARMED"); }
14
+ }
15
+
16
+ class SmartHomeFacade {
17
+ private LightingSystem light = new LightingSystem();
18
+ private CoolingSystem ac = new CoolingSystem();
19
+ private SecuritySystem security = new SecuritySystem();
20
+
21
+ public void arriveHome() {
22
+ System.out.println("\n--- Entering Home Mode ---");
23
+ security.disarm();
24
+ light.turnOn();
25
+ ac.setTemp(22);
26
+ }
27
+
28
+ public void leaveHome() {
29
+ System.out.println("\n--- Leaving Home Mode ---");
30
+ ac.turnOff();
31
+ light.turnOff();
32
+ security.arm();
33
+ }
34
+ }
35
+
36
+ public class FacadeDemo {
37
+ public static void main(String[] args) {
38
+ SmartHomeFacade homeApp = new SmartHomeFacade();
39
+ homeApp.arriveHome();
40
+ homeApp.leaveHome();
41
+ }
42
+ }
@@ -0,0 +1,36 @@
1
+ interface Notification {
2
+ void notifyUser();
3
+ }
4
+
5
+ class SMSNotification implements Notification {
6
+ public void notifyUser() {
7
+ System.out.println("Sending SMS Notification...");
8
+ }
9
+ }
10
+
11
+ class EmailNotification implements Notification {
12
+ public void notifyUser() {
13
+ System.out.println("Sending Email Notification...");
14
+ }
15
+ }
16
+
17
+ class NotificationFactory {
18
+ public Notification createNotification(String channel) {
19
+ if (channel == null || channel.isEmpty()) return null;
20
+ if (channel.equalsIgnoreCase("SMS")) return new SMSNotification();
21
+ if (channel.equalsIgnoreCase("EMAIL")) return new EmailNotification();
22
+ return null;
23
+ }
24
+ }
25
+
26
+ public class FactoryPatternDemo {
27
+ public static void main(String[] args) {
28
+ NotificationFactory factory = new NotificationFactory();
29
+
30
+ Notification email = factory.createNotification("EMAIL");
31
+ email.notifyUser();
32
+
33
+ Notification sms = factory.createNotification("SMS");
34
+ sms.notifyUser();
35
+ }
36
+ }
@@ -0,0 +1,47 @@
1
+ import java.util.HashMap;
2
+
3
+ class TreeType {
4
+ private String name;
5
+ private String color;
6
+ private String textureData;
7
+
8
+ public TreeType(String name, String color, String textureData) {
9
+ this.name = name;
10
+ this.color = color;
11
+ this.textureData = textureData;
12
+ }
13
+
14
+ public void draw(int x, int y) {
15
+ System.out.println("Drawing a " + color + " " + name + " tree at X:" + x + ", Y:" + y);
16
+ }
17
+ }
18
+
19
+ class TreeFactory {
20
+ private static HashMap<String, TreeType> treeTypes = new HashMap<>();
21
+
22
+ public static TreeType getTreeType(String name, String color, String textureData) {
23
+ String key = name + "_" + color;
24
+ if (!treeTypes.containsKey(key)) {
25
+ treeTypes.put(key, new TreeType(name, color, textureData));
26
+ System.out.println("--> CACHE MISS: Instantiated new TreeType: " + key);
27
+ }
28
+ return treeTypes.get(key);
29
+ }
30
+ }
31
+
32
+ public class FlyweightDemo {
33
+ public static void main(String[] args) {
34
+ System.out.println("Planting Forest...\n");
35
+
36
+ TreeType oak = TreeFactory.getTreeType("Oak", "Green", "Oak_Texture.png");
37
+ oak.draw(10, 20);
38
+
39
+ TreeType oak2 = TreeFactory.getTreeType("Oak", "Green", "Oak_Texture.png");
40
+ oak2.draw(50, 60);
41
+
42
+ TreeType pine = TreeFactory.getTreeType("Pine", "Dark-Green", "Pine_Texture.png");
43
+ pine.draw(100, 100);
44
+
45
+ System.out.println("\nTotal unique tree types in memory: 2 (Even if we plant 10,000 trees)");
46
+ }
47
+ }
@@ -0,0 +1,36 @@
1
+ interface Expression {
2
+ boolean interpret(String context);
3
+ }
4
+
5
+ class ContextCheckExpression implements Expression {
6
+ private String data;
7
+ public ContextCheckExpression(String data) { this.data = data; }
8
+
9
+ public boolean interpret(String context) {
10
+ return context.contains(data);
11
+ }
12
+ }
13
+
14
+ class AndExpression implements Expression {
15
+ private Expression expr1, expr2;
16
+ public AndExpression(Expression expr1, Expression expr2) {
17
+ this.expr1 = expr1; this.expr2 = expr2;
18
+ }
19
+ public boolean interpret(String context) {
20
+ return expr1.interpret(context) && expr2.interpret(context);
21
+ }
22
+ }
23
+
24
+ public class InterpreterDemo {
25
+ public static void main(String[] args) {
26
+ Expression isPremium = new ContextCheckExpression("Premium");
27
+ Expression buyingTech = new ContextCheckExpression("Electronics");
28
+ Expression discountRule = new AndExpression(isPremium, buyingTech);
29
+
30
+ String currentTransaction = "User is Premium, buying Electronics";
31
+ String otherTransaction = "User is Standard, buying Electronics";
32
+
33
+ System.out.println("Transaction 1 gets discount? " + discountRule.interpret(currentTransaction));
34
+ System.out.println("Transaction 2 gets discount? " + discountRule.interpret(otherTransaction));
35
+ }
36
+ }
@@ -0,0 +1,62 @@
1
+ import java.util.ArrayList;
2
+ import java.util.List;
3
+
4
+ interface ATCMediator {
5
+ void registerFlight(Flight flight);
6
+ boolean requestLanding(Flight flight);
7
+ }
8
+
9
+ class ControlTower implements ATCMediator {
10
+ private List<Flight> flights = new ArrayList<>();
11
+ private boolean runwayAvailable = true;
12
+
13
+ public void registerFlight(Flight flight) { flights.add(flight); }
14
+
15
+ public boolean requestLanding(Flight flight) {
16
+ if (runwayAvailable) {
17
+ System.out.println("ATC: Runway cleared for " + flight.getName());
18
+ runwayAvailable = false;
19
+ return true;
20
+ } else {
21
+ System.out.println("ATC: Runway busy! " + flight.getName() + " must hold.");
22
+ return false;
23
+ }
24
+ }
25
+
26
+ public void clearRunway() {
27
+ System.out.println("ATC: Runway is now clear.");
28
+ runwayAvailable = true;
29
+ }
30
+ }
31
+
32
+ class Flight {
33
+ private String name;
34
+ private ATCMediator atc;
35
+
36
+ public Flight(String name, ATCMediator atc) {
37
+ this.name = name;
38
+ this.atc = atc;
39
+ atc.registerFlight(this);
40
+ }
41
+ public String getName() { return name; }
42
+
43
+ public void land() {
44
+ if (atc.requestLanding(this)) {
45
+ System.out.println(name + ": Landing successful.");
46
+ ((ControlTower) atc).clearRunway();
47
+ } else {
48
+ System.out.println(name + ": Waiting for clearance...");
49
+ }
50
+ }
51
+ }
52
+
53
+ public class MediatorDemo {
54
+ public static void main(String[] args) {
55
+ ControlTower atc = new ControlTower();
56
+ Flight f1 = new Flight("Boeing 747", atc);
57
+ Flight f2 = new Flight("Airbus A320", atc);
58
+
59
+ f1.land();
60
+ f2.land();
61
+ }
62
+ }
@@ -0,0 +1,50 @@
1
+ class GameSave {
2
+ private final int level;
3
+ private final int health;
4
+
5
+ public GameSave(int level, int health) {
6
+ this.level = level;
7
+ this.health = health;
8
+ }
9
+ public int getLevel() { return level; }
10
+ public int getHealth() { return health; }
11
+ }
12
+
13
+ class Player {
14
+ private int level = 1;
15
+ private int health = 100;
16
+
17
+ public void takeDamage(int damage) { health -= damage; }
18
+ public void levelUp() { level++; }
19
+
20
+ public GameSave save() {
21
+ System.out.println(">> Game Saved. Level: " + level + ", Health: " + health);
22
+ return new GameSave(level, health);
23
+ }
24
+
25
+ public void restore(GameSave save) {
26
+ this.level = save.getLevel();
27
+ this.health = save.getHealth();
28
+ System.out.println(">> Game Restored. Level: " + level + ", Health: " + health);
29
+ }
30
+
31
+ public void status() { System.out.println("Current Status -> Level: " + level + ", Health: " + health); }
32
+ }
33
+
34
+ public class MementoDemo {
35
+ public static void main(String[] args) {
36
+ Player player = new Player();
37
+ player.status();
38
+
39
+ player.levelUp();
40
+ player.takeDamage(20);
41
+
42
+ GameSave checkpoint = player.save();
43
+
44
+ player.takeDamage(80);
45
+ player.status();
46
+
47
+ player.restore(checkpoint);
48
+ player.status();
49
+ }
50
+ }
@@ -0,0 +1,47 @@
1
+ import java.util.ArrayList;
2
+ import java.util.List;
3
+
4
+ interface Observer {
5
+ void update(String stockName, double price);
6
+ }
7
+
8
+ class Investor implements Observer {
9
+ private String name;
10
+ public Investor(String name) { this.name = name; }
11
+ public void update(String stockName, double price) {
12
+ System.out.println("Notification for " + name + ": " + stockName + " is now $" + price);
13
+ }
14
+ }
15
+
16
+ class StockMarket {
17
+ private List<Observer> investors = new ArrayList<>();
18
+ private String stockName;
19
+ private double price;
20
+
21
+ public StockMarket(String stockName) { this.stockName = stockName; }
22
+
23
+ public void subscribe(Observer investor) { investors.add(investor); }
24
+
25
+ public void updatePrice(double newPrice) {
26
+ this.price = newPrice;
27
+ System.out.println("\n[MARKET UPDATE] " + stockName + " changed to $" + newPrice);
28
+ for (Observer investor : investors) {
29
+ investor.update(stockName, price);
30
+ }
31
+ }
32
+ }
33
+
34
+ public class ObserverDemo {
35
+ public static void main(String[] args) {
36
+ StockMarket reliance = new StockMarket("Reliance Industries");
37
+
38
+ Investor investor1 = new Investor("Rahul");
39
+ Investor investor2 = new Investor("Neha");
40
+
41
+ reliance.subscribe(investor1);
42
+ reliance.subscribe(investor2);
43
+
44
+ reliance.updatePrice(2500.50);
45
+ reliance.updatePrice(2512.00);
46
+ }
47
+ }
@@ -0,0 +1,38 @@
1
+ interface ConfigPrototype {
2
+ ConfigPrototype clone();
3
+ }
4
+
5
+ class DatabaseConfig implements ConfigPrototype {
6
+ private String host;
7
+ private int port;
8
+ private String dbName;
9
+
10
+ public DatabaseConfig(String host, int port, String dbName) {
11
+ System.out.println("Connecting to Database server... (Expensive Operation)");
12
+ this.host = host;
13
+ this.port = port;
14
+ this.dbName = dbName;
15
+ }
16
+
17
+ public void setDbName(String dbName) { this.dbName = dbName; }
18
+
19
+ @Override
20
+ public ConfigPrototype clone() {
21
+ return new DatabaseConfig(this.host, this.port, this.dbName);
22
+ }
23
+
24
+ public void showConfig() {
25
+ System.out.println("DB Config [Host: " + host + ", Port: " + port + ", DB: " + dbName + "]");
26
+ }
27
+ }
28
+
29
+ public class PrototypeDemo {
30
+ public static void main(String[] args) {
31
+ DatabaseConfig devConfig = new DatabaseConfig("localhost", 5432, "dev_db");
32
+ devConfig.showConfig();
33
+
34
+ DatabaseConfig prodConfig = (DatabaseConfig) devConfig.clone();
35
+ prodConfig.setDbName("prod_db");
36
+ prodConfig.showConfig();
37
+ }
38
+ }
@@ -0,0 +1,48 @@
1
+ interface DatabaseExecutor {
2
+ void executeQuery(String query) throws Exception;
3
+ }
4
+
5
+ class RealDatabaseExecutor implements DatabaseExecutor {
6
+ public void executeQuery(String query) {
7
+ System.out.println("Executing Query: " + query);
8
+ }
9
+ }
10
+
11
+ class ProxyDatabaseExecutor implements DatabaseExecutor {
12
+ private boolean isAdmin;
13
+ private RealDatabaseExecutor realExecutor;
14
+
15
+ public ProxyDatabaseExecutor(String userRole) {
16
+ this.isAdmin = "ADMIN".equalsIgnoreCase(userRole);
17
+ this.realExecutor = new RealDatabaseExecutor();
18
+ }
19
+
20
+ public void executeQuery(String query) throws Exception {
21
+ if (!isAdmin && (query.toUpperCase().startsWith("DROP") || query.toUpperCase().startsWith("DELETE"))) {
22
+ throw new Exception("Access Denied: Only Admins can execute destructive queries.");
23
+ }
24
+ realExecutor.executeQuery(query);
25
+ }
26
+ }
27
+
28
+ public class ProxyDemo {
29
+ public static void main(String[] args) {
30
+ DatabaseExecutor nonAdminExecutor = new ProxyDatabaseExecutor("USER");
31
+ DatabaseExecutor adminExecutor = new ProxyDatabaseExecutor("ADMIN");
32
+
33
+ try {
34
+ nonAdminExecutor.executeQuery("SELECT * FROM users");
35
+ System.out.println("Select query successful by USER.");
36
+ nonAdminExecutor.executeQuery("DELETE FROM users");
37
+ } catch (Exception e) {
38
+ System.out.println("Error: " + e.getMessage());
39
+ }
40
+
41
+ try {
42
+ adminExecutor.executeQuery("DELETE FROM users");
43
+ System.out.println("Delete query successful by ADMIN.");
44
+ } catch (Exception e) {
45
+ System.out.println("Error: " + e.getMessage());
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,40 @@
1
+ interface OrderState {
2
+ void next(Order order);
3
+ void printStatus();
4
+ }
5
+
6
+ class PlacedState implements OrderState {
7
+ public void next(Order order) { order.setState(new ShippedState()); }
8
+ public void printStatus() { System.out.println("State: Order has been PLACED."); }
9
+ }
10
+
11
+ class ShippedState implements OrderState {
12
+ public void next(Order order) { order.setState(new DeliveredState()); }
13
+ public void printStatus() { System.out.println("State: Order has been SHIPPED."); }
14
+ }
15
+
16
+ class DeliveredState implements OrderState {
17
+ public void next(Order order) { System.out.println("Order is already delivered."); }
18
+ public void printStatus() { System.out.println("State: Order is DELIVERED."); }
19
+ }
20
+
21
+ class Order {
22
+ private OrderState state = new PlacedState();
23
+
24
+ public void setState(OrderState state) { this.state = state; }
25
+ public void nextState() { state.next(this); }
26
+ public void checkStatus() { state.printStatus(); }
27
+ }
28
+
29
+ public class StateDemo {
30
+ public static void main(String[] args) {
31
+ Order myOrder = new Order();
32
+ myOrder.checkStatus();
33
+
34
+ myOrder.nextState();
35
+ myOrder.checkStatus();
36
+
37
+ myOrder.nextState();
38
+ myOrder.checkStatus();
39
+ }
40
+ }
@@ -0,0 +1,40 @@
1
+ abstract class DataExportPipeline {
2
+ public final void runPipeline() {
3
+ extractData();
4
+ transformData();
5
+ exportData();
6
+ System.out.println("Pipeline execution completed.\n");
7
+ }
8
+
9
+ protected void extractData() {
10
+ System.out.println("Extracting data from SQL Database...");
11
+ }
12
+
13
+ protected void transformData() {
14
+ System.out.println("Transforming and cleansing raw data...");
15
+ }
16
+
17
+ protected abstract void exportData();
18
+ }
19
+
20
+ class JSONExporter extends DataExportPipeline {
21
+ protected void exportData() {
22
+ System.out.println("Exporting transformed data into a .JSON file");
23
+ }
24
+ }
25
+
26
+ class CSVExporter extends DataExportPipeline {
27
+ protected void exportData() {
28
+ System.out.println("Exporting transformed data into a .CSV file");
29
+ }
30
+ }
31
+
32
+ public class TemplateDemo {
33
+ public static void main(String[] args) {
34
+ DataExportPipeline jsonJob = new JSONExporter();
35
+ jsonJob.runPipeline();
36
+
37
+ DataExportPipeline csvJob = new CSVExporter();
38
+ csvJob.runPipeline();
39
+ }
40
+ }
@@ -0,0 +1,42 @@
1
+ interface Visitor {
2
+ double visit(Grocery grocery);
3
+ double visit(Electronics electronics);
4
+ }
5
+
6
+ interface CartItem {
7
+ double accept(Visitor visitor);
8
+ }
9
+
10
+ class Grocery implements CartItem {
11
+ private double price;
12
+ public Grocery(double price) { this.price = price; }
13
+ public double getPrice() { return price; }
14
+ public double accept(Visitor visitor) { return visitor.visit(this); }
15
+ }
16
+
17
+ class Electronics implements CartItem {
18
+ private double price;
19
+ public Electronics(double price) { this.price = price; }
20
+ public double getPrice() { return price; }
21
+ public double accept(Visitor visitor) { return visitor.visit(this); }
22
+ }
23
+
24
+ class TaxVisitor implements Visitor {
25
+ public double visit(Grocery grocery) {
26
+ return grocery.getPrice() * 0.05;
27
+ }
28
+ public double visit(Electronics electronics) {
29
+ return electronics.getPrice() * 0.18;
30
+ }
31
+ }
32
+
33
+ public class VisitorDemo {
34
+ public static void main(String[] args) {
35
+ CartItem apple = new Grocery(100);
36
+ CartItem laptop = new Electronics(50000);
37
+ TaxVisitor taxCalculator = new TaxVisitor();
38
+
39
+ System.out.println("Tax on Apple (Grocery): $" + apple.accept(taxCalculator));
40
+ System.out.println("Tax on Laptop (Electronics): $" + laptop.accept(taxCalculator));
41
+ }
42
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modelit
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: Local-first ML starter templates you can print or save
5
5
  Author: Yashsmith
6
6
  License-Expression: MIT
@@ -86,6 +86,12 @@ modelit/templates/mycode/
86
86
  modelit/templates/mycode/template.py
87
87
  ```
88
88
 
89
+ For Java, use:
90
+
91
+ ```text
92
+ modelit/templates/mycode/template.java
93
+ ```
94
+
89
95
  3. Done. The folder name becomes the function name.
90
96
 
91
97
  That means this will work automatically:
@@ -0,0 +1,39 @@
1
+ .gitignore
2
+ CONTRIBUTING.md
3
+ LICENSE
4
+ MANIFEST.in
5
+ README.md
6
+ pyproject.toml
7
+ .github/workflows/publish.yml
8
+ .github/workflows/test.yml
9
+ modelit/__init__.py
10
+ modelit/__main__.py
11
+ modelit/cli.py
12
+ modelit/registry.py
13
+ modelit.egg-info/PKG-INFO
14
+ modelit.egg-info/SOURCES.txt
15
+ modelit.egg-info/dependency_links.txt
16
+ modelit.egg-info/entry_points.txt
17
+ modelit.egg-info/top_level.txt
18
+ modelit/templates/abstract_factory_pattern/template.java
19
+ modelit/templates/adapter_pattern/template.java
20
+ modelit/templates/backpropagation/template.py
21
+ modelit/templates/bridge_pattern/template.java
22
+ modelit/templates/builder_pattern/template.java
23
+ modelit/templates/cnn/template.py
24
+ modelit/templates/command_pattern/template.java
25
+ modelit/templates/composite_pattern/template.java
26
+ modelit/templates/decorator_pattern/template.java
27
+ modelit/templates/facade_pattern/template.java
28
+ modelit/templates/factory_pattern/template.java
29
+ modelit/templates/flyweight_pattern/template.java
30
+ modelit/templates/interpreter_pattern/template.java
31
+ modelit/templates/mediator_pattern/template.java
32
+ modelit/templates/memento_pattern/template.java
33
+ modelit/templates/observer_pattern/template.java
34
+ modelit/templates/perceptron/template.py
35
+ modelit/templates/prototype_pattern/template.java
36
+ modelit/templates/proxy_pattern/template.java
37
+ modelit/templates/state_pattern/template.java
38
+ modelit/templates/template_pattern/template.java
39
+ modelit/templates/visitor_pattern/template.java
@@ -36,7 +36,7 @@ where = ["."]
36
36
  include = ["modelit*"]
37
37
 
38
38
  [tool.setuptools.package-data]
39
- modelit = ["templates/*/*.py"]
39
+ modelit = ["templates/*/*.py", "templates/*/*.java"]
40
40
 
41
41
  [tool.setuptools_scm]
42
42
  version_scheme = "guess-next-dev"
modelit-0.2.4/MANIFEST.in DELETED
@@ -1 +0,0 @@
1
- recursive-include modelit/templates *.py *.json
@@ -1,20 +0,0 @@
1
- .gitignore
2
- CONTRIBUTING.md
3
- LICENSE
4
- MANIFEST.in
5
- README.md
6
- pyproject.toml
7
- .github/workflows/publish.yml
8
- .github/workflows/test.yml
9
- modelit/__init__.py
10
- modelit/__main__.py
11
- modelit/cli.py
12
- modelit/registry.py
13
- modelit.egg-info/PKG-INFO
14
- modelit.egg-info/SOURCES.txt
15
- modelit.egg-info/dependency_links.txt
16
- modelit.egg-info/entry_points.txt
17
- modelit.egg-info/top_level.txt
18
- modelit/templates/backpropagation/template.py
19
- modelit/templates/cnn/template.py
20
- modelit/templates/perceptron/template.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes