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

50
LINES

< > BotCompany Repo | #1001913 - unnull

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

Transpiled version (2481L) 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 <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 long unnull(Long l) { ret l == null ? 0L : l; }

Author comment

Began life as a copy of #2000506

download  show line numbers  debug dex   

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

No comments. add comment

Snippet ID: #1001913
Snippet name: unnull
Eternal ID of this version: #1001913/18
Text MD5: 93f6cc07e01156df88786016eff29409
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-10-29 10:32:16
Source code size: 1185 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 496 / 6935
Version history: 17 change(s)
Referenced in: [show references]

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