Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

12
LINES

< > BotCompany Repo | #1021956 // toIntOr

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5046L/28K).

1  
static int toIntOr(O o, int defaultValue) {
2  
  if (o == null) ret defaultValue;
3  
  if (o instanceof Number)
4  
    ret ((Number) o).intValue();
5  
  if (o cast S)
6  
    ret isInteger(o) ? parseInt(o) : defaultValue;
7  
  ret defaultValue;
8  
}
9  
10  
static int toIntOr(Int i, int defaultValue) {
11  
  ret i != null ? i.intValue() : defaultValue;
12  
}

Author comment

Began life as a copy of #1020918

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1021956
Snippet name: toIntOr
Eternal ID of this version: #1021956/3
Text MD5: 6a6754bc165b87d6786a4c8d8ec62878
Transpilation MD5: 9f8a0a523331dc1f9cd00d68f5b1d599
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-01 15:42:18
Source code size: 334 bytes / 12 lines
Pitched / IR pitched: No / No
Views / Downloads: 343 / 400
Version history: 2 change(s)
Referenced in: [show references]