Class BudgetItemList
- java.lang.Object
-
- com.infinitekind.moneydance.model.BudgetItemList
-
- All Implemented Interfaces:
java.lang.Iterable<BudgetItem>
public class BudgetItemList extends java.lang.Object implements java.lang.Iterable<BudgetItem>
this contains a list of budget items associated with a budget and is used to perform calculations and interactions with the items of the list without having to query the main data model for every budget-specific interaction. This can also be used to create an editable copy of a budget so that changes can be aborted or committed rather than synced individually.
-
-
Constructor Summary
Constructors Constructor Description BudgetItemList(Budget budget)
BudgetItemList(Budget budget, java.util.List<BudgetItem> itemList)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BudgetItem
createItem()
long
getActualAmount(Account account, BudgetPeriod budgetPeriod)
Return the actual amount for a specific category in a month.long
getActualAmountForAllCategoriesInPeriod(BudgetPeriod budgetPeriod, CurrencyType resultCurrency, Account.AccountType accountType)
Returns the actual amount for all categories in the given period.Budget
getBudget()
long
getBudgetedAmount(Account account, BudgetPeriod budgetPeriod)
Return the budgeted amount for a specific category in a month.long
getBudgetedAmountForAllCategoriesInPeriod(BudgetPeriod budgetPeriod, Account.AccountType accountType)
Returns the budgeted amount for all categories in the given periodBudgetItem
getBudgetItemForCategory(Account account, BudgetPeriod budgetPeriod)
Get the budget items for the given account in the given budget period.java.util.List<BudgetItem>
getBudgetItemsForAccountAndInterval(Account account, int interval)
java.util.ArrayList<BudgetItem>
getBudgetItemsForAccountInRange(Account account, DateRange dateRange, java.util.ArrayList<BudgetItem> budgetItems)
Get the budget items with the given transfer account whose date interval overlap with the given date range.BudgetItem
getItem(int i)
Get the budget item at the given position in the listint
getItemCount()
Get the number of items in this budgetint
indexOf(BudgetItem item)
Return the position in the item list of the given itemjava.util.Iterator<BudgetItem>
iterator()
static BudgetItemList
makeEditableList(Budget budget)
BudgetItemList
makeEditingCopy()
void
reload()
Reload by rescanning the data model for budget items.boolean
removeItem(BudgetItem item)
Remove the given budget item from the list.void
saveEdits()
void
setBudgetedAmount(Account account, long amount, BudgetPeriod budgetPeriod)
Sets the budgeted amount for a given Account in a given BudgetPeriod.void
sortItems()
BudgetItem[]
toArray()
Get a new array of the budget items contained in this list
-
-
-
Constructor Detail
-
BudgetItemList
public BudgetItemList(Budget budget, java.util.List<BudgetItem> itemList)
-
BudgetItemList
public BudgetItemList(Budget budget)
-
-
Method Detail
-
reload
public void reload()
Reload by rescanning the data model for budget items. If this is an editable list then this resets the list to make it no longer able to be reverted.
-
makeEditingCopy
public BudgetItemList makeEditingCopy()
-
makeEditableList
public static BudgetItemList makeEditableList(Budget budget)
-
saveEdits
public void saveEdits()
-
getBudget
public Budget getBudget()
-
sortItems
public void sortItems()
-
getItemCount
public int getItemCount()
Get the number of items in this budget
-
getItem
public BudgetItem getItem(int i)
Get the budget item at the given position in the list
-
toArray
public BudgetItem[] toArray()
Get a new array of the budget items contained in this list
-
removeItem
public boolean removeItem(BudgetItem item)
Remove the given budget item from the list. Returns true if the item was in the list.
-
indexOf
public int indexOf(BudgetItem item)
Return the position in the item list of the given item
-
iterator
public java.util.Iterator<BudgetItem> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<BudgetItem>
-
getBudgetItemForCategory
public BudgetItem getBudgetItemForCategory(Account account, BudgetPeriod budgetPeriod)
Get the budget items for the given account in the given budget period.- Parameters:
account
-budgetPeriod
-- Returns:
-
getBudgetItemsForAccountAndInterval
public java.util.List<BudgetItem> getBudgetItemsForAccountAndInterval(Account account, int interval)
- Parameters:
account
-interval
-- Returns:
-
getBudgetItemsForAccountInRange
public java.util.ArrayList<BudgetItem> getBudgetItemsForAccountInRange(Account account, DateRange dateRange, java.util.ArrayList<BudgetItem> budgetItems)
Get the budget items with the given transfer account whose date interval overlap with the given date range.- Parameters:
account
- the account (category) for itemsdateRange
- the date range to search for matching itemsbudgetItems
- an empty ArrayList to which the matching items should be added. or null.- Returns:
- a list of items matching the given account/category and date range. Will be the same as the given budgetItems, if non-null;
-
getBudgetedAmount
public long getBudgetedAmount(Account account, BudgetPeriod budgetPeriod)
Return the budgeted amount for a specific category in a month. Because of a bug in the Calendar class, date is not reset to the first day of the month so it must be passed in already set correctly.- Parameters:
account
- the account (category) for itemsbudgetPeriod
- the budget period- Returns:
-
getActualAmount
public long getActualAmount(Account account, BudgetPeriod budgetPeriod)
Return the actual amount for a specific category in a month. Because of a bug in the Calendar class, date is not reset to the first day of the month so it must be passed in already set correctly. FIXME Note that this method is not strictly related to the budget, it's here for convenience but should belong to the Account class rather than the Budget one.- Parameters:
account
-budgetPeriod
-- Returns:
-
getActualAmountForAllCategoriesInPeriod
public long getActualAmountForAllCategoriesInPeriod(BudgetPeriod budgetPeriod, CurrencyType resultCurrency, Account.AccountType accountType)
Returns the actual amount for all categories in the given period.- Parameters:
budgetPeriod
- the budget period to gather amounts for
-
getBudgetedAmountForAllCategoriesInPeriod
public long getBudgetedAmountForAllCategoriesInPeriod(BudgetPeriod budgetPeriod, Account.AccountType accountType)
Returns the budgeted amount for all categories in the given period- Parameters:
budgetPeriod
-
-
setBudgetedAmount
public void setBudgetedAmount(Account account, long amount, BudgetPeriod budgetPeriod)
Sets the budgeted amount for a given Account in a given BudgetPeriod.- Parameters:
account
-amount
-budgetPeriod
-
-
createItem
public BudgetItem createItem()
-
-