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.

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

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

static <A> L<A> unnull(L<A> l) { ret l == null ? emptyList() : l; }
static int[] unnull(int[] l) { ret l == null ? emptyIntArray() : l; }
static char[] unnull(char[] l) { ret l == null ? emptyCharArray() : l; }
static double[] unnull(double[] l) { ret l == null ? emptyDoubleArray() : l; }
static float[] unnull(float[] l) { ret l == null ? emptyFloatArray() : l; }

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

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

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

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

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

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

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

static int unnull(Int i) { ret i == null ? 0 : i; }
static long unnull(Long l) { ret l == null ? 0L : l; }
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: 966 / 7601
Version history: 21 change(s)
Referenced in: [show references]