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

61
LINES

< > BotCompany Repo | #1012632 // n2 - n2(3, "item") => "3 items"

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

Transpiled version (5335L) is out of date.

static S n2(long l) { ret formatWithThousands(l); }
static S n2(AtomicLong l) { ret n2(l!); }
static S n2(Collection l) { ret n2(l(l)); }
static S n2(Map map) { ret n2(l(map)); }

sS n2_getPlural(S singular) {
  //ret singular + "s";
  ret plural(singular);
}

sS n2(double l, S singular) {
  ret empty(singular) ? str(l) : n2(l, singular, n2_getPlural(singular));
}

sS n2(double l, S singular, S plural) {
  if (fraction(l) == 0)
    ret n2((long) l, singular, plural);
  else
    ret l + " " + plural;
}

static S n2(long l, S singular, S plural) {
  ret n_fancy2(l, singular, plural);
}

static S n2(long l, S singular) {
  ret empty(singular) ? n2(l) : n_fancy2(l, singular, n2_getPlural(singular));
}

static S n2(Collection l, S singular) {
  ret n2(l(l), singular);
}

static S n2(Collection l, S singular, S plural) {
  ret n_fancy2(l, singular, plural);
}

static S n2(Map m, S singular, S plural) {
  ret n_fancy2(m, singular, plural);
}

static S n2(Map m, S singular) {
  ret n2(l(m), singular);
}

static S n2(long[] a, S singular) { ret n2(l(a), singular); }

static S n2(O[] a, S singular) { ret n2(l(a), singular); }
static S n2(O[] a, S singular, S plural) { ret n_fancy2(a, singular, plural); }

ifclass MultiSet
  static S n2(MultiSet ms, S singular, S plural default n2_getPlural(singular)) {
    ret n_fancy2(ms, singular, plural);
  }
endif

ifclass IMultiMap
  static S n2(IMultiMap mm, S singular, S plural default n2_getPlural(singular)) {
    ret n_fancy2(l(mm), singular, plural);
  }
endif

Author comment

Began life as a copy of #1012450

download  show line numbers  debug dex  old transpilations   

Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wnsclhtenguj, xrpafgyirdlv

No comments. add comment

Snippet ID: #1012632
Snippet name: n2 - n2(3, "item") => "3 items"
Eternal ID of this version: #1012632/24
Text MD5: 21a1e958d9ce11a29a04dc306488d0f0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-07 12:39:49
Source code size: 1578 bytes / 61 lines
Pitched / IR pitched: No / No
Views / Downloads: 679 / 899
Version history: 23 change(s)
Referenced in: [show references]