Merged categories into one file
This commit is contained in:
28
src/main/java/entities/Categories.java
Normal file
28
src/main/java/entities/Categories.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package entities;
|
||||||
|
|
||||||
|
public class Categories {
|
||||||
|
|
||||||
|
public enum ExpenseCategory {
|
||||||
|
MISC;
|
||||||
|
|
||||||
|
public String getEffectiveName() {
|
||||||
|
return Categories.getEffectiveName(this.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum IncomeCategory {
|
||||||
|
MISC;
|
||||||
|
|
||||||
|
public String getEffectiveName() {
|
||||||
|
return Categories.getEffectiveName(this.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getEffectiveName(String name) {
|
||||||
|
String[] arr = name.split("");
|
||||||
|
StringBuilder result = new StringBuilder(arr[0].toLowerCase());
|
||||||
|
for(int i = 1; i < name.length(); i++) result.append(arr[i]);
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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