|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jbudget.io.DataIndex
public class DataIndex
An object that stores an index of all available Month objects.
| Field Summary | |
|---|---|
private int |
accountCounter
A counter that is used for assigning IDs to Accounts |
private java.util.Map<java.lang.Integer,org.jbudget.Core.Account> |
accounts
A map of numberic account ID's and Accounts. |
private int |
budgetCounter
A counter that is used for assinging IDs to Budgets |
private java.util.Map<java.lang.Integer,org.jbudget.Core.Budget> |
budgets
A map of numeric budget ID's and budgets. |
private int |
categoryCounter
A counter that is used for assigning IDs to ExpenseCategories and income sources. |
private boolean |
haveData
If this flag is true the object does not store any Month instances. |
private java.util.Map<java.lang.Integer,org.jbudget.Core.Month> |
months
A map of year*100+month to the Month objects |
private long |
transactionCounter
A counter that is used for assigning IDs to Transactions |
private int |
userCounter
A user counter |
private java.util.Map<java.lang.Integer,org.jbudget.Core.User> |
users
A map of uids and User objects |
private java.util.List<Pair<java.lang.Integer,java.lang.String>> |
validAccounts
A list of valid accounts. |
private java.util.List<Pair<java.lang.Integer,java.lang.String>> |
validBudgets
A list of Pairs of budgetIDs
and names of the budgets that are active.This has different meaning for the index of data in the memory and on the disk or on a server. |
private java.util.Map<java.lang.Integer,java.util.List<java.lang.Integer>> |
validMonths
A map that connects a year to a list of valid months for that year |
private java.util.List<Pair<java.lang.Integer,java.lang.String>> |
validUsers
A list of uids/names of users |
private java.util.List<java.lang.Integer> |
validYears
A list of valid years |
| Constructor Summary | |
|---|---|
DataIndex(boolean storeData)
Creates a new instance of DataIndex |
|
| Method Summary | ||
|---|---|---|
void |
addAccount(org.jbudget.Core.Account account)
Stores an account in this index |
|
void |
addBudget(org.jbudget.Core.Budget budget)
Stores the budget. |
|
void |
addMonth(org.jbudget.Core.Month monthObject)
Adds or replaces a Month object that is associated with the given year/month combination |
|
private static
|
addToList(java.util.List<Pair<T,E>> list,
T index,
E data,
java.lang.String name)
Used to add a pair Integer, String and such to sorted lists and maintain sorting. |
|
void |
addUser(org.jbudget.Core.User user)
Stores an user in this index |
|
int |
generateAccountID()
Creates a new numeric account id and increases the counter. |
|
int |
generateBudgetID()
Creates a new numeric budget id and increases the counter. |
|
int |
generateExpenseCategoryID()
Creates a new numeric id for an expense category and increases the counter. |
|
int |
generateIncomeSourceID()
Creates a new numeric id for an income source and increases the counter. |
|
long |
generateTransactionID()
Creates a new numeric transaction id for and increases the counter. |
|
int |
generateUID()
Creates a new uid for a new user and increases the counter. |
|
org.jbudget.Core.Account |
getAccount(int id)
Returns an account with a given ID. |
|
java.util.List<Pair<java.lang.Integer,java.lang.String>> |
getAccountInfo()
Returns an unmodifiable list that contains numerical IDs and names of all valid accounts |
|
java.lang.String |
getAccountName(int id)
Returns the name of the account that has a given ID |
|
org.jbudget.Core.Budget |
getBudget(int id)
Returns a Budget object with the given numeric ID. |
|
private static
|
getFromList(java.util.List<Pair<T,E>> list,
T index)
Searches the list of pairs index/data for a pair with a give index and returns the data |
|
static DataIndex |
getInstance(Element element)
Parses JDOM Element into a DataIndex object. |
|
org.jbudget.Core.Month |
getMonth(int month,
int year)
Returns the Month object that represents the given year/month combination. |
|
org.jbudget.Core.User |
getUser(int uid)
Returns an user with a given UID. |
|
java.util.List<Pair<java.lang.Integer,java.lang.String>> |
getUserInfo()
Returns an unmodifiable list that contains UIDs and names of all valid users |
|
java.lang.String |
getUserName(int uid)
Returns the name of the user that has a given UID |
|
java.util.List<Pair<java.lang.Integer,java.lang.String>> |
getValidBudgets()
Returns a list containing Pairs of ids and names of all valid Budgets |
|
java.util.List<java.lang.Integer> |
getValidMonths(int year)
Returns a list of valid months for a given year |
|
java.util.List<java.lang.Integer> |
getValidYears()
Returns a list of years that have at least one valid month (a month for which we have a Month object) |
|
Element |
getXmlElement()
Returns a JDOM XML Element representation of the current budget |
|
boolean |
indexingMode()
Returns true if the index is used in indexing only mode. |
|
boolean |
isValidAccount(int id)
Returns true if there is an account with a given ID |
|
boolean |
isValidBudget(int id)
Returns true if there is a Budget with such id |
|
boolean |
isValidMonth(int month,
int year)
Returns true if we have a Month object for the given year/month combination |
|
boolean |
isValidUser(int uid)
Returns true if there is a user with a given ID |
|
void |
registerAccount(int accountID,
java.lang.String accountName)
Records information about account. |
|
private void |
registerAccountPrivate(int accountID,
java.lang.String accountName)
Actually does the work of registering the account |
|
void |
registerBudget(int id,
java.lang.String name)
adds information about a Budget instance to the list of valid budgets. |
|
private void |
registerBudgetPrivate(int id,
java.lang.String name)
adds information about a Budget instance to the list of valid budgets. |
|
void |
registerMonth(int month,
int year)
Registers a month object by marking that there is a month object that corresponds to the given year/month combination. |
|
private void |
registerMonthPrivate(int month,
int year)
Actually does the work necessary to make a record that a month is valid. |
|
void |
registerUser(int uid,
java.lang.String userName)
Records information about a user. |
|
private void |
registerUserPrivate(int uid,
java.lang.String userName)
Actually does the work of registering the user |
|
void |
removeAccount(int accountID)
Removes all information about an account with a given id. |
|
void |
removeBudget(int id)
Removes a budget with a given numeric ID. |
|
private static
|
removeFromList(java.util.List<Pair<T,E>> list,
T index,
java.lang.String name)
Removes a generic pair index/data (i.e. |
|
void |
removeMonth(org.jbudget.Core.Month monthObject)
Removes a Month object from this data index. |
|
void |
removeUser(int uid)
Removes all information about an user with a given uid. |
|
java.lang.String |
toString()
|
|
void |
unregisterAccount(int accountID)
Removes a record of information about account.Should only be used when the DataIndex object is in indexing only mode (haveData is false). |
|
private void |
unregisterAccountPrivate(int accountID)
Acutally does the work on unregestering the account |
|
void |
unregisterBudget(int id)
removes information about a Budget instance from the list of valid budgets. |
|
private void |
unregisterBudgetPrivate(int id)
removes information about a Budget instance from the list of valid budgets. |
|
void |
unregisterMonth(int month,
int year)
Unregisteres a month object by removing all information related to it from this data index. |
|
private void |
unregisterMonthPrivate(int month,
int year)
Actually does the work to remove information about a month object. |
|
void |
unregisterUser(int uid)
Removes a record of information about a user. |
|
private void |
unregisterUserPrivate(int uid)
Acutally does the work on unregestering the user |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private java.util.List<java.lang.Integer> validYears
private java.util.Map<java.lang.Integer,java.util.List<java.lang.Integer>> validMonths
private java.util.Map<java.lang.Integer,org.jbudget.Core.Month> months
private java.util.List<Pair<java.lang.Integer,java.lang.String>> validBudgets
Pairs of budgetIDs
and names of the budgets that are active.getBudget(budgetID).
In the case when this object is used to index
the data available in permanent storage, the map just contains all numeric
ids and names of all budgets available in storage.
private java.util.Map<java.lang.Integer,org.jbudget.Core.Budget> budgets
private java.util.List<Pair<java.lang.Integer,java.lang.String>> validAccounts
private java.util.Map<java.lang.Integer,org.jbudget.Core.Account> accounts
private java.util.List<Pair<java.lang.Integer,java.lang.String>> validUsers
private java.util.Map<java.lang.Integer,org.jbudget.Core.User> users
private final boolean haveData
private int budgetCounter
private int accountCounter
private int categoryCounter
private long transactionCounter
private int userCounter
| Constructor Detail |
|---|
public DataIndex(boolean storeData)
| Method Detail |
|---|
public java.util.List<java.lang.Integer> getValidYears()
public java.util.List<java.lang.Integer> getValidMonths(int year)
public boolean isValidMonth(int month,
int year)
public org.jbudget.Core.Month getMonth(int month,
int year)
java.lang.UnsupportedOperationException - if this object is used in indexing
only mode (a 'false' is passed to the constructor).public void addMonth(org.jbudget.Core.Month monthObject)
java.lang.UnsupportedOperationException - if this object is used in indexing
only mode ('false' is passed to the constructor).public void removeMonth(org.jbudget.Core.Month monthObject)
java.lang.UnsupportedOperationException - if this object is used in indexing
only mode ('false' is passed to the constructor).
java.lang.IllegalArgumentException - if the Month is not present in the data
index.
public void registerMonth(int month,
int year)
addMonth.
java.lang.UnsupportedOperationException - if this object is not used in indexing
only mode ('true' is passed to the constructor).
public void unregisterMonth(int month,
int year)
removeMonth.
java.lang.UnsupportedOperationException - if this object is not used in indexing
only mode ('true' is passed to the constructor).
java.lang.IllegalArgumentException - if the month that is bein passed to this
function is not present in this index.
private void registerMonthPrivate(int month,
int year)
registerMonth(int, int),
addMonth(Month)
private void unregisterMonthPrivate(int month,
int year)
java.lang.IllegalArgumentException - if no record for the current month exists.unregisterMonth(int, int),
removeMonth(Month)public java.util.List<Pair<java.lang.Integer,java.lang.String>> getValidBudgets()
Pairs of ids and names of all valid Budgets
public void registerBudget(int id,
java.lang.String name)
java.lang.IllegalStateException - if a budget with given id is already
present.
java.lang.UnsupportedOperationException - if this object is not used in indexing
only mode ('true' is passed to the constructor).
private void registerBudgetPrivate(int id,
java.lang.String name)
java.lang.IllegalStateException - if a budget with given id is already
present.public void unregisterBudget(int id)
java.lang.IllegalArgumentException - if no budget with the given id exists.
java.lang.UnsupportedOperationException - if this object is not used in indexing
only mode ('true' is passed to the constructor).private void unregisterBudgetPrivate(int id)
java.lang.IllegalArgumentException - if no budget with the given id exists.public org.jbudget.Core.Budget getBudget(int id)
java.lang.UnsupportedOperationException - if this object is used in indexing
only mode ('false' is passed to the constructor).
IllegalArguementException - if there is no budget with such id.public void addBudget(org.jbudget.Core.Budget budget)
java.lang.UnsupportedOperationException - if this object is used in indexing
only mode ('false' is passed to the constructor).public void removeBudget(int id)
java.lang.UnsupportedOperationException - if this object is used in indexing
only mode ('false' is passed to the constructor).
java.lang.IllegalArgumentException - if no budget with the given id exists.public boolean isValidBudget(int id)
public boolean isValidAccount(int id)
public java.util.List<Pair<java.lang.Integer,java.lang.String>> getAccountInfo()
public java.lang.String getAccountName(int id)
public org.jbudget.Core.Account getAccount(int id)
an - UnsupportedOperationException if haveData is false.public void addAccount(org.jbudget.Core.Account account)
an - UnsupportedOperationException if haveData is false.public void removeAccount(int accountID)
an - UnsupportedOperationException if haveData is false.
public void registerAccount(int accountID,
java.lang.String accountName)
an - UnsupportedOperationException if haveData is true.
private void registerAccountPrivate(int accountID,
java.lang.String accountName)
public void unregisterAccount(int accountID)
an - UnsupportedOperationException if haveData is true.
na - IllegalArgumentException if there is no account with such ID.private void unregisterAccountPrivate(int accountID)
public boolean isValidUser(int uid)
public java.util.List<Pair<java.lang.Integer,java.lang.String>> getUserInfo()
public java.lang.String getUserName(int uid)
public org.jbudget.Core.User getUser(int uid)
an - UnsupportedOperationException if haveData is false.public void addUser(org.jbudget.Core.User user)
an - UnsupportedOperationException if haveData is false.public void removeUser(int uid)
an - UnsupportedOperationException if haveData is false.
public void registerUser(int uid,
java.lang.String userName)
an - UnsupportedOperationException if haveData is true.
private void registerUserPrivate(int uid,
java.lang.String userName)
public void unregisterUser(int uid)
an - UnsupportedOperationException if haveData is true.
na - IllegalArgumentException if there is no user with such ID.private void unregisterUserPrivate(int uid)
public int generateBudgetID()
public int generateAccountID()
public int generateExpenseCategoryID()
public int generateIncomeSourceID()
public int generateUID()
public long generateTransactionID()
private static <T extends java.lang.Comparable,E> void addToList(java.util.List<Pair<T,E>> list,
T index,
E data,
java.lang.String name)
private static <T extends java.lang.Comparable,E> void removeFromList(java.util.List<Pair<T,E>> list,
T index,
java.lang.String name)
private static <T extends java.lang.Comparable,E> E getFromList(java.util.List<Pair<T,E>> list,
T index)
public boolean indexingMode()
public java.lang.String toString()
toString in class java.lang.Objectpublic Element getXmlElement()
public static DataIndex getInstance(Element element)
throws JDOMException
DataIndex object. The
DataIndex object created by this function works in
indexing only mode.
JDOMException - in case of parsing errors.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||