@Test void parseNullLine() { assertThrows(InvalidDatasetException.class, () -> { parser.parse(null, timestamp, systemShardNum); }); }
@Override public AccountBalance parse(String line, long consensusTimestamp, long systemShardNum) { try { if (line == null) { throw new InvalidDatasetException("Null line cannot be parsed"); } List<String> parts = SPLITTER.splitToList(line); boolean hasTokenBalance; if (parts.size() == 5) { hasTokenBalance = true; } else if (parts.size() == 4) { hasTokenBalance = false; } else { throw new InvalidDatasetException("Invalid account balance line: " + line); } long shardNum = Long.parseLong(parts.get(0)); int realmNum = Integer.parseInt(parts.get(1)); int accountNum = Integer.parseInt(parts.get(2)); long balance = Long.parseLong(parts.get(3)); if (shardNum < 0 || realmNum < 0 || accountNum < 0 || balance < 0) { throw new InvalidDatasetException("Invalid account balance line: " + line); } if (shardNum != systemShardNum) { throw new InvalidDatasetException(String.format("Invalid account balance line: %s. Expect " + "shard (%d), got shard (%d)", line, systemShardNum, shardNum)); } EntityId accountId = EntityId .of(shardNum, realmNum, accountNum, EntityTypeEnum.ACCOUNT); List<TokenBalance> tokenBalances = hasTokenBalance ? parseTokenBalanceList(parts.get(4), consensusTimestamp, accountId) : Collections .emptyList(); return new AccountBalance(balance, tokenBalances, new AccountBalance.Id(consensusTimestamp, accountId)); } catch (NumberFormatException | InvalidProtocolBufferException ex) { throw new InvalidDatasetException("Invalid account balance line: " + line, ex); } }
AccountBalanceLineParserV2 implements AccountBalanceLineParser { @Override public AccountBalance parse(String line, long consensusTimestamp, long systemShardNum) { try { if (line == null) { throw new InvalidDatasetException("Null line cannot be parsed"); } List<String> parts = SPLITTER.splitToList(line); boolean hasTokenBalance; if (parts.size() == 5) { hasTokenBalance = true; } else if (parts.size() == 4) { hasTokenBalance = false; } else { throw new InvalidDatasetException("Invalid account balance line: " + line); } long shardNum = Long.parseLong(parts.get(0)); int realmNum = Integer.parseInt(parts.get(1)); int accountNum = Integer.parseInt(parts.get(2)); long balance = Long.parseLong(parts.get(3)); if (shardNum < 0 || realmNum < 0 || accountNum < 0 || balance < 0) { throw new InvalidDatasetException("Invalid account balance line: " + line); } if (shardNum != systemShardNum) { throw new InvalidDatasetException(String.format("Invalid account balance line: %s. Expect " + "shard (%d), got shard (%d)", line, systemShardNum, shardNum)); } EntityId accountId = EntityId .of(shardNum, realmNum, accountNum, EntityTypeEnum.ACCOUNT); List<TokenBalance> tokenBalances = hasTokenBalance ? parseTokenBalanceList(parts.get(4), consensusTimestamp, accountId) : Collections .emptyList(); return new AccountBalance(balance, tokenBalances, new AccountBalance.Id(consensusTimestamp, accountId)); } catch (NumberFormatException | InvalidProtocolBufferException ex) { throw new InvalidDatasetException("Invalid account balance line: " + line, ex); } } }
AccountBalanceLineParserV2 implements AccountBalanceLineParser { @Override public AccountBalance parse(String line, long consensusTimestamp, long systemShardNum) { try { if (line == null) { throw new InvalidDatasetException("Null line cannot be parsed"); } List<String> parts = SPLITTER.splitToList(line); boolean hasTokenBalance; if (parts.size() == 5) { hasTokenBalance = true; } else if (parts.size() == 4) { hasTokenBalance = false; } else { throw new InvalidDatasetException("Invalid account balance line: " + line); } long shardNum = Long.parseLong(parts.get(0)); int realmNum = Integer.parseInt(parts.get(1)); int accountNum = Integer.parseInt(parts.get(2)); long balance = Long.parseLong(parts.get(3)); if (shardNum < 0 || realmNum < 0 || accountNum < 0 || balance < 0) { throw new InvalidDatasetException("Invalid account balance line: " + line); } if (shardNum != systemShardNum) { throw new InvalidDatasetException(String.format("Invalid account balance line: %s. Expect " + "shard (%d), got shard (%d)", line, systemShardNum, shardNum)); } EntityId accountId = EntityId .of(shardNum, realmNum, accountNum, EntityTypeEnum.ACCOUNT); List<TokenBalance> tokenBalances = hasTokenBalance ? parseTokenBalanceList(parts.get(4), consensusTimestamp, accountId) : Collections .emptyList(); return new AccountBalance(balance, tokenBalances, new AccountBalance.Id(consensusTimestamp, accountId)); } catch (NumberFormatException | InvalidProtocolBufferException ex) { throw new InvalidDatasetException("Invalid account balance line: " + line, ex); } }  }
AccountBalanceLineParserV2 implements AccountBalanceLineParser { @Override public AccountBalance parse(String line, long consensusTimestamp, long systemShardNum) { try { if (line == null) { throw new InvalidDatasetException("Null line cannot be parsed"); } List<String> parts = SPLITTER.splitToList(line); boolean hasTokenBalance; if (parts.size() == 5) { hasTokenBalance = true; } else if (parts.size() == 4) { hasTokenBalance = false; } else { throw new InvalidDatasetException("Invalid account balance line: " + line); } long shardNum = Long.parseLong(parts.get(0)); int realmNum = Integer.parseInt(parts.get(1)); int accountNum = Integer.parseInt(parts.get(2)); long balance = Long.parseLong(parts.get(3)); if (shardNum < 0 || realmNum < 0 || accountNum < 0 || balance < 0) { throw new InvalidDatasetException("Invalid account balance line: " + line); } if (shardNum != systemShardNum) { throw new InvalidDatasetException(String.format("Invalid account balance line: %s. Expect " + "shard (%d), got shard (%d)", line, systemShardNum, shardNum)); } EntityId accountId = EntityId .of(shardNum, realmNum, accountNum, EntityTypeEnum.ACCOUNT); List<TokenBalance> tokenBalances = hasTokenBalance ? parseTokenBalanceList(parts.get(4), consensusTimestamp, accountId) : Collections .emptyList(); return new AccountBalance(balance, tokenBalances, new AccountBalance.Id(consensusTimestamp, accountId)); } catch (NumberFormatException | InvalidProtocolBufferException ex) { throw new InvalidDatasetException("Invalid account balance line: " + line, ex); } }  @Override AccountBalance parse(String line, long consensusTimestamp, long systemShardNum); }
AccountBalanceLineParserV2 implements AccountBalanceLineParser { @Override public AccountBalance parse(String line, long consensusTimestamp, long systemShardNum) { try { if (line == null) { throw new InvalidDatasetException("Null line cannot be parsed"); } List<String> parts = SPLITTER.splitToList(line); boolean hasTokenBalance; if (parts.size() == 5) { hasTokenBalance = true; } else if (parts.size() == 4) { hasTokenBalance = false; } else { throw new InvalidDatasetException("Invalid account balance line: " + line); } long shardNum = Long.parseLong(parts.get(0)); int realmNum = Integer.parseInt(parts.get(1)); int accountNum = Integer.parseInt(parts.get(2)); long balance = Long.parseLong(parts.get(3)); if (shardNum < 0 || realmNum < 0 || accountNum < 0 || balance < 0) { throw new InvalidDatasetException("Invalid account balance line: " + line); } if (shardNum != systemShardNum) { throw new InvalidDatasetException(String.format("Invalid account balance line: %s. Expect " + "shard (%d), got shard (%d)", line, systemShardNum, shardNum)); } EntityId accountId = EntityId .of(shardNum, realmNum, accountNum, EntityTypeEnum.ACCOUNT); List<TokenBalance> tokenBalances = hasTokenBalance ? parseTokenBalanceList(parts.get(4), consensusTimestamp, accountId) : Collections .emptyList(); return new AccountBalance(balance, tokenBalances, new AccountBalance.Id(consensusTimestamp, accountId)); } catch (NumberFormatException | InvalidProtocolBufferException ex) { throw new InvalidDatasetException("Invalid account balance line: " + line, ex); } }  @Override AccountBalance parse(String line, long consensusTimestamp, long systemShardNum);  }