Java tutorial
/* * 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 com.creditcloud.interestbearing.model; import com.creditcloud.interestbearing.ta.model.ProductFundMetadata; import com.creditcloud.interestbearing.ta.model.ProductFundRegistrationMetadata; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.util.ArrayList; import java.util.List; import lombok.Data; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; /** * * @author GuohuaZhang */ @Data @JsonIgnoreProperties(ignoreUnknown = true) public class CreditCloudTAConfig extends ConfigObjBase { /** * ?TA? */ private String tenantId = ""; private String name = ""; private String desc = ""; private String url = ""; private List<ProductFundRegistrationMetadata> registeredProducts = new ArrayList<>(); @Override public String toString() { return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE, false, false); } /** * ?TA?(???) * * @param product */ public void addRegisteredProduct(ProductFundRegistrationMetadata product) { if (product == null || product.getProduct() == null) { return; } if (registeredProducts == null) { registeredProducts = new ArrayList<>(); } if (!isProductAlreadyRegistered(product)) { registeredProducts.add(product); } } /** * ?TA?(???) * * @param product */ public void addOrReplaceRegisteredProduct(ProductFundRegistrationMetadata product) { if (product == null || product.getProduct() == null) { return; } if (registeredProducts == null) { registeredProducts = new ArrayList<>(); } for (ProductFundRegistrationMetadata r : registeredProducts) { if (product.getProduct().isOfSameProduct(r.getProduct())) { { registeredProducts.remove(r); break; } } } registeredProducts.add(product); } public boolean isProductAlreadyRegistered(ProductFundRegistrationMetadata product) { if (registeredProducts == null) { return false; } if (product == null || product.getProduct() == null) { return false; } for (ProductFundRegistrationMetadata r : registeredProducts) { if (product.getProduct().isOfSameProduct(r.getProduct())) { return true; } } return false; } public boolean isProductAlreadyRegistered(String brokerName, String fundId) { if (registeredProducts == null) { return false; } if (brokerName == null || fundId == null) { return false; } for (ProductFundRegistrationMetadata r : registeredProducts) { if (r.getProduct() == null) { continue; } if (r.getProduct().isOfSameProduct(brokerName, fundId)) { return true; } } return false; } public Pair<String, String> firstFund() { if (registeredProducts == null || registeredProducts.isEmpty()) { return null; } ProductFundMetadata p = registeredProducts.get(0).getProduct(); if (p == null) { return null; } String broker = StringUtils.defaultString(p.getBroker()); String fundId = StringUtils.defaultString(p.getFund_id()); return ImmutablePair.of(broker, fundId); } }