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

53
LINES

< > BotCompany Repo | #1001913 // unnull

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

Transpiled version (3061L) is out of date.

1  
static String unnull(String s) {
2  
  return s == null ? "" : s;
3  
}
4  
5  
static <A> Collection<A> unnull(Collection<A> l) {
6  
  ret l == null ? emptyList() : l;
7  
}
8  
9  
static <A> L<A> unnull(L<A> l) { ret l == null ? emptyList() : l; }
10  
static int[] unnull(int[] l) { ret l == null ? emptyIntArray() : l; }
11  
static char[] unnull(char[] l) { ret l == null ? emptyCharArray() : l; }
12  
static double[] unnull(double[] l) { ret l == null ? emptyDoubleArray() : l; }
13  
static float[] unnull(float[] l) { ret l == null ? emptyFloatArray() : l; }
14  
15  
static <A, B> Map<A, B> unnull(Map<A, B> l) {
16  
  ret l == null ? emptyMap() : l;
17  
}
18  
19  
static <A> Iterable<A> unnull(Iterable<A> i) {
20  
  ret i == null ? emptyList() : i;
21  
}
22  
23  
static <A> A[] unnull(A[] a) {
24  
  ret a == null ? (A[]) emptyObjectArray() : a;
25  
}
26  
27  
static BitSet unnull(BitSet b) {
28  
  ret b == null ? new BitSet() : b;
29  
}
30  
31  
ifclass Pt
32  
static Pt unnull(Pt p) {
33  
  ret p == null ? new Pt : p;
34  
}
35  
endif
36  
37  
//ifclass Symbol
38  
ifndef SymbolAsString
39  
static Symbol unnull(Symbol s) {
40  
  ret s == null ? emptySymbol() : s;
41  
}
42  
//endif
43  
endifndef
44  
45  
ifclass Pair
46  
static <A, B> Pair<A, B> unnull(Pair<A, B> p) {
47  
  ret p != null ? p : Pair(null, null);
48  
}
49  
endif
50  
51  
static int unnull(Int i) { ret i == null ? 0 : i; }
52  
static long unnull(Long l) { ret l == null ? 0L : l; }
53  
static double unnull(Double l) { ret l == null ? 0.0 : l; }

Author comment

Began life as a copy of #2000506

download  show line numbers  debug dex  old transpilations   

Travelled to 22 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jcllbfdqhrgy, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, omdjrrnzbjjv, onxytkatvevr, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv

No comments. add comment

Snippet ID: #1001913
Snippet name: unnull
Eternal ID of this version: #1001913/22
Text MD5: 1b79e07fb88f1202d0df8636a6707b80
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-10-01 09:47:58
Source code size: 1376 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 967 / 7604
Version history: 21 change(s)
Referenced in: [show references]