Merge branch 'master' of https://github.com/lumijiez/ExpenseTrackerFAF into security_branch

This commit is contained in:
Dmitrii Cravcenco
2023-09-21 12:13:37 +03:00
7 changed files with 52 additions and 29 deletions

View File

@@ -0,0 +1,33 @@
package entities;
public class Categories {
public enum ExpenseCategory {
CREDIT, BUY, BUSINESS, ENTERTAINMENT, RESTAURANTS_AND_CAFE, COMMUNAL_PAYMENTS, SUPERMARKET, MISC;
public String getEffectiveName() {
return Categories.getEffectiveName(this.name());
}
}
public enum IncomeCategory {
P2P, SALARY, GIFT, CREDIT, MISC;
public String getEffectiveName() {
return Categories.getEffectiveName(this.name());
}
}
private static String getEffectiveName(String name) {
String[] arr = name.split("_");
StringBuilder result = new StringBuilder();
for(String entry : arr) {
String[] entryArr = entry.split("");
StringBuilder builder = new StringBuilder(entryArr[0]);
for(int i = 1; i < entry.length(); i++) builder.append(entryArr[i].toLowerCase());
result.append(builder).append(" ");
}
return result.toString();
}
}

View File

@@ -1,12 +1,12 @@
package entities; package entities;
public class Expense extends MoneyTransaction { public class Expense implements IMoneyTransaction {
private int userId; private int userId;
private int amount; private int amount;
private ExpensesCategory category; private Categories.ExpenseCategory category;
public Expense(int userId, int amount, ExpensesCategory category) { public Expense(int userId, int amount, Categories.ExpenseCategory category) {
this.userId = userId; this.userId = userId;
this.amount = amount; this.amount = amount;
this.category = category; this.category = category;
@@ -32,10 +32,10 @@ public class Expense extends MoneyTransaction {
@Override @Override
public String getCategory() { public String getCategory() {
return category.toString(); return category.getEffectiveName();
} }
public void setCategory(ExpensesCategory category) { public void setCategory(Categories.ExpenseCategory category) {
this.category = category; this.category = category;
} }
} }

View File

@@ -1,5 +0,0 @@
package entities;
public enum ExpensesCategory {
MISC;
}

View File

@@ -0,0 +1,9 @@
package entities;
public interface IMoneyTransaction {
long getUserId();
int getAmount();
String getCategory();
}

View File

@@ -1,12 +1,12 @@
package entities; package entities;
public class Income extends MoneyTransaction { public class Income implements IMoneyTransaction {
private long userId; private long userId;
private int amount; private int amount;
private IncomeCategory category; private Categories.IncomeCategory category;
public Income(long userId, int amount, IncomeCategory category) { public Income(long userId, int amount, Categories.IncomeCategory category) {
this.userId = userId; this.userId = userId;
this.amount = amount; this.amount = amount;
this.category = category; this.category = category;
@@ -24,7 +24,7 @@ public class Income extends MoneyTransaction {
@Override @Override
public String getCategory() { public String getCategory() {
return category.toString(); return category.getEffectiveName();
} }
public void setUserId(long userId) { public void setUserId(long userId) {
@@ -35,7 +35,7 @@ public class Income extends MoneyTransaction {
this.amount = amount; this.amount = amount;
} }
public void setCategory(IncomeCategory category) { public void setCategory(Categories.IncomeCategory category) {
this.category = category; this.category = category;
} }
} }

View File

@@ -1,5 +0,0 @@
package entities;
public enum IncomeCategory {
MISC;
}

View File

@@ -1,9 +0,0 @@
package entities;
public abstract class MoneyTransaction {
public abstract long getUserId();
public abstract int getAmount();
public abstract String getCategory();
}