org.kisoonlineapp.uc.view.KostenView.java Source code

Java tutorial

Introduction

Here is the source code for org.kisoonlineapp.uc.view.KostenView.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.kisoonlineapp.uc.view;

import java.math.BigDecimal;
import java.util.Objects;
import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.kisoonlineapp.cdi.MessageResolver;
import org.kisoonlineapp.model.Kosten;

/**
 *
 * @author berni
 */
@View
public class KostenView {

    @Inject
    MessageResolver messageResolver;

    public KostenView() {
    }

    public KostenView(MessageResolver messageResolver) {
        this.messageResolver = messageResolver;
    }

    public String formatKosten(Kosten kosten) {
        final StringBuilder sb = new StringBuilder();

        BigDecimal kostenWert = null;
        String kostenHinweisText = null;
        if (kosten != null) {
            if (kosten.getBetragEuro() != null) {
                kostenWert = kosten.getBetragEuro();
            }
            if (StringUtils.isNotBlank(kosten.getHinweis())) {
                kostenHinweisText = kosten.getHinweis();
            }
        }
        //---
        if (Objects.nonNull(kostenWert) && Objects.nonNull(kostenHinweisText)) {
            sb.append(messageResolver.retrieveMessageFor("kostenKostenHinweis", kostenWert, kostenHinweisText));
        } else if (Objects.nonNull(kostenWert) && Objects.isNull(kostenHinweisText)) {
            sb.append(messageResolver.retrieveMessageFor("kostenKosten", kostenWert));
        } else if (Objects.isNull(kostenWert) && Objects.nonNull(kostenHinweisText)) {
            sb.append(messageResolver.retrieveMessageFor("kostenKeineKostenHinweis", kostenHinweisText));
        } else {
            sb.append(messageResolver.retrieveMessageFor("kostenKeineAngaben", kostenHinweisText));
        }

        return sb.toString();
    }
}