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.

static String unnullForIteration(String s) {
  return s == null ? "" : s;
}

static <A> Collection<A> unnullForIteration(Collection<A> l) {
  ret l == null ? immutableEmptyList() : l;
}

static <A> L<A> unnullForIteration(L<A> l) { ret l == null ? immutableEmptyList() : l; }
static byte[] unnullForIteration(byte[] l) { ret l == null ? emptyByteArray() : l; }
static int[] unnullForIteration(int[] l) { ret l == null ? emptyIntArray() : l; }
static char[] unnullForIteration(char[] l) { ret l == null ? emptyCharArray() : l; }
static double[] unnullForIteration(double[] l) { ret l == null ? emptyDoubleArray() : l; }
static short[] unnullForIteration(short[] l) { ret l == null ? emptyShortArray() : l; }

static <A, B> Map<A, B> unnullForIteration(Map<A, B> l) {
  ret l == null ? immutableEmptyMap() : l;
}

static <A> Iterable<A> unnullForIteration(Iterable<A> i) {
  ret i == null ? immutableEmptyList() : i;
}

static <A> A[] unnullForIteration(A[] a) {
  ret a == null ? (A[]) emptyObjectArray() : a;
}

static BitSet unnullForIteration(BitSet b) {
  ret b == null ? new BitSet() : b;
}

ifclass Pt
static Pt unnullForIteration(Pt p) {
  ret p == null ? new Pt : p;
}
endif

//ifclass Symbol
ifndef SymbolAsString
static Symbol unnullForIteration(Symbol s) {
  ret s == null ? emptySymbol() : s;
}
//endif
endifndef

ifclass Pair
static <A, B> Pair<A, B> unnullForIteration(Pair<A, B> p) {
  ret p != null ? p : Pair(null, null);
}
endif

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: 178 / 328
Version history: 5 change(s)
Referenced in: [show references]