Example usage for java.util.function UnaryOperator apply

List of usage examples for java.util.function UnaryOperator apply

Introduction

In this page you can find the example usage for java.util.function UnaryOperator apply.

Prototype

R apply(T t);

Source Link

Document

Applies this function to the given argument.

Usage

From source file:org.briljantframework.array.AbstractComplexArray.java

@Override
public Complex reduce(Complex identity, BinaryOperator<Complex> reduce, UnaryOperator<Complex> map) {
    for (int i = 0; i < size(); i++) {
        identity = reduce.apply(map.apply(get(i)), identity);
    }/*from   w  w w. j  av  a  2 s. c  om*/
    return identity;
}

From source file:org.fenixedu.treasury.services.integration.erp.ERPExporter.java

private String generateERPFile(FinantialInstitution institution, DateTime fromDate, DateTime toDate,
        List<? extends FinantialDocument> allDocuments, Boolean generateAllCustomers,
        Boolean generateAllProducts,
        java.util.function.UnaryOperator<AuditFile> preProcessFunctionBeforeSerialize) {

    // Build SAFT-AuditFile
    AuditFile auditFile = new AuditFile();
    // ThreadInformation information = 
    // SaftThreadRegister.retrieveCurrentThreadInformation();

    // Build SAFT-HEADER (Chapter 1 in AuditFile)
    Header header = this.createSAFTHeader(fromDate, toDate, institution, ERP_HEADER_VERSION_1_00_00);
    // SetHeader//from   w w  w .  j av a 2  s .c o m
    auditFile.setHeader(header);

    // Build Master-Files
    oecd.standardauditfile_tax.pt_1.AuditFile.MasterFiles masterFiles = new oecd.standardauditfile_tax.pt_1.AuditFile.MasterFiles();

    // SetMasterFiles
    auditFile.setMasterFiles(masterFiles);

    // Build SAFT-MovementOfGoods (Customer and Products are built inside)
    // ProductsTable (Chapter 2.4 in AuditFile)
    List<oecd.standardauditfile_tax.pt_1.Product> productList = masterFiles.getProduct();
    Map<String, oecd.standardauditfile_tax.pt_1.Product> productMap = new HashMap<String, oecd.standardauditfile_tax.pt_1.Product>();
    Set<String> productCodes = new HashSet<String>();

    // ClientsTable (Chapter 2.2 in AuditFile)
    List<oecd.standardauditfile_tax.pt_1.Customer> customerList = masterFiles.getCustomer();
    Map<String, oecd.standardauditfile_tax.pt_1.Customer> customerMap = new HashMap<String, oecd.standardauditfile_tax.pt_1.Customer>();

    // Readd All  Clients if needed
    if (generateAllCustomers) {
        logger.info("Reading all Customers in Institution " + institution.getCode());

        Set<Customer> allCustomers = new HashSet<Customer>();
        for (DebtAccount debt : institution.getDebtAccountsSet()) {
            allCustomers.add(debt.getCustomer());
        }

        // Update the Total Objects Count
        // information.setTotalCounter(allCustomers.size() +
        // allProducts.size() + allDocuments.size() * 10);

        int i = 0;
        for (Customer customer : allCustomers) {
            oecd.standardauditfile_tax.pt_1.Customer saftCustomer = this
                    .convertCustomerToSAFTCustomer(customer);
            // information.setCurrentCounter(information.getCurrentCounter()
            // + 1);
            customerMap.put(saftCustomer.getCustomerID(), saftCustomer);
            i++;
            if (i % 100 == 0) {
                logger.info("Processing " + i + "/" + allCustomers.size() + " Customers in Institution "
                        + institution.getCode());
            }
        }
    }
    // Readd All Products if needed
    if (generateAllProducts) {

        logger.info("Reading all Customers in Institution " + institution.getCode());
        Set<Product> allProducts = institution.getAvailableProductsSet();
        int i = 0;
        for (Product product : allProducts) {
            if (!productCodes.contains(product.getCode())) {
                oecd.standardauditfile_tax.pt_1.Product saftProduct = this.convertProductToSAFTProduct(product);
                productCodes.add(product.getCode());
                productMap.put(saftProduct.getProductCode(), saftProduct);
            }

            i++;
            if (i % 100 == 0) {
                logger.info("Processing " + i + "/" + allProducts.size() + " Products in Institution "
                        + institution.getCode());
            }

            // information.setCurrentCounter(information.getCurrentCounter()
            // + 1);
        }
    } else {
        // information.setTotalCounter(allDocuments.size() * 10);
        // Update the Total Objects Count
        // information.setCurrentCounter(0);
    }

    // TaxTable (Chapter 2.5 in AuditFile)
    oecd.standardauditfile_tax.pt_1.TaxTable taxTable = new oecd.standardauditfile_tax.pt_1.TaxTable();
    masterFiles.setTaxTable(taxTable);

    for (Vat vat : institution.getVatsSet()) {
        taxTable.getTaxTableEntry().add(this.convertVATtoTaxTableEntry(vat, institution));
    }

    // Set MovementOfGoods in SourceDocuments(AuditFile)
    oecd.standardauditfile_tax.pt_1.SourceDocuments sourceDocuments = new oecd.standardauditfile_tax.pt_1.SourceDocuments();
    auditFile.setSourceDocuments(sourceDocuments);

    SourceDocuments.SalesInvoices invoices = new SourceDocuments.SalesInvoices();
    SourceDocuments.WorkingDocuments workingDocuments = new SourceDocuments.WorkingDocuments();
    Payments paymentsDocuments = new Payments();

    BigInteger numberOfPaymentsDocuments = BigInteger.ZERO;
    BigDecimal totalDebitOfPaymentsDocuments = BigDecimal.ZERO;
    BigDecimal totalCreditOfPaymentsDocuments = BigDecimal.ZERO;

    BigInteger numberOfWorkingDocuments = BigInteger.ZERO;
    BigDecimal totalDebitOfWorkingDocuments = BigDecimal.ZERO;
    BigDecimal totalCreditOfWorkingDocuments = BigDecimal.ZERO;

    invoices.setNumberOfEntries(BigInteger.ZERO);
    invoices.setTotalCredit(BigDecimal.ZERO);
    invoices.setTotalDebit(BigDecimal.ZERO);

    //        int i = 0;
    for (FinantialDocument document : allDocuments) {
        if ((document.isCreditNote() || document.isDebitNote())
                && (document.isClosed() || document.isAnnulled())) {
            try {
                WorkDocument workDocument = convertToSAFTWorkDocument((Invoice) document, customerMap,
                        productMap);
                workingDocuments.getWorkDocument().add(workDocument);

                // AcumulateValues
                numberOfWorkingDocuments = numberOfWorkingDocuments.add(BigInteger.ONE);
                if (!document.isAnnulled()) {
                    if (document.isDebitNote()) {
                        totalDebitOfWorkingDocuments = totalDebitOfWorkingDocuments
                                .add(workDocument.getDocumentTotals().getNetTotal());
                    } else if (document.isCreditNote()) {
                        totalCreditOfWorkingDocuments = totalCreditOfWorkingDocuments
                                .add(workDocument.getDocumentTotals().getNetTotal());
                    }
                }

                //                    i++;

            } catch (Exception ex) {
                logger.error("Error processing document " + document.getUiDocumentNumber() + ": "
                        + ex.getLocalizedMessage());
                throw ex;
            }
        } else {
            logger.info("Ignoring document " + document.getUiDocumentNumber() + " because is not closed yet.");
        }

    }
    // Update Totals of Workingdocuments
    workingDocuments.setNumberOfEntries(numberOfWorkingDocuments);
    workingDocuments.setTotalCredit(totalCreditOfWorkingDocuments.setScale(2, RoundingMode.HALF_EVEN));
    workingDocuments.setTotalDebit(totalDebitOfWorkingDocuments.setScale(2, RoundingMode.HALF_EVEN));

    sourceDocuments.setWorkingDocuments(workingDocuments);

    //PROCESSING PAYMENTS TABLE

    paymentsDocuments.setNumberOfEntries(BigInteger.ZERO);
    paymentsDocuments.setTotalCredit(BigDecimal.ZERO);
    paymentsDocuments.setTotalDebit(BigDecimal.ZERO);
    for (FinantialDocument document : allDocuments) {
        if (document.isSettlementNote() && (document.isClosed() || document.isAnnulled())) {
            try {
                Payment paymentDocument = convertToSAFTPaymentDocument((SettlementNote) document, customerMap,
                        productMap);
                paymentsDocuments.getPayment().add(paymentDocument);

                // AcumulateValues
                numberOfPaymentsDocuments = numberOfPaymentsDocuments.add(BigInteger.ONE);
                if (!document.isAnnulled()) {
                    totalCreditOfPaymentsDocuments = totalCreditOfPaymentsDocuments
                            .add(((SettlementNote) document).getTotalCreditAmount());
                    totalDebitOfPaymentsDocuments = totalDebitOfPaymentsDocuments
                            .add(((SettlementNote) document).getTotalDebitAmount());
                }
                //                    i++;
            } catch (Exception ex) {
                // persistenceSupport.flush();
                logger.error("Error processing document " + document.getUiDocumentNumber() + ": "
                        + ex.getLocalizedMessage());
                throw ex;
            }
        } else {
            logger.info("Ignoring document " + document.getUiDocumentNumber() + " because is not closed yet.");
        }

    }

    // Update Totals of Payment Documents
    paymentsDocuments.setNumberOfEntries(numberOfPaymentsDocuments);
    paymentsDocuments.setTotalCredit(totalCreditOfPaymentsDocuments.setScale(2, RoundingMode.HALF_EVEN));
    paymentsDocuments.setTotalDebit(totalDebitOfPaymentsDocuments.setScale(2, RoundingMode.HALF_EVEN));
    sourceDocuments.setPayments(paymentsDocuments);

    // Update the Customer Table in SAFT
    for (oecd.standardauditfile_tax.pt_1.Customer customer : customerMap.values()) {
        customerList.add(customer);
    }

    // Update the Product Table in SAFT
    for (oecd.standardauditfile_tax.pt_1.Product product : productMap.values()) {
        productList.add(product);
    }

    if (preProcessFunctionBeforeSerialize != null) {
        auditFile = preProcessFunctionBeforeSerialize.apply(auditFile);
    }
    String xml = exportAuditFileToXML(auditFile);

    logger.info("SAFT File export concluded with success.");
    return xml;
}

