Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit873f582

Browse files
committed
[2.0.0-SNAPSHOT]
Builders NPE fixesHashcode & Equals improved
1 parentaa25129 commit873f582

File tree

15 files changed

+108
-170
lines changed

15 files changed

+108
-170
lines changed

‎src/main/java/io/goodforgod/api/etherscan/model/Abi.java‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
packageio.goodforgod.api.etherscan.model;
22

33
importio.goodforgod.api.etherscan.util.BasicUtils;
4+
importjava.util.Objects;
45

56
/**
67
* @author GoodforGod
@@ -40,27 +41,15 @@ public boolean isVerified() {
4041
publicbooleanequals(Objecto) {
4142
if (this ==o)
4243
returntrue;
43-
if (o ==null ||getClass() !=o.getClass())
44+
if (!(oinstanceofAbi))
4445
returnfalse;
45-
4646
Abiabi = (Abi)o;
47-
48-
if (isVerified !=abi.isVerified)
49-
returnfalse;
50-
returncontractAbi !=null
51-
?contractAbi.equals(abi.contractAbi)
52-
:abi.contractAbi ==null;
47+
returnisVerified ==abi.isVerified &&Objects.equals(contractAbi,abi.contractAbi);
5348
}
5449

5550
@Override
5651
publicinthashCode() {
57-
intresult =contractAbi !=null
58-
?contractAbi.hashCode()
59-
:0;
60-
result =31 *result + (isVerified
61-
?1
62-
:0);
63-
returnresult;
52+
returnObjects.hash(contractAbi,isVerified);
6453
}
6554

6655
@Override

‎src/main/java/io/goodforgod/api/etherscan/model/Balance.java‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,15 @@ public BigInteger getEther() {
4848
publicbooleanequals(Objecto) {
4949
if (this ==o)
5050
returntrue;
51-
if (o ==null ||getClass() !=o.getClass())
51+
if (!(oinstanceofBalance))
5252
returnfalse;
53-
5453
Balancebalance1 = (Balance)o;
55-
56-
if (!balance.equals(balance1.balance))
57-
returnfalse;
58-
returnObjects.equals(address,balance1.address);
54+
returnObjects.equals(balance,balance1.balance) &&Objects.equals(address,balance1.address);
5955
}
6056

6157
@Override
6258
publicinthashCode() {
63-
intresult =balance.hashCode();
64-
result =31 *result + (address !=null
65-
?address.hashCode()
66-
:0);
67-
returnresult;
59+
returnObjects.hash(balance,address);
6860
}
6961

7062
@Override

‎src/main/java/io/goodforgod/api/etherscan/model/Block.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
importjava.math.BigInteger;
66
importjava.time.LocalDateTime;
77
importjava.time.ZoneOffset;
8+
importjava.util.Objects;
89

910
/**
1011
* @author GoodforGod
@@ -40,17 +41,15 @@ public BigInteger getBlockReward() {
4041
publicbooleanequals(Objecto) {
4142
if (this ==o)
4243
returntrue;
43-
if (o ==null ||getClass() !=o.getClass())
44+
if (!(oinstanceofBlock))
4445
returnfalse;
45-
4646
Blockblock = (Block)o;
47-
4847
returnblockNumber ==block.blockNumber;
4948
}
5049

5150
@Override
5251
publicinthashCode() {
53-
return(int) (blockNumber ^ (blockNumber >>>32));
52+
returnObjects.hash(blockNumber);
5453
}
5554

5655
@Override
@@ -98,8 +97,10 @@ public Block build() {
9897
Blockblock =newBlock();
9998
block.blockNumber =this.blockNumber;
10099
block.blockReward =this.blockReward;
101-
block._timeStamp =this.timeStamp;
102-
block.timeStamp =String.valueOf(this.timeStamp.toEpochSecond(ZoneOffset.UTC));
100+
if (this.timeStamp !=null) {
101+
block._timeStamp =this.timeStamp;
102+
block.timeStamp =String.valueOf(this.timeStamp.toEpochSecond(ZoneOffset.UTC));
103+
}
103104
returnblock;
104105
}
105106
}

‎src/main/java/io/goodforgod/api/etherscan/model/BlockUncle.java‎

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
importjava.time.LocalDateTime;
66
importjava.time.ZoneOffset;
77
importjava.util.List;
8+
importjava.util.Objects;
89

910
/**
1011
* @author GoodforGod
@@ -38,31 +39,16 @@ public int getUnclePosition() {
3839
publicbooleanequals(Objecto) {
3940
if (this ==o)
4041
returntrue;
41-
if (o ==null ||getClass() !=o.getClass())
42+
if (!(oinstanceofUncle))
4243
returnfalse;
43-
4444
Uncleuncle = (Uncle)o;
45-
if (unclePosition !=uncle.unclePosition)
46-
returnfalse;
47-
if (miner !=null
48-
? !miner.equals(uncle.miner)
49-
:uncle.miner !=null)
50-
returnfalse;
51-
returnblockreward !=null
52-
?blockreward.equals(uncle.blockreward)
53-
:uncle.blockreward ==null;
45+
returnunclePosition ==uncle.unclePosition &&Objects.equals(miner,uncle.miner)
46+
&&Objects.equals(blockreward,uncle.blockreward);
5447
}
5548

5649
@Override
5750
publicinthashCode() {
58-
intresult =miner !=null
59-
?miner.hashCode()
60-
:0;
61-
result =31 *result + (blockreward !=null
62-
?blockreward.hashCode()
63-
:0);
64-
result =31 *result +unclePosition;
65-
returnresult;
51+
returnObjects.hash(miner,blockreward,unclePosition);
6652
}
6753

6854
@Override
@@ -139,27 +125,6 @@ public String getUncleInclusionReward() {
139125
}
140126
// </editor-fold>
141127

142-
@Override
143-
publicbooleanequals(Objecto) {
144-
if (this ==o)
145-
returntrue;
146-
if (o ==null ||getClass() !=o.getClass())
147-
returnfalse;
148-
if (!super.equals(o))
149-
returnfalse;
150-
151-
BlockUnclethat = (BlockUncle)o;
152-
153-
returngetBlockNumber() !=0 &&getBlockNumber() ==that.getBlockNumber();
154-
}
155-
156-
@Override
157-
publicinthashCode() {
158-
intresult =super.hashCode();
159-
result = (int) (31 *result +getBlockNumber());
160-
returnresult;
161-
}
162-
163128
@Override
164129
publicStringtoString() {
165130
return"UncleBlock{" +
@@ -223,8 +188,10 @@ public BlockUncle build() {
223188
blockUncle.blockNumber =this.blockNumber;
224189
blockUncle.blockReward =this.blockReward;
225190
blockUncle.blockMiner =this.blockMiner;
226-
blockUncle._timeStamp =this.timeStamp;
227-
blockUncle.timeStamp =String.valueOf(this.timeStamp.toEpochSecond(ZoneOffset.UTC));
191+
if (this.timeStamp !=null) {
192+
blockUncle._timeStamp =this.timeStamp;
193+
blockUncle.timeStamp =String.valueOf(this.timeStamp.toEpochSecond(ZoneOffset.UTC));
194+
}
228195
returnblockUncle;
229196
}
230197
}

‎src/main/java/io/goodforgod/api/etherscan/model/Log.java‎

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -125,40 +125,17 @@ public Long getLogIndex() {
125125
publicbooleanequals(Objecto) {
126126
if (this ==o)
127127
returntrue;
128-
if (o ==null ||getClass() !=o.getClass())
128+
if (!(oinstanceofLog))
129129
returnfalse;
130-
131130
Loglog = (Log)o;
132-
133-
if (!Objects.equals(blockNumber,log.blockNumber))
134-
returnfalse;
135-
if (!Objects.equals(address,log.address))
136-
returnfalse;
137-
if (!Objects.equals(transactionHash,log.transactionHash))
138-
returnfalse;
139-
if (!Objects.equals(timeStamp,log.timeStamp))
140-
returnfalse;
141-
returnObjects.equals(logIndex,log.logIndex);
131+
returnObjects.equals(blockNumber,log.blockNumber) &&Objects.equals(address,log.address)
132+
&&Objects.equals(transactionHash,log.transactionHash) &&Objects.equals(transactionIndex,log.transactionIndex)
133+
&&Objects.equals(logIndex,log.logIndex);
142134
}
143135

144136
@Override
145137
publicinthashCode() {
146-
intresult =blockNumber !=null
147-
?blockNumber.hashCode()
148-
:0;
149-
result =31 *result + (address !=null
150-
?address.hashCode()
151-
:0);
152-
result =31 *result + (transactionHash !=null
153-
?transactionHash.hashCode()
154-
:0);
155-
result =31 *result + (timeStamp !=null
156-
?timeStamp.hashCode()
157-
:0);
158-
result =31 *result + (logIndex !=null
159-
?logIndex.hashCode()
160-
:0);
161-
returnresult;
138+
returnObjects.hash(blockNumber,address,transactionHash,transactionIndex,logIndex);
162139
}
163140

164141
@Override
@@ -255,17 +232,23 @@ public LogBuilder withLogIndex(Long logIndex) {
255232
publicLogbuild() {
256233
Loglog =newLog();
257234
log.address =this.address;
258-
log.gasPrice =String.valueOf(this.gasPrice);
259-
log._gasPrice =this.gasPrice;
235+
if (this.gasPrice !=null) {
236+
log.gasPrice =String.valueOf(this.gasPrice);
237+
log._gasPrice =this.gasPrice;
238+
}
260239
log._logIndex =this.logIndex;
261240
log._transactionIndex =this.transactionIndex;
262-
log._gasUsed =this.gasUsed;
263241
log.blockNumber =String.valueOf(this.blockNumber);
264242
log.transactionIndex =String.valueOf(this.transactionIndex);
265-
log.timeStamp =String.valueOf(this.timeStamp);
243+
if (this.timeStamp !=null) {
244+
log.timeStamp =String.valueOf(this.timeStamp.toEpochSecond(ZoneOffset.UTC));
245+
log._timeStamp =this.timeStamp;
246+
}
266247
log.data =this.data;
267-
log.gasUsed =String.valueOf(this.gasUsed);
268-
log._timeStamp =this.timeStamp;
248+
if (this.gasUsed !=null) {
249+
log.gasUsed =String.valueOf(this.gasUsed);
250+
log._gasUsed =this.gasUsed;
251+
}
269252
log.logIndex =String.valueOf(this.logIndex);
270253
log._blockNumber =this.blockNumber;
271254
log.topics =this.topics;

‎src/main/java/io/goodforgod/api/etherscan/model/Price.java‎

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
importcom.google.gson.annotations.Expose;
44
importjava.time.LocalDateTime;
55
importjava.time.ZoneOffset;
6+
importjava.util.Objects;
67

78
/**
89
* @author GoodforGod
@@ -30,54 +31,34 @@ public double inBtc() {
3031
}
3132

3233
publicLocalDateTimeusdTimestamp() {
33-
if (_ethusd_timestamp ==null)
34+
if (_ethusd_timestamp ==null &&ethusd_timestamp !=null) {
3435
_ethusd_timestamp =LocalDateTime.ofEpochSecond(Long.parseLong(ethusd_timestamp),0,ZoneOffset.UTC);
36+
}
3537
return_ethusd_timestamp;
3638
}
3739

3840
publicLocalDateTimebtcTimestamp() {
39-
if (_ethbtc_timestamp ==null)
41+
if (_ethbtc_timestamp ==null &&ethbtc_timestamp !=null) {
4042
_ethbtc_timestamp =LocalDateTime.ofEpochSecond(Long.parseLong(ethbtc_timestamp),0,ZoneOffset.UTC);
43+
}
4144
return_ethbtc_timestamp;
4245
}
4346

4447
@Override
4548
publicbooleanequals(Objecto) {
4649
if (this ==o)
4750
returntrue;
48-
if (o ==null ||getClass() !=o.getClass())
51+
if (!(oinstanceofPrice))
4952
returnfalse;
50-
5153
Priceprice = (Price)o;
52-
53-
if (Double.compare(price.ethusd,ethusd) !=0)
54-
returnfalse;
55-
if (Double.compare(price.ethbtc,ethbtc) !=0)
56-
returnfalse;
57-
if (ethusd_timestamp !=null
58-
? !ethusd_timestamp.equals(price.ethusd_timestamp)
59-
:price.ethusd_timestamp !=null)
60-
returnfalse;
61-
return (ethbtc_timestamp !=null
62-
? !ethbtc_timestamp.equals(price.ethbtc_timestamp)
63-
:price.ethbtc_timestamp !=null);
54+
returnDouble.compare(price.ethusd,ethusd) ==0 &&Double.compare(price.ethbtc,ethbtc) ==0
55+
&&Objects.equals(ethusd_timestamp,price.ethusd_timestamp)
56+
&&Objects.equals(ethbtc_timestamp,price.ethbtc_timestamp);
6457
}
6558

6659
@Override
6760
publicinthashCode() {
68-
intresult;
69-
longtemp;
70-
temp =Double.doubleToLongBits(ethusd);
71-
result = (int) (temp ^ (temp >>>32));
72-
temp =Double.doubleToLongBits(ethbtc);
73-
result =31 *result + (int) (temp ^ (temp >>>32));
74-
result =31 *result + (ethusd_timestamp !=null
75-
?ethusd_timestamp.hashCode()
76-
:0);
77-
result =31 *result + (ethbtc_timestamp !=null
78-
?ethbtc_timestamp.hashCode()
79-
:0);
80-
returnresult;
61+
returnObjects.hash(ethusd,ethbtc,ethusd_timestamp,ethbtc_timestamp);
8162
}
8263

8364
@Override
@@ -126,11 +107,15 @@ public PriceBuilder withEthBtcTimestamp(LocalDateTime ethbtcTimestamp) {
126107
publicPricebuild() {
127108
Priceprice =newPrice();
128109
price.ethbtc =this.ethbtc;
129-
price.ethbtc_timestamp =String.valueOf(this.ethbtcTimestamp.toEpochSecond(ZoneOffset.UTC));
130-
price._ethbtc_timestamp =this.ethbtcTimestamp;
131110
price.ethusd =this.ethusd;
132-
price.ethusd_timestamp =String.valueOf(this.ethusdTimestamp.toEpochSecond(ZoneOffset.UTC));
133-
price._ethusd_timestamp =this.ethusdTimestamp;
111+
if (this.ethbtcTimestamp !=null) {
112+
price.ethbtc_timestamp =String.valueOf(this.ethbtcTimestamp.toEpochSecond(ZoneOffset.UTC));
113+
price._ethbtc_timestamp =this.ethbtcTimestamp;
114+
}
115+
if (this.ethusdTimestamp !=null) {
116+
price.ethusd_timestamp =String.valueOf(this.ethusdTimestamp.toEpochSecond(ZoneOffset.UTC));
117+
price._ethusd_timestamp =this.ethusdTimestamp;
118+
}
134119
returnprice;
135120
}
136121
}

‎src/main/java/io/goodforgod/api/etherscan/model/Tx.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,12 @@ public Tx build() {
228228
tx.value =this.value;
229229
tx.transactionIndex =this.transactionIndex;
230230
tx.confirmations =this.confirmations;
231-
tx.timeStamp =String.valueOf(this.timeStamp.toEpochSecond(ZoneOffset.UTC));
231+
if (this.timeStamp !=null) {
232+
tx.timeStamp =String.valueOf(this.timeStamp.toEpochSecond(ZoneOffset.UTC));
233+
tx._timeStamp =this.timeStamp;
234+
}
232235
tx.nonce =this.nonce;
233236
tx.blockNumber =this.blockNumber;
234-
tx._timeStamp =this.timeStamp;
235237
tx.to =this.to;
236238
tx.input =this.input;
237239
tx.cumulativeGasUsed =this.cumulativeGasUsed;

‎src/main/java/io/goodforgod/api/etherscan/model/TxErc1155.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ public TxErc1155 build() {
235235
txERC721.contractAddress =this.contractAddress;
236236
txERC721.cumulativeGasUsed =this.cumulativeGasUsed;
237237
txERC721.tokenID =this.tokenID;
238-
txERC721.timeStamp =String.valueOf(this.timeStamp.toEpochSecond(ZoneOffset.UTC));
238+
if (this.timeStamp !=null) {
239+
txERC721.timeStamp =String.valueOf(this.timeStamp.toEpochSecond(ZoneOffset.UTC));
240+
txERC721._timeStamp =this.timeStamp;
241+
}
239242
txERC721.blockNumber =this.blockNumber;
240-
txERC721._timeStamp =this.timeStamp;
241243
txERC721.tokenValue =this.tokenValue;
242244
txERC721.transactionIndex =this.transactionIndex;
243245
txERC721.to =this.to;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp