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

52
LINES

< > BotCompany Repo | #1001913 - unnull

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

Libraryless. Click here for Pure Java version (3061L/17K).

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 <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/21
Text MD5: 888f1d3adec39108bf7c1e4f26aeb092
Transpilation MD5: 89fe39861ece26d4d57fc920e370eaf4
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-22 20:53:01
Source code size: 1299 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 616 / 7140
Version history: 20 change(s)
Referenced in: [show references]