Skip to content

Commit

Permalink
[+] Add EntryFactory to create entry and fix some problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottCTD committed Nov 6, 2022
1 parent 6c9a6e8 commit 3594fc3
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/main/java/billgates/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package billgates;

import billgates.entities.Entry;
import billgates.entities.EntryFactory;

import java.time.ZonedDateTime;

public class Main {

public static void main(String[] args) {
Entry entry = new EntryFactory(1)
.setDate(ZonedDateTime.now())
.setValue(123)
.setCurrency("CAD")
.setDescription("RAY")
.setFrom("Scott's credit card")
.setTo("T&T supermarket")
.createEntry();
System.out.println(entry);
}

}
10 changes: 9 additions & 1 deletion src/main/java/billgates/entities/AbstractEntry.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package billgates.entities;

import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Objects;

public abstract class AbstractEntry {
Expand All @@ -14,7 +15,7 @@ public abstract class AbstractEntry {
private Attribute<String> to;
private Attribute<String> location;

public AbstractEntry(Attribute<Integer> id, Attribute<ZonedDateTime> date, Attribute<Double> value,
protected AbstractEntry(Attribute<Integer> id, Attribute<ZonedDateTime> date, Attribute<Double> value,
Attribute<String> currency, Attribute<String> description,
Attribute<String> from, Attribute<String> to, Attribute<String> location) {
this.id = id;
Expand All @@ -27,6 +28,13 @@ public AbstractEntry(Attribute<Integer> id, Attribute<ZonedDateTime> date, Attri
this.location = location;
}

@Override
public String toString() {
return Arrays.toString(new String[]{
this.id.toString(), this.date.toString(), this.value.toString(), this.currency.toString(),
this.description.toString(), this.from.toString(), this.to.toString(), this.location.toString()});
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/billgates/entities/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public Attribute(T attribute, String name) {
this.name = name;
}

@Override
public String toString() {
return this.attribute.toString();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/billgates/entities/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Entry extends AbstractEntry {

public Entry(Attribute<Integer> id, Attribute<ZonedDateTime> date, Attribute<Double> value,
protected Entry(Attribute<Integer> id, Attribute<ZonedDateTime> date, Attribute<Double> value,
Attribute<String> currency, Attribute<String> description,
Attribute<String> from, Attribute<String> to, Attribute<String> location) {
super(id, date, value, currency, description, from, to, location);
Expand Down
71 changes: 71 additions & 0 deletions src/main/java/billgates/entities/EntryFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package billgates.entities;

import java.time.ZonedDateTime;

public class EntryFactory {

private int id = -1;
private ZonedDateTime date = ZonedDateTime.now();
private double value = 0.0;
private String currency = "";
private String description = "";
private String from = "";
private String to = "";
private String location = "";

// TODO splitter

// TODO for splitter, payee

public EntryFactory(int id) {
this.id = id;
}

public Entry createEntry() {
return new Entry(
new Attribute<>(this.id, "id"),
new Attribute<>(this.date, "date"),
new Attribute<>(this.value, "value"),
new Attribute<>(this.currency, "currency"),
new Attribute<>(this.description, "description"),
new Attribute<>(this.from, "from"),
new Attribute<>(this.to, "to"),
new Attribute<>(this.location, "location")
);
}

public EntryFactory setDate(ZonedDateTime date) {
this.date = date;
return this;
}

public EntryFactory setValue(double value) {
this.value = value;
return this;
}

public EntryFactory setCurrency(String currency) {
this.currency = currency;
return this;
}

public EntryFactory setDescription(String description) {
this.description = description;
return this;
}

public EntryFactory setFrom(String from) {
this.from = from;
return this;
}

public EntryFactory setTo(String to) {
this.to = to;
return this;
}

public EntryFactory setLocation(String location) {
this.location = location;
return this;
}
}

0 comments on commit 3594fc3

Please sign in to comment.