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

47
LINES

< > BotCompany Repo | #1001913 - unnull

JavaX fragment (include)

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 <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[]) new O[0] : 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

Author comment

Began life as a copy of #2000506

download  show line numbers  debug dex   

Travelled to 16 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jcllbfdqhrgy, lpdgvwnxivlt, mqqgnosmbjvj, omdjrrnzbjjv, onxytkatvevr, podlckwnjdmb, tslmcundralx, tvejysmllsmz, whxojlpjdney

No comments. add comment

Snippet ID: #1001913
Snippet name: unnull
Eternal ID of this version: #1001913/12
Text MD5: b62a6c0643e13d7e3b2067347bf6adb2
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-24 21:08:35
Source code size: 896 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 399 / 6714
Version history: 11 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1001913 & http://1001913.tinybrain.de