Merge branch 'master' of https://github.com/lumijiez/ExpenseTrackerFAF into security_branch
This commit is contained in:
33
src/main/java/entities/Categories.java
Normal file
33
src/main/java/entities/Categories.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package entities;
|
||||
|
||||
public class Expense extends MoneyTransaction {
|
||||
public class Expense implements IMoneyTransaction {
|
||||
|
||||
private int userId;
|
||||
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.amount = amount;
|
||||
this.category = category;
|
||||
@@ -32,10 +32,10 @@ public class Expense extends MoneyTransaction {
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return category.toString();
|
||||
return category.getEffectiveName();
|
||||
}
|
||||
|
||||
public void setCategory(ExpensesCategory category) {
|
||||
public void setCategory(Categories.ExpenseCategory category) {
|
||||
this.category = category;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package entities;
|
||||
|
||||
public enum ExpensesCategory {
|
||||
MISC;
|
||||
}
|
||||
9
src/main/java/entities/IMoneyTransaction.java
Normal file
9
src/main/java/entities/IMoneyTransaction.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package entities;
|
||||
|
||||
public interface IMoneyTransaction {
|
||||
|
||||
long getUserId();
|
||||
int getAmount();
|
||||
String getCategory();
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package entities;
|
||||
|
||||
public class Income extends MoneyTransaction {
|
||||
public class Income implements IMoneyTransaction {
|
||||
|
||||
private long userId;
|
||||
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.amount = amount;
|
||||
this.category = category;
|
||||
@@ -24,7 +24,7 @@ public class Income extends MoneyTransaction {
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return category.toString();
|
||||
return category.getEffectiveName();
|
||||
}
|
||||
|
||||
public void setUserId(long userId) {
|
||||
@@ -35,7 +35,7 @@ public class Income extends MoneyTransaction {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public void setCategory(IncomeCategory category) {
|
||||
public void setCategory(Categories.IncomeCategory category) {
|
||||
this.category = category;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package entities;
|
||||
|
||||
public enum IncomeCategory {
|
||||
MISC;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package entities;
|
||||
|
||||
public abstract class MoneyTransaction {
|
||||
|
||||
public abstract long getUserId();
|
||||
public abstract int getAmount();
|
||||
public abstract String getCategory();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user