38
38
import java .util .Arrays ;
39
39
import java .util .List ;
40
40
import java .util .Map ;
41
+ import java .util .Objects ;
42
+ import java .util .Optional ;
41
43
import java .util .concurrent .TimeUnit ;
42
44
import java .util .stream .Stream ;
43
45
import org .hiero .base .utility .CommonUtils ;
@@ -93,7 +95,7 @@ default HapiSpec.UTF8Mode getUTF8Mode(String property) {
93
95
94
96
default FileID getFile (String property ) {
95
97
try {
96
- return asFile (get ( "default.shard" ), get ( "default.realm" ), get (property ));
98
+ return asFile (getShard ( ), getRealm ( ), Long . parseLong ( get (property ) ));
97
99
} catch (Exception ignore ) {
98
100
}
99
101
return FileID .getDefaultInstance ();
@@ -111,7 +113,7 @@ default AccountID getAccount(String property) {
111
113
}
112
114
113
115
try {
114
- return asAccount (get ( "default.shard" ), get ( "default.realm" ), get ( property ));
116
+ return asAccount (getShard ( ), getRealm ( ), Long . parseLong ( value ));
115
117
} catch (Exception ignore ) {
116
118
}
117
119
@@ -145,14 +147,28 @@ default ContractID getContract(String property) {
145
147
return ContractID .getDefaultInstance ();
146
148
}
147
149
150
+ @ Deprecated
148
151
default RealmID getRealm (String property ) {
149
152
return RealmID .newBuilder ().setRealmNum (Long .parseLong (get (property ))).build ();
150
153
}
151
154
155
+ default long getRealm () {
156
+ return Optional .ofNullable (get ("hapi.spec.default.realm" ))
157
+ .map (Long ::parseLong )
158
+ .orElse (realm );
159
+ }
160
+
161
+ @ Deprecated
152
162
default ShardID getShard (String property ) {
153
163
return ShardID .newBuilder ().setShardNum (Long .parseLong (get (property ))).build ();
154
164
}
155
165
166
+ default long getShard () {
167
+ return Optional .ofNullable (get ("hapi.spec.default.shard" ))
168
+ .map (Long ::parseLong )
169
+ .orElse ((long ) shard );
170
+ }
171
+
156
172
default TimeUnit getTimeUnit (String property ) {
157
173
return TimeUnit .valueOf (get (property ));
158
174
}
@@ -221,6 +237,7 @@ default HapiSpec.SpecStatus getSpecStatus(String property) {
221
237
222
238
static HapiPropertySource [] asSources (Object ... sources ) {
223
239
return Stream .of (sources )
240
+ .filter (Objects ::nonNull )
224
241
.map (s -> (s instanceof HapiPropertySource )
225
242
? s
226
243
: ((s instanceof Map ) ? new MapPropertySource ((Map ) s ) : new JutilPropertySource ((String ) s )))
@@ -250,10 +267,14 @@ static AccountID asAccount(String v) {
250
267
}
251
268
252
269
static AccountID asAccount (String shard , String realm , String num ) {
270
+ return asAccount (Long .parseLong (shard ), Long .parseLong (realm ), Long .parseLong (num ));
271
+ }
272
+
273
+ static AccountID asAccount (long shard , long realm , long num ) {
253
274
return AccountID .newBuilder ()
254
- .setShardNum (Long . parseLong ( shard ) )
255
- .setRealmNum (Long . parseLong ( realm ) )
256
- .setAccountNum (Long . parseLong ( num ) )
275
+ .setShardNum (shard )
276
+ .setRealmNum (realm )
277
+ .setAccountNum (num )
257
278
.build ();
258
279
}
259
280
@@ -266,10 +287,14 @@ static ContractID asContract(String shard, String realm, String num) {
266
287
}
267
288
268
289
static FileID asFile (String shard , String realm , String num ) {
290
+ return asFile (Long .parseLong (shard ), Long .parseLong (realm ), Long .parseLong (num ));
291
+ }
292
+
293
+ static FileID asFile (long shard , long realm , long num ) {
269
294
return FileID .newBuilder ()
270
- .setShardNum (Long . parseLong ( shard ) )
271
- .setRealmNum (Long . parseLong ( realm ) )
272
- .setFileNum (Long . parseLong ( num ) )
295
+ .setShardNum (shard )
296
+ .setRealmNum (realm )
297
+ .setFileNum (num )
273
298
.build ();
274
299
}
275
300
@@ -454,6 +479,14 @@ static long[] asDotDelimitedLongArray(String s) {
454
479
return Stream .of (parts ).mapToLong (Long ::valueOf ).toArray ();
455
480
}
456
481
482
+ static ShardID asShard (long v ) {
483
+ return ShardID .newBuilder ().setShardNum (v ).build ();
484
+ }
485
+
486
+ static RealmID asRealm (long v ) {
487
+ return RealmID .newBuilder ().setRealmNum (v ).build ();
488
+ }
489
+
457
490
static byte [] asSolidityAddress (final AccountID accountId ) {
458
491
return asSolidityAddress ((int ) accountId .getShardNum (), accountId .getRealmNum (), accountId .getAccountNum ());
459
492
}
@@ -529,6 +562,14 @@ static String literalIdFromHexedMirrorAddress(final String hexedEvm) {
529
562
.build ());
530
563
}
531
564
565
+ static String asEntityString (final long shard , final long realm , final long num ) {
566
+ return String .format (ENTITY_STRING , shard , realm , num );
567
+ }
568
+
569
+ static String asEntityString (final long shard , final long realm , final String num ) {
570
+ return String .format ("%d.%d.%s" , shard , realm , num );
571
+ }
572
+
532
573
static String asEntityString (final long num ) {
533
574
return String .format (ENTITY_STRING , shard , realm , num );
534
575
}
0 commit comments