Libraryless. Click here for Pure Java version (3201L/20K).
| 1 | sclass PosNeg<A> {
 | 
| 2 | new MultiSet<A> pos; | 
| 3 | new MultiSet<A> neg; | 
| 4 | |
| 5 |   *() {}
 | 
| 6 |   *(Iterable<A> pos, Iterable<A> neg) {
 | 
| 7 | this.pos.addAll(pos); | 
| 8 | this.neg.addAll(neg); | 
| 9 | } | 
| 10 | |
| 11 |   *(Iterable<Pair<A, Bool>> pairs) {
 | 
| 12 | fOr (Pair<A, Bool> p : pairs) | 
| 13 | add(p.a, p.b); | 
| 14 | } | 
| 15 | |
| 16 |   *(Map<A, Bool> map) {
 | 
| 17 | fOr (A a, Bool b : map) | 
| 18 | add(a, b); | 
| 19 | } | 
| 20 | |
| 21 |   void add(A a, int score) {
 | 
| 22 | if (score > 0) | 
| 23 | pos.add(a, score); | 
| 24 | else if (score < 0) | 
| 25 | neg.add(a, -score); | 
| 26 | } | 
| 27 | |
| 28 |   void add(A a, Bool b) {
 | 
| 29 | if (isTrue(b)) | 
| 30 | pos.add(a); | 
| 31 | else if (isFalse(b)) | 
| 32 | neg.add(a); | 
| 33 | } | 
| 34 | |
| 35 |   int get(A a) {
 | 
| 36 | ret pos.get(a)-neg.get(a); | 
| 37 | } | 
| 38 | |
| 39 |   int score() { ret l(pos)-l(neg); }
 | 
| 40 |   int n() { ret l(pos)+l(neg); }
 | 
| 41 |   int nPos() { ret l(pos); }
 | 
| 42 |   int nNeg() { ret l(neg); }
 | 
| 43 |   bool isEmpty() { ret n() == 0; }
 | 
| 44 |   bool perfect() { ret nPos() != 0 && nNeg() == 0; }
 | 
| 45 |   bool antiPerfect() { ret nPos() == 0 && nNeg() != 0; }
 | 
| 46 | |
| 47 |   toString {
 | 
| 48 | ret "+" + nPos() + "/-" + nNeg() + ": " + pos + " / " + neg; | 
| 49 | } | 
| 50 | } | 
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1010411 | 
| Snippet name: | PosNeg - positive MultiSet + negative MultiSet | 
| Eternal ID of this version: | #1010411/15 | 
| Text MD5: | d4ea5ae779490183441d7d171fd848b0 | 
| Transpilation MD5: | 847b61b3f5036b7c666268795057f9f6 | 
| Author: | stefan | 
| Category: | javax | 
| Type: | JavaX fragment (include) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2020-07-06 00:32:30 | 
| Source code size: | 1057 bytes / 50 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 757 / 1509 | 
| Version history: | 14 change(s) | 
| Referenced in: | [show references] |