MoneyWiseLoan.java
/*
* MoneyWise: Finance Application
* Copyright 2012-2026. Tony Washer
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package io.github.tonywasher.joceanus.moneywise.data.basic;
import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
import io.github.tonywasher.joceanus.oceanus.decimal.OceanusMoney;
import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
import io.github.tonywasher.joceanus.metis.data.MetisDataDifference;
import io.github.tonywasher.joceanus.metis.data.MetisDataEditState;
import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataFieldId;
import io.github.tonywasher.joceanus.metis.data.MetisDataResource;
import io.github.tonywasher.joceanus.metis.data.MetisDataState;
import io.github.tonywasher.joceanus.metis.field.MetisFieldItem;
import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
import io.github.tonywasher.joceanus.metis.field.MetisFieldVersionedSet;
import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseLoanCategory.MoneyWiseLoanCategoryList;
import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseLoanInfo.MoneyWiseLoanInfoList;
import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee.MoneyWisePayeeList;
import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseAccountInfoClass;
import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseAccountInfoType.MoneyWiseAccountInfoTypeList;
import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseCurrency;
import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseCurrency.MoneyWiseCurrencyList;
import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseLoanCategoryClass;
import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticDataType;
import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseDataException;
import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseLogicException;
import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataItem;
import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataMapItem;
import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues.PrometheusInfoItem;
import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues.PrometheusInfoSetItem;
import io.github.tonywasher.joceanus.prometheus.views.PrometheusEditSet;
import java.util.Iterator;
/**
* Loan class.
*/
public class MoneyWiseLoan
extends MoneyWiseAssetBase
implements PrometheusInfoSetItem {
/**
* Object name.
*/
public static final String OBJECT_NAME = MoneyWiseBasicDataType.LOAN.getItemName();
/**
* List name.
*/
public static final String LIST_NAME = MoneyWiseBasicDataType.LOAN.getListName();
/**
* Local Report fields.
*/
private static final MetisFieldVersionedSet<MoneyWiseLoan> FIELD_DEFS = MetisFieldVersionedSet.newVersionedFieldSet(MoneyWiseLoan.class);
/*
* FieldIds.
*/
static {
FIELD_DEFS.declareLocalField(PrometheusDataResource.DATAINFOSET_NAME, MoneyWiseLoan::getInfoSet);
FIELD_DEFS.buildFieldMap(MoneyWiseAccountInfoClass.class, MoneyWiseLoan::getFieldValue);
}
/**
* Do we have an InfoSet.
*/
private final boolean hasInfoSet;
/**
* Should we use infoSet for DataState etc.
*/
private final boolean useInfoSet;
/**
* LoanInfoSet.
*/
private final MoneyWiseLoanInfoSet theInfoSet;
/**
* Copy Constructor.
*
* @param pList the list
* @param pLoan The Loan to copy
*/
protected MoneyWiseLoan(final MoneyWiseLoanList pList,
final MoneyWiseLoan pLoan) {
/* Set standard values */
super(pList, pLoan);
/* switch on list type */
switch (getList().getStyle()) {
case EDIT:
theInfoSet = new MoneyWiseLoanInfoSet(this, pList.getActInfoTypes(), pList.getLoanInfo());
theInfoSet.cloneDataInfoSet(pLoan.getInfoSet());
hasInfoSet = true;
useInfoSet = true;
break;
case CLONE:
case CORE:
theInfoSet = new MoneyWiseLoanInfoSet(this, pList.getActInfoTypes(), pList.getLoanInfo());
hasInfoSet = true;
useInfoSet = false;
break;
default:
theInfoSet = null;
hasInfoSet = false;
useInfoSet = false;
break;
}
}
/**
* Values constructor.
*
* @param pList the List to add to
* @param pValues the values constructor
* @throws OceanusException on error
*/
private MoneyWiseLoan(final MoneyWiseLoanList pList,
final PrometheusDataValues pValues) throws OceanusException {
/* Initialise the item */
super(pList, pValues);
/* Create the InfoSet */
theInfoSet = new MoneyWiseLoanInfoSet(this, pList.getActInfoTypes(), pList.getLoanInfo());
hasInfoSet = true;
useInfoSet = false;
}
/**
* Edit Constructor.
*
* @param pList the list
*/
public MoneyWiseLoan(final MoneyWiseLoanList pList) {
super(pList);
/* Build InfoSet */
theInfoSet = new MoneyWiseLoanInfoSet(this, pList.getActInfoTypes(), pList.getLoanInfo());
hasInfoSet = true;
useInfoSet = true;
}
@Override
public MetisFieldSetDef getDataFieldSet() {
return FIELD_DEFS;
}
@Override
public boolean includeXmlField(final MetisDataFieldId pField) {
/* Determine whether fields should be included */
if (MoneyWiseBasicResource.CATEGORY_NAME.equals(pField)) {
return true;
}
if (MoneyWiseStaticDataType.CURRENCY.equals(pField)) {
return true;
}
if (MoneyWiseBasicResource.ASSET_PARENT.equals(pField)) {
return true;
}
/* Pass call on */
return super.includeXmlField(pField);
}
@Override
public Long getExternalId() {
return MoneyWiseAssetType.createExternalId(MoneyWiseAssetType.LOAN, getIndexedId());
}
@Override
public MoneyWiseLoanInfoSet getInfoSet() {
return theInfoSet;
}
/**
* Obtain fieldValue for infoSet.
*
* @param pFieldId the fieldId
* @return the value
*/
private Object getFieldValue(final MetisDataFieldId pFieldId) {
return theInfoSet != null ? theInfoSet.getFieldValue(pFieldId) : null;
}
/**
* Obtain SortCode.
*
* @return the sort code
*/
public char[] getSortCode() {
return hasInfoSet
? theInfoSet.getValue(MoneyWiseAccountInfoClass.SORTCODE, char[].class)
: null;
}
/**
* Obtain Reference.
*
* @return the reference
*/
public char[] getReference() {
return hasInfoSet
? theInfoSet.getValue(MoneyWiseAccountInfoClass.REFERENCE, char[].class)
: null;
}
/**
* Obtain Account.
*
* @return the account
*/
public char[] getAccount() {
return hasInfoSet
? theInfoSet.getValue(MoneyWiseAccountInfoClass.ACCOUNT, char[].class)
: null;
}
/**
* Obtain Notes.
*
* @return the notes
*/
public char[] getNotes() {
return hasInfoSet
? theInfoSet.getValue(MoneyWiseAccountInfoClass.NOTES, char[].class)
: null;
}
@Override
public OceanusMoney getOpeningBalance() {
return hasInfoSet
? theInfoSet.getValue(MoneyWiseAccountInfoClass.OPENINGBALANCE, OceanusMoney.class)
: null;
}
@Override
public MoneyWiseLoanCategory getCategory() {
return getValues().getValue(MoneyWiseBasicResource.CATEGORY_NAME, MoneyWiseLoanCategory.class);
}
/**
* Obtain CategoryId.
*
* @return the categoryId
*/
public Integer getCategoryId() {
final MoneyWiseLoanCategory myCategory = getCategory();
return myCategory == null
? null
: myCategory.getIndexedId();
}
/**
* Obtain CategoryName.
*
* @return the categoryName
*/
public String getCategoryName() {
final MoneyWiseLoanCategory myCategory = getCategory();
return myCategory == null
? null
: myCategory.getName();
}
/**
* Obtain AccountCategoryClass.
*
* @return the actCategoryClass
*/
public MoneyWiseLoanCategoryClass getCategoryClass() {
final MoneyWiseLoanCategory myCategory = getCategory();
return myCategory == null
? null
: myCategory.getCategoryTypeClass();
}
@Override
public boolean isForeign() {
final MoneyWiseCurrency myDefault = getDataSet().getReportingCurrency();
return !myDefault.equals(getAssetCurrency());
}
@Override
public MoneyWiseLoan getBase() {
return (MoneyWiseLoan) super.getBase();
}
@Override
public MoneyWiseLoanList getList() {
return (MoneyWiseLoanList) super.getList();
}
@Override
public MetisDataState getState() {
/* Pop history for self */
MetisDataState myState = super.getState();
/* If we should use the InfoSet */
if ((myState == MetisDataState.CLEAN) && useInfoSet) {
/* Get state for infoSet */
myState = theInfoSet.getState();
}
/* Return the state */
return myState;
}
@Override
public MetisDataEditState getEditState() {
/* Pop history for self */
MetisDataEditState myState = super.getEditState();
/* If we should use the InfoSet */
if (myState == MetisDataEditState.CLEAN
&& useInfoSet) {
/* Get state for infoSet */
myState = theInfoSet.getEditState();
}
/* Return the state */
return myState;
}
@Override
public boolean hasHistory() {
/* Check for history for self */
boolean hasHistory = super.hasHistory();
/* If we should use the InfoSet */
if (!hasHistory && useInfoSet) {
/* Check history for infoSet */
hasHistory = theInfoSet.hasHistory();
}
/* Return details */
return hasHistory;
}
@Override
public void pushHistory() {
/* Push history for self */
super.pushHistory();
/* If we should use the InfoSet */
if (useInfoSet) {
/* Push history for infoSet */
theInfoSet.pushHistory();
}
}
@Override
public void popHistory() {
/* Pop history for self */
super.popHistory();
/* If we should use the InfoSet */
if (useInfoSet) {
/* Pop history for infoSet */
theInfoSet.popHistory();
}
}
@Override
public boolean checkForHistory() {
/* Check for history for self */
boolean bChanges = super.checkForHistory();
/* If we should use the InfoSet */
if (useInfoSet) {
/* Check for history for infoSet */
bChanges |= theInfoSet.checkForHistory();
}
/* return result */
return bChanges;
}
@Override
public MetisDataDifference fieldChanged(final MetisDataFieldId pField) {
/* Handle InfoSet fields */
final MoneyWiseAccountInfoClass myClass = MoneyWiseLoanInfoSet.getClassForField(pField);
if (myClass != null) {
return useInfoSet
? theInfoSet.fieldChanged(myClass)
: MetisDataDifference.IDENTICAL;
}
/* Check super fields */
return super.fieldChanged(pField);
}
@Override
public void setDeleted(final boolean bDeleted) {
/* Pass call to infoSet if required */
if (useInfoSet) {
theInfoSet.setDeleted(bDeleted);
}
/* Pass call onwards */
super.setDeleted(bDeleted);
}
/**
* Is this payee the required class.
*
* @param pClass the required payee class.
* @return true/false
*/
public boolean isLoanClass(final MoneyWiseLoanCategoryClass pClass) {
/* Check for match */
return getCategoryClass() == pClass;
}
/**
* Set defaults.
*
* @throws OceanusException on error
*/
public void setDefaults() throws OceanusException {
getList().getValidator().setDefaults(this);
}
/**
* adjust values after change.
*
* @throws OceanusException on error
*/
public void autoCorrect() throws OceanusException {
getList().getValidator().autoCorrect(this);
}
@Override
public int compareValues(final PrometheusDataItem pThat) {
/* Check the category and then the name */
final MoneyWiseLoan myThat = (MoneyWiseLoan) pThat;
int iDiff = MetisDataDifference.compareObject(getCategory(), myThat.getCategory());
if (iDiff == 0) {
iDiff = MetisDataDifference.compareObject(getName(), myThat.getName());
}
return iDiff;
}
@Override
public void resolveDataSetLinks() throws OceanusException {
/* Update the Encryption details */
super.resolveDataSetLinks();
/* Resolve data links */
final MoneyWiseDataSet myData = getDataSet();
resolveDataLink(MoneyWiseBasicResource.CATEGORY_NAME, myData.getLoanCategories());
resolveDataLink(MoneyWiseStaticDataType.CURRENCY, myData.getAccountCurrencies());
resolveDataLink(MoneyWiseBasicResource.ASSET_PARENT, myData.getPayees());
}
@Override
protected void resolveEditSetLinks() throws OceanusException {
/* Access the editSet */
final PrometheusEditSet myEditSet = getList().getEditSet();
/* Resolve Parent/Category/Currency if required */
resolveDataLink(MoneyWiseBasicResource.ASSET_PARENT, myEditSet.getDataList(MoneyWiseBasicDataType.PAYEE, MoneyWisePayeeList.class));
if (myEditSet.hasDataType(MoneyWiseBasicDataType.LOANCATEGORY)) {
resolveDataLink(MoneyWiseBasicResource.CATEGORY_NAME, myEditSet.getDataList(MoneyWiseBasicDataType.LOANCATEGORY, MoneyWiseLoanCategoryList.class));
}
if (myEditSet.hasDataType(MoneyWiseStaticDataType.CURRENCY)) {
resolveDataLink(MoneyWiseStaticDataType.CURRENCY, myEditSet.getDataList(MoneyWiseStaticDataType.CURRENCY, MoneyWiseCurrencyList.class));
}
/* Resolve links in infoSet */
theInfoSet.resolveEditSetLinks(myEditSet);
}
/**
* Set a new SortCode.
*
* @param pSortCode the new sort code
* @throws OceanusException on error
*/
public void setSortCode(final char[] pSortCode) throws OceanusException {
setInfoSetValue(MoneyWiseAccountInfoClass.SORTCODE, pSortCode);
}
/**
* Set a new Account.
*
* @param pAccount the new account
* @throws OceanusException on error
*/
public void setAccount(final char[] pAccount) throws OceanusException {
setInfoSetValue(MoneyWiseAccountInfoClass.ACCOUNT, pAccount);
}
/**
* Set a new Reference.
*
* @param pReference the new reference
* @throws OceanusException on error
*/
public void setReference(final char[] pReference) throws OceanusException {
setInfoSetValue(MoneyWiseAccountInfoClass.REFERENCE, pReference);
}
/**
* Set a new Notes.
*
* @param pNotes the new notes
* @throws OceanusException on error
*/
public void setNotes(final char[] pNotes) throws OceanusException {
setInfoSetValue(MoneyWiseAccountInfoClass.NOTES, pNotes);
}
/**
* Set a new opening balance.
*
* @param pBalance the new opening balance
* @throws OceanusException on error
*/
public void setOpeningBalance(final OceanusMoney pBalance) throws OceanusException {
setInfoSetValue(MoneyWiseAccountInfoClass.OPENINGBALANCE, pBalance);
}
/**
* Set an infoSet value.
*
* @param pInfoClass the class of info to set
* @param pValue the value to set
* @throws OceanusException on error
*/
private void setInfoSetValue(final MoneyWiseAccountInfoClass pInfoClass,
final Object pValue) throws OceanusException {
/* Reject if there is no infoSet */
if (!hasInfoSet) {
throw new MoneyWiseLogicException(ERROR_BADINFOSET);
}
/* Set the value */
theInfoSet.setValue(pInfoClass, pValue);
}
@Override
public void touchUnderlyingItems() {
/* touch the category and currency */
getCategory().touchItem(this);
getAssetCurrency().touchItem(this);
/* Touch parent */
getParent().touchItem(this);
/* touch infoSet items */
theInfoSet.touchUnderlyingItems();
}
@Override
public void touchOnUpdate() {
/* Touch parent */
getParent().touchItem(this);
}
/**
* Update base loan from an edited loan.
*
* @param pLoan the edited loan
* @return whether changes have been made
*/
@Override
public boolean applyChanges(final PrometheusDataItem pLoan) {
/* Can only update from a loan */
if (!(pLoan instanceof MoneyWiseLoan)) {
return false;
}
final MoneyWiseLoan myLoan = (MoneyWiseLoan) pLoan;
/* Store the current detail into history */
pushHistory();
/* Apply basic changes */
applyBasicChanges(myLoan);
/* Check for changes */
return checkForHistory();
}
@Override
public void adjustMapForItem() {
final MoneyWiseLoanList myList = getList();
final MoneyWiseLoanDataMap myMap = myList.getDataMap();
myMap.adjustForItem(this);
}
@Override
public void removeItem() {
theInfoSet.removeItems();
super.removeItem();
}
/**
* The Loan List class.
*/
public static class MoneyWiseLoanList
extends MoneyWiseAssetBaseList<MoneyWiseLoan> {
/**
* Report fields.
*/
private static final MetisFieldSet<MoneyWiseLoanList> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseLoanList.class);
/**
* The LoanInfo List.
*/
private MoneyWiseLoanInfoList theInfoList;
/**
* The AccountInfoType list.
*/
private MoneyWiseAccountInfoTypeList theInfoTypeList;
/**
* Construct an empty CORE list.
*
* @param pData the DataSet for the list
*/
public MoneyWiseLoanList(final MoneyWiseDataSet pData) {
super(pData, MoneyWiseLoan.class, MoneyWiseBasicDataType.LOAN);
}
/**
* Constructor for a cloned List.
*
* @param pSource the source List
*/
protected MoneyWiseLoanList(final MoneyWiseLoanList pSource) {
super(pSource);
}
@Override
public MetisFieldSet<MoneyWiseLoanList> getDataFieldSet() {
return FIELD_DEFS;
}
@Override
public String listName() {
return LIST_NAME;
}
@Override
public MetisFieldSetDef getItemFields() {
return MoneyWiseLoan.FIELD_DEFS;
}
@Override
protected MoneyWiseLoanDataMap getDataMap() {
return (MoneyWiseLoanDataMap) super.getDataMap();
}
/**
* Obtain the depositInfoList.
*
* @return the deposit info list
*/
public MoneyWiseLoanInfoList getLoanInfo() {
if (theInfoList == null) {
theInfoList = getDataSet().getLoanInfo();
}
return theInfoList;
}
/**
* Obtain the accountInfoTypeList.
*
* @return the account info type list
*/
public MoneyWiseAccountInfoTypeList getActInfoTypes() {
if (theInfoTypeList == null) {
theInfoTypeList = getEditSet() == null
? getDataSet().getActInfoTypes()
: getEditSet().getDataList(MoneyWiseStaticDataType.ACCOUNTINFOTYPE, MoneyWiseAccountInfoTypeList.class);
}
return theInfoTypeList;
}
@Override
protected MoneyWiseLoanList getEmptyList(final PrometheusListStyle pStyle) {
final MoneyWiseLoanList myList = new MoneyWiseLoanList(this);
myList.setStyle(pStyle);
return myList;
}
/**
* Derive Edit list.
*
* @param pEditSet the editSet
* @return the edit list
* @throws OceanusException on error
*/
public MoneyWiseLoanList deriveEditList(final PrometheusEditSet pEditSet) throws OceanusException {
/* Build an empty List */
final MoneyWiseLoanList myList = getEmptyList(PrometheusListStyle.EDIT);
final MoneyWisePayeeList myPayees = pEditSet.getDataList(MoneyWiseBasicDataType.PAYEE, MoneyWisePayeeList.class);
myList.ensureMap(myPayees);
pEditSet.setEditEntryList(MoneyWiseBasicDataType.LOAN, myList);
myList.getValidator().setEditSet(pEditSet);
/* Store InfoType list */
myList.theInfoTypeList = pEditSet.getDataList(MoneyWiseStaticDataType.ACCOUNTINFOTYPE, MoneyWiseAccountInfoTypeList.class);
/* Create info List */
final MoneyWiseLoanInfoList myLoanInfo = getLoanInfo();
myList.theInfoList = myLoanInfo.getEmptyList(PrometheusListStyle.EDIT);
pEditSet.setEditEntryList(MoneyWiseBasicDataType.LOANINFO, myList.theInfoList);
/* Store the editSet */
myList.setEditSet(pEditSet);
/* Loop through the loans */
final Iterator<MoneyWiseLoan> myIterator = iterator();
while (myIterator.hasNext()) {
final MoneyWiseLoan myCurr = myIterator.next();
/* Ignore deleted deposits */
if (myCurr.isDeleted()) {
continue;
}
/* Build the new linked loan and add it to the list */
final MoneyWiseLoan myLoan = new MoneyWiseLoan(myList, myCurr);
myList.add(myLoan);
myLoan.resolveEditSetLinks();
/* Adjust the map */
myLoan.adjustMapForItem();
}
/* Return the list */
return myList;
}
@Override
public MoneyWiseLoan findItemByName(final String pName) {
/* look up the name in the map */
return getDataMap().findItemByName(pName);
}
@Override
public boolean checkAvailableName(final String pName) {
/* check availability in map */
return getDataMap().availableName(pName);
}
@Override
public boolean validNameCount(final String pName) {
/* check availability in map */
return getDataMap().validNameCount(pName);
}
@Override
public MoneyWiseLoan addCopyItem(final PrometheusDataItem pLoan) {
/* Can only clone a Loan */
if (!(pLoan instanceof MoneyWiseLoan)) {
throw new UnsupportedOperationException();
}
final MoneyWiseLoan myLoan = new MoneyWiseLoan(this, (MoneyWiseLoan) pLoan);
add(myLoan);
return myLoan;
}
@Override
public MoneyWiseLoan addNewItem() {
final MoneyWiseLoan myLoan = new MoneyWiseLoan(this);
add(myLoan);
return myLoan;
}
@Override
public MoneyWiseLoan addValuesItem(final PrometheusDataValues pValues) throws OceanusException {
/* Create the loan */
final MoneyWiseLoan myLoan = new MoneyWiseLoan(this, pValues);
/* Check that this LoanId has not been previously added */
if (!isIdUnique(myLoan.getIndexedId())) {
myLoan.addError(ERROR_DUPLICATE, MetisDataResource.DATA_ID);
throw new MoneyWiseDataException(myLoan, ERROR_VALIDATION);
}
/* Add to the list */
add(myLoan);
/* Loop through the info items */
if (pValues.hasInfoItems()) {
/* Loop through the items */
final Iterator<PrometheusInfoItem> myIterator = pValues.infoIterator();
while (myIterator.hasNext()) {
final PrometheusInfoItem myItem = myIterator.next();
/* Build info */
final PrometheusDataValues myValues = myItem.getValues(myLoan);
theInfoList.addValuesItem(myValues);
}
}
/* Return it */
return myLoan;
}
/**
* Ensure Map based on the payee list.
*
* @param pPayees the payee list
*/
private void ensureMap(final MoneyWisePayeeList pPayees) {
setDataMap(new MoneyWiseLoanDataMap(pPayees));
}
@Override
protected MoneyWiseLoanDataMap allocateDataMap() {
return new MoneyWiseLoanDataMap(getDataSet().getPayees());
}
@Override
public void postProcessOnLoad() throws OceanusException {
/* Resolve links and sort the data */
super.resolveDataSetLinks();
reSort();
}
}
/**
* The dataMap class.
*/
protected static class MoneyWiseLoanDataMap
implements PrometheusDataMapItem, MetisFieldItem {
/**
* Report fields.
*/
private static final MetisFieldSet<MoneyWiseLoanDataMap> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseLoanDataMap.class);
/*
* UnderlyingMap Field Id.
*/
static {
FIELD_DEFS.declareLocalField(MoneyWiseBasicResource.MONEYWISEDATA_MAP_UNDERLYING, MoneyWiseLoanDataMap::getUnderlyingMap);
}
/**
* The assetMap.
*/
private final MoneyWiseAssetDataMap theUnderlyingMap;
/**
* Constructor.
*
* @param pPayees the payee list
*/
protected MoneyWiseLoanDataMap(final MoneyWisePayeeList pPayees) {
theUnderlyingMap = pPayees.getDataMap().getUnderlyingMap();
}
@Override
public MetisFieldSet<MoneyWiseLoanDataMap> getDataFieldSet() {
return FIELD_DEFS;
}
@Override
public String formatObject(final OceanusDataFormatter pFormatter) {
return FIELD_DEFS.getName();
}
/**
* Obtain the underlying map.
*
* @return the underlying map
*/
private MoneyWiseAssetDataMap getUnderlyingMap() {
return theUnderlyingMap;
}
@Override
public void resetMap() {
/* No action */
}
@Override
public void adjustForItem(final PrometheusDataItem pItem) {
/* Adjust name count */
theUnderlyingMap.adjustForItem(pItem);
}
/**
* find item by name.
*
* @param pName the name to look up
* @return the matching item
*/
public MoneyWiseLoan findItemByName(final String pName) {
final MoneyWiseAssetBase myAsset = theUnderlyingMap.findAssetByName(pName);
return myAsset instanceof MoneyWiseLoan myLoan
? myLoan
: null;
}
/**
* Check validity of name.
*
* @param pName the name to look up
* @return true/false
*/
public boolean validNameCount(final String pName) {
return theUnderlyingMap.validNameCount(pName);
}
/**
* Check availability of name.
*
* @param pName the key to look up
* @return true/false
*/
public boolean availableName(final String pName) {
return theUnderlyingMap.availableKey(pName);
}
}
}