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

52
LINES

< > BotCompany Repo | #1031350 // unnullForIteration

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

Transpiled version (84L) is out of date.

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

Author comment

Began life as a copy of #1001913

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031350
Snippet name: unnullForIteration
Eternal ID of this version: #1031350/6
Text MD5: 4da73adda1ea9e1ef5bfab7854aef1b7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-07-03 02:55:37
Source code size: 1564 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 179 / 330
Version history: 5 change(s)
Referenced in: [show references]