Skip to content

Commit

Permalink
add nullable annos
Browse files Browse the repository at this point in the history
  • Loading branch information
vananiev committed Oct 27, 2024
1 parent 59f52b8 commit d4cca1e
Show file tree
Hide file tree
Showing 34 changed files with 117 additions and 71 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@
<arg>-AskipDefs=V2022_1_0_1</arg>
<!-- Checker framework inner file https://github.com/typetools/checker-framework/blob/master/checker/src/main/java/org/checkerframework/checker/nullness/permit-nullness-assertion-exception.astub -->
<arg>-Astubs=permit-nullness-assertion-exception.astub</arg>
<arg>-AsuppressWarnings=type.anno.before.modifier</arg>
<!-- Remove type.anno.before.modifier -->
<arg>-AsuppressWarnings=type.anno.before.modifier,type.arguments.not.inferred,removal</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class EventCashFlowConverter implements EntityConverter<EventCashFlowEnti
private final PortfolioRepository portfolioRepository;
private final CashFlowTypeRepository cashFlowTypeRepository;

@SuppressWarnings({"nullness", "DataFlowIssue"})
@Override
public EventCashFlowEntity toEntity(EventCashFlow eventCashFlow) {
PortfolioEntity portfolioEntity = portfolioRepository.getReferenceById(eventCashFlow.getPortfolio());
Expand All @@ -45,6 +46,7 @@ public EventCashFlowEntity toEntity(EventCashFlow eventCashFlow) {
entity.setTimestamp(eventCashFlow.getTimestamp());
entity.setCashFlowType(cashFlowTypeEntity);
entity.setValue(eventCashFlow.getValue());
//noinspection ConstantValue
if(eventCashFlow.getCurrency() != null) entity.setCurrency(eventCashFlow.getCurrency());
if (eventCashFlow.getDescription() != null &&! eventCashFlow.getDescription().isEmpty()) {
entity.setDescription(eventCashFlow.getDescription());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ru/investbook/converter/IssuerConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@Component
public class IssuerConverter implements EntityConverter<IssuerEntity, Issuer> {

@SuppressWarnings({"nullness", "DataFlowIssue"})
@Override
public IssuerEntity toEntity(Issuer issuer) {
IssuerEntity entity = new IssuerEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@Component
public class PortfolioCashConverter implements EntityConverter<PortfolioCashEntity, PortfolioCash> {

@SuppressWarnings({"nullness", "DataFlowIssue"})
@Override
public PortfolioCashEntity toEntity(PortfolioCash cash) {
PortfolioCashEntity entity = new PortfolioCashEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
public class PortfolioPropertyConverter implements EntityConverter<PortfolioPropertyEntity, PortfolioProperty> {
private final PortfolioRepository portfolioRepository;

@SuppressWarnings({"nullness", "DataFlowIssue"})
@Override
public PortfolioPropertyEntity toEntity(PortfolioProperty property) {
PortfolioEntity portfolioEntity = portfolioRepository.getReferenceById(property.getPortfolio());

PortfolioPropertyEntity entity = new PortfolioPropertyEntity();
entity.setId(property.getId());
entity.setPortfolio(portfolioEntity);
entity.setTimestamp(property.getTimestamp());
entity.setTimestamp(property.getTimestamp()); // is null, default value is set
entity.setProperty(property.getProperty().name());
entity.setValue(property.getValue());
return entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@RequiredArgsConstructor
public class SecurityConverter implements EntityConverter<SecurityEntity, Security> {

@SuppressWarnings({"nullness", "DataFlowIssue"})
@Override
public SecurityEntity toEntity(Security security) {
SecurityEntity entity = new SecurityEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class SecurityEventCashFlowConverter implements EntityConverter<SecurityE
private final SecurityRepository securityRepository;
private final CashFlowTypeRepository cashFlowTypeRepository;

@SuppressWarnings({"nullness", "DataFlowIssue"})
@Override
public SecurityEventCashFlowEntity toEntity(SecurityEventCashFlow eventCashFlow) {
SecurityEntity securityEntity = securityRepository.getReferenceById(eventCashFlow.getSecurity());
Expand All @@ -51,6 +52,7 @@ public SecurityEventCashFlowEntity toEntity(SecurityEventCashFlow eventCashFlow)
entity.setCount(eventCashFlow.getCount());
entity.setCashFlowType(cashFlowTypeEntity);
entity.setValue(eventCashFlow.getValue());
//noinspection ConstantValue
if (eventCashFlow.getCurrency() != null) entity.setCurrency(eventCashFlow.getCurrency());
return entity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
public class SecurityQuoteConverter implements EntityConverter<SecurityQuoteEntity, SecurityQuote> {
private final SecurityRepository securityRepository;

@SuppressWarnings({"nullness", "DataFlowIssue"})
@Override
public SecurityQuoteEntity toEntity(SecurityQuote quote) {
SecurityEntity securityEntity = securityRepository.getReferenceById(quote.getSecurity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
import ru.investbook.entity.CashFlowTypeEntity;
import ru.investbook.entity.TransactionCashFlowEntity;
import ru.investbook.repository.CashFlowTypeRepository;
import ru.investbook.repository.TransactionRepository;

@Component
@RequiredArgsConstructor
public class TransactionCashFlowConverter implements EntityConverter<TransactionCashFlowEntity, TransactionCashFlow> {
private final TransactionRepository transactionRepository;
private final CashFlowTypeRepository cashFlowTypeRepository;

@SuppressWarnings({"nullness", "DataFlowIssue"})
@Override
public TransactionCashFlowEntity toEntity(TransactionCashFlow cash) {
CashFlowTypeEntity cashFlowTypeEntity = cashFlowTypeRepository.getReferenceById(cash.getEventType().getId());
Expand All @@ -42,6 +41,7 @@ public TransactionCashFlowEntity toEntity(TransactionCashFlow cash) {
entity.setTransactionId(cash.getTransactionId());
entity.setCashFlowType(cashFlowTypeEntity);
entity.setValue(cash.getValue());
//noinspection ConstantValue
if (cash.getCurrency() != null) entity.setCurrency(cash.getCurrency());
return entity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
public class TransactionConverter implements EntityConverter<TransactionEntity, Transaction> {
private final SecurityRepository securityRepository;

@SuppressWarnings({"nullness", "DataFlowIssue"})
@Override
public TransactionEntity toEntity(Transaction transaction) {
SecurityEntity securityEntity = securityRepository.getReferenceById(transaction.getSecurity());

TransactionEntity entity = new TransactionEntity();
//noinspection DataFlowIssue
entity.setId(transaction.getId());
entity.setTradeId(transaction.getTradeId());
entity.setPortfolio(transaction.getPortfolio());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spacious_team.broker.pojo.CashFlowType;
import org.spacious_team.broker.pojo.EventCashFlow;
import org.spacious_team.table_wrapper.api.PatternTableColumn;
Expand All @@ -36,7 +37,7 @@

public class TinkoffCashFlowTable extends SingleAbstractReportTable<EventCashFlow> {

private String currency = null;
private String currency = "";

protected TinkoffCashFlowTable(SingleBrokerReport report) {
super(report,
Expand All @@ -48,9 +49,9 @@ protected TinkoffCashFlowTable(SingleBrokerReport report) {
}

@Override
protected EventCashFlow parseRow(TableRow row) {
protected @Nullable EventCashFlow parseRow(TableRow row) {
currency = TinkoffCashFlowTableHelper.getCurrency(row, currency);
if (currency == null) {
if (!hasLength(currency)) {
return null;
}
String operationOriginal = row.getStringCellValueOrDefault(OPERATION, "");
Expand Down Expand Up @@ -86,7 +87,7 @@ protected EventCashFlow parseRow(TableRow row) {
}

private EventCashFlow.EventCashFlowBuilder getBuilder(TableRow row, String currency) {
String description = row.getStringCellValueOrDefault(DESCRIPTION, null);
@Nullable String description = row.getStringCellValueOrDefault(DESCRIPTION, null);
return EventCashFlow.builder()
.portfolio(getReport().getPortfolio())
.timestamp(getReport().convertToInstant(row.getStringCellValue(DATE)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TinkoffCashFlowTableHelper {
static String getCurrency(TableRow row, String defaultCurrency) {
boolean isCurrencyHeader = !hasLength(row.getStringCellValueOrDefault(DATE, null));
if (isCurrencyHeader) {
String currency = row.getStringCellValueOrDefault(CURRENCY, null);
String currency = row.getStringCellValueOrDefault(CURRENCY, "");
if (hasLength(currency) && currency.length() == 3) { // RUB, USD, ... (ISO format)
return currency.toUpperCase();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spacious_team.broker.pojo.PortfolioCash;
import org.spacious_team.table_wrapper.api.PatternTableColumn;
import org.spacious_team.table_wrapper.api.TableColumn;
Expand All @@ -40,12 +41,12 @@ protected TinkoffCashTable(SingleBrokerReport report) {
}

@Override
protected PortfolioCash parseRow(TableRow row) {
BigDecimal value = row.getBigDecimalCellValueOrDefault(CashTableHeader.VALUE, null);
protected @Nullable PortfolioCash parseRow(TableRow row) {
@Nullable BigDecimal value = row.getBigDecimalCellValueOrDefault(CashTableHeader.VALUE, null);
if (value == null) {
return null;
}
String currency = row.getStringCellValue(CashTableHeader.CURRENCY);
@Nullable String currency = row.getStringCellValue(CashTableHeader.CURRENCY);
if (currency == null || currency.length() != 3) {
return null; // неизвестный контракт GLD_MOEX указывается в качестве валюты
}
Expand All @@ -58,12 +59,12 @@ protected PortfolioCash parseRow(TableRow row) {
.build();
}

@Getter
@RequiredArgsConstructor
protected enum CashTableHeader implements TableHeaderColumn {
CURRENCY("Валюта"),
VALUE("Исходящий", "остаток", "на конец", "периода");

@Getter
private final TableColumn column;

CashTableHeader(String... words) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spacious_team.broker.pojo.CashFlowType;
import org.spacious_team.broker.pojo.SecurityEventCashFlow;
import org.spacious_team.table_wrapper.api.PatternTableColumn;
Expand All @@ -42,8 +43,8 @@ protected TinkoffDerivativeCashFlowTable(SingleBrokerReport report) {
}

@Override
protected SecurityEventCashFlow parseRow(TableRow row) {
String contract = row.getStringCellValueOrDefault(CONTRACT, null);
protected @Nullable SecurityEventCashFlow parseRow(TableRow row) {
@Nullable String contract = row.getStringCellValueOrDefault(CONTRACT, null);
if (!hasLength(contract) || contract.contains("Наименование")) {
return null;
}
Expand All @@ -61,6 +62,7 @@ protected SecurityEventCashFlow parseRow(TableRow row) {
.build();
}

@Getter
@RequiredArgsConstructor
protected enum DerivativeCashFlowTableHeader implements TableHeaderColumn {
DATE("Дата"),
Expand All @@ -69,7 +71,6 @@ protected enum DerivativeCashFlowTableHeader implements TableHeaderColumn {
OUTGOING_COUNT("Позиция", "на", "конец", "дня"),
VARIATION_MARGIN("Вар", "маржа", "на", "конец", "дня");

@Getter
private final TableColumn column;

DerivativeCashFlowTableHeader(String... words) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package ru.investbook.parser.tinkoff;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.spacious_team.broker.pojo.CashFlowType;
import org.spacious_team.broker.pojo.Security;
import org.spacious_team.broker.pojo.SecurityEventCashFlow;
Expand All @@ -38,7 +39,7 @@
public class TinkoffSecurityEventCashFlowTable extends SingleAbstractReportTable<SecurityEventCashFlow> {

private final SecurityCodeAndIsinTable codeAndIsin;
private String currency = null;
private String currency = "";

protected TinkoffSecurityEventCashFlowTable(SingleBrokerReport report, SecurityCodeAndIsinTable codeAndIsin) {
super(report,
Expand All @@ -51,9 +52,9 @@ protected TinkoffSecurityEventCashFlowTable(SingleBrokerReport report, SecurityC
}

@Override
protected SecurityEventCashFlow parseRow(TableRow row) {
protected @Nullable SecurityEventCashFlow parseRow(TableRow row) {
currency = TinkoffCashFlowTableHelper.getCurrency(row, currency);
if (currency == null) {
if (!hasLength(currency)) {
return null;
}
String operation = row.getStringCellValueOrDefault(OPERATION, "").toLowerCase();
Expand Down Expand Up @@ -135,7 +136,7 @@ private int getCount(TableRow row) {
Assert.isTrue(slashPos != -1 && description.endsWith(" шт."),
"Ожидается количество бумаг в формате '<...>/ 10 шт.'");
String text = description.substring(slashPos + 1).trim();
return Integer.parseInt(text.split("\s+")[0]);
return Integer.parseInt(text.split("\\s+")[0]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spacious_team.broker.pojo.Security;
import org.spacious_team.broker.pojo.SecurityQuote;
import org.spacious_team.broker.pojo.SecurityType;
Expand All @@ -29,7 +30,6 @@
import org.spacious_team.table_wrapper.api.TableColumn;
import org.spacious_team.table_wrapper.api.TableHeaderColumn;
import org.spacious_team.table_wrapper.api.TableRow;
import org.springframework.util.StringUtils;
import ru.investbook.parser.SingleAbstractReportTable;
import ru.investbook.parser.SingleBrokerReport;
import ru.investbook.report.ForeignExchangeRateService;
Expand All @@ -39,6 +39,8 @@
import java.util.Optional;

import static java.math.RoundingMode.HALF_UP;
import static java.util.Objects.requireNonNull;
import static org.springframework.util.StringUtils.hasLength;
import static ru.investbook.parser.tinkoff.TinkoffSecurityQuoteTable.SecurityQuoteTableHeader.*;
import static ru.investbook.parser.tinkoff.TinkoffSecurityTransactionTableHelper.declareSecurity;

Expand Down Expand Up @@ -76,10 +78,10 @@ public TinkoffSecurityQuoteTable(String tableNamePrefix,
}

@Override
protected SecurityQuote parseRow(TableRow row) {
protected @Nullable SecurityQuote parseRow(TableRow row) {
adjustSecuritiesValueEstimate(row);

BigDecimal price = row.getBigDecimalCellValueOrDefault(PRICE, null);
@Nullable BigDecimal price = row.getBigDecimalCellValueOrDefault(PRICE, null);
if (price == null) {
return null;
}
Expand Down Expand Up @@ -116,7 +118,7 @@ protected SecurityQuote parseRow(TableRow row) {

private void adjustSecuritiesValueEstimate(TableRow row) {
try {
BigDecimal value = row.getBigDecimalCellValueOrDefault(VALUE, null);
@Nullable BigDecimal value = row.getBigDecimalCellValueOrDefault(VALUE, null);
if (value != null) {
String currency = row.getStringCellValue(CURRENCY);
if (currency.equalsIgnoreCase("RUB")) {
Expand All @@ -138,12 +140,12 @@ private void adjustSecuritiesValueEstimate(TableRow row) {

private Optional<Security> getSecurityId(TableRow row) {
try {
String code = row.getStringCellValueOrDefault(CODE, null);
if (StringUtils.hasLength(code)) {
@Nullable String code = row.getStringCellValueOrDefault(CODE, null);
if (hasLength(code)) {
BigDecimal accruedInterest = row.getBigDecimalCellValueOrDefault(ACCRUED_INTEREST, BigDecimal.ZERO);
boolean isBond = accruedInterest.floatValue() > 1e-3;
Security security = TinkoffSecurityTransactionTableHelper.getSecurity(
code,
requireNonNull(code),
codeAndIsin,
row.getStringCellValue(SHORT_NAME),
isBond ? SecurityType.BOND : SecurityType.STOCK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spacious_team.broker.pojo.SecurityType;
import org.spacious_team.broker.report_parser.api.AbstractTransaction;
import org.spacious_team.broker.report_parser.api.DerivativeTransaction;
Expand Down Expand Up @@ -77,7 +78,7 @@ private TinkoffSecurityTransactionTable(String tableNamePrefix,
}

@Override
protected AbstractTransaction parseRow(TableRow row) {
protected @Nullable AbstractTransaction parseRow(TableRow row) {
String tradeId = row.getStringCellValueOrDefault(TRADE_ID, "");
if (!hasLength(tradeId)) return null;
String operation = row.getStringCellValue(OPERATION).toLowerCase();
Expand All @@ -97,7 +98,7 @@ protected AbstractTransaction parseRow(TableRow row) {
amount = isBuy ? amount.negate() : amount;
count = isBuy ? count : -count;

Instant timestamp = null;
Instant timestamp;
SecurityType securityType = transactionTableHelper.getSecurityType(row);
AbstractTransaction.AbstractTransactionBuilder<?, ?> builder = switch (securityType) {
case STOCK -> SecurityTransaction.builder()
Expand Down
Loading

0 comments on commit d4cca1e

Please sign in to comment.