Package org.zeroexchange.model.mcredit

Examples of org.zeroexchange.model.mcredit.CreditLine


    public void testDebtRoute() throws DebtRotingException {
        User a = new User();
        User b = new User();
        User c = new User();
        User d = new User();
        CreditLine l1 = new CreditLine();
        l1.setMaxCreditValue(BigDecimal.TEN);
        l1.setDebtor(a);
        l1.setCreditor(b);
        CreditLine l2 = new CreditLine();
        l2.setMaxCreditValue(BigDecimal.ONE);
        l2.setDebtor(b);
        l2.setCreditor(c);
        CreditLine l3 = new CreditLine();
        l3.setMaxCreditValue(BigDecimal.TEN);
        l3.setDebtor(c);
        l3.setCreditor(d);
       
        CreditPath path = new CreditPath();
        Collection<CreditLine> creditLines = path.getPath();
        creditLines.add(l1);
        creditLines.add(l2);
View Full Code Here


    public BigDecimal getFirstDebtorDebt() {
        Collection<CreditPath> twoPartnersPaths = getPaths();
        BigDecimal debt = BigDecimal.ZERO;
        for(CreditPath path: twoPartnersPaths) {
            if(!path.getPath().isEmpty()) {
                CreditLine line = path.getPath().get(0);
                debt = debt.add(line.getCurrentCredit());
            }
        }
        return debt;
    }
View Full Code Here

     * {@inheritDoc}
     */
    @Transactional
    @Override
    public CreditLine setCreditLine(User creditor, User debtor, BigDecimal value) {
        CreditLine creditLine = creditLineDAO.getCreditLine(creditor, debtor);
        if(creditLine == null) {
            creditLine = new CreditLine();
            creditLine.setCreditor(creditor);
            creditLine.setDebtor(debtor);
           
        }
        creditLine.setMaxCreditValue(value);
        creditLineDAO.save(creditLine);
        return creditLine;
    }
View Full Code Here

     */
    protected Collection<CreditLine> roteDebt(Collection<CreditLine> path,
            BigDecimal valueToMove) {
        Collection<CreditLine> complementatyLines = new LinkedList<CreditLine>();
        for(CreditLine line: path) {
            CreditLine complementaryLine = creditLineReader.getComplemetaryCreditLine(line);
            BigDecimal complementaryDebt = BigDecimal.ZERO;
            if(complementaryLine != null) {
                complementaryDebt = complementaryLine.getCurrentCredit();
            }
            BigDecimal rest = complementaryDebt.subtract(valueToMove);
            if(complementaryLine != null) {
                complementaryLine.setCurrentCredit(rest.max(BigDecimal.ZERO));
                complementatyLines.add(complementaryLine);
            }
            line.setCurrentCredit(line.getCurrentCredit().add(rest.negate().max(BigDecimal.ZERO)));
        }
        return complementatyLines;
View Full Code Here

    @Override
    public BigDecimal getAvailableAmount(CreditLine creditLine) {
        if(creditLine == null) {
            return BigDecimal.ZERO;
        }
        CreditLine complementaryLine = getComplemetaryCreditLine(creditLine);
        BigDecimal availableAmount = creditLine.getMaxCreditValue().subtract(creditLine.getCurrentCredit());
        if(availableAmount.compareTo(BigDecimal.ZERO) <= 0 && complementaryLine != null) {
            availableAmount = availableAmount.add(complementaryLine.getCurrentCredit());
        }
        return availableAmount;
    }
View Full Code Here

                if(allowedValue.compareTo(BigDecimal.ZERO) <= 0) {
                    continue;
                }
                if(intermediateCreditor.equals(creditor)) {
                    CreditPath foundPath = new CreditPath();
                    CreditLine firstLine = path.getFirst();
                    foundPath.setCreditor(creditor);
                    foundPath.setDebtor(firstLine.getDebtor());
                           
                    foundPath.getPath().addAll(path);
                    paths.getPaths().add(foundPath);
                    break;
                }
View Full Code Here

            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item<ICellPopulator<CreditLine>> cellItem,
                    String componentId, IModel<CreditLine> rowModel) {
                CreditLine line = rowModel.getObject();
                User debtor = line.getDebtor();
                cellItem.add(new Label(componentId, debtor != null ? debtor.getDisplayName() : "-"));
            }
        });
       
        //Amount
        columns.add(new AbstractColumn<CreditLine, String>(new ResourceModel(MKEY_MAX_AMOUNT)) {
            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item<ICellPopulator<CreditLine>> cellItem,
                    String componentId, IModel<CreditLine> rowModel) {
                final CreditLine line = rowModel.getObject();
                cellItem.add(new AttributeAppender("style", ";width:110px;"));//TODO: constant
                cellItem.add(new AjaxEditorLink<BigDecimal>(componentId, new PropertyModel<BigDecimal>(line, "maxCreditValue")) {
                    private static final long serialVersionUID = 1L;
                    private NumberTextField<BigDecimal> amountInput;

                    @Override
                    protected boolean onValueSubmit(AjaxRequestTarget target) {
                        BigDecimal newValue = amountInput.getModelObject();
                        creditLineWriter.setCreditLine(line.getCreditor(), line.getDebtor(), newValue);
                        return true;
                    }

                    @Override
                    protected Component getFormControl(String controlId, final IModel<BigDecimal> model) {
View Full Code Here

TOP

Related Classes of org.zeroexchange.model.mcredit.CreditLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.