From source file:org.languagetool.tagging.uk.UkrainianTagger.java

private List<AnalyzedToken> getAdjustedAnalyzedTokens(String word, String adjustedWord, Pattern posTagRegex,
        String additionalTag, UnaryOperator<String> lemmaFunction) {

    List<AnalyzedToken> newTokens = super.getAnalyzedTokens(adjustedWord);

    if (newTokens.get(0).hasNoTag())
        return new ArrayList<>();

    List<AnalyzedToken> derivedTokens = new ArrayList<>();

    for (int i = 0; i < newTokens.size(); i++) {
        AnalyzedToken analyzedToken = newTokens.get(i);
        String posTag = analyzedToken.getPOSTag();

        if (adjustedWord.equals(analyzedToken.getToken()) // filter out tokens with accents etc with null pos tag
                && (posTagRegex == null || posTagRegex.matcher(posTag).matches())) {

            String lemma = analyzedToken.getLemma();
            if (lemmaFunction != null) {
                lemma = lemmaFunction.apply(lemma);
            }//  w ww.java2  s  .co m

            if (additionalTag != null) {
                posTag = PosTagHelper.addIfNotContains(posTag, additionalTag);
            }

            AnalyzedToken newToken = new AnalyzedToken(word, posTag, lemma);
            derivedTokens.add(newToken);
        }
    }

    return derivedTokens;
}