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

22
LINES

< > BotCompany Repo | #1034195 // CombinedStringifier

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

Libraryless. Click here for Pure Java version (5077L/28K).

sclass CombinedStringifier<A> is IStringifier<A> {
  new CopyOnWriteArrayList<IPartialStringifier<A>> stringifiers;
  IStringifier<A> defaultStringifier = new Stringifier_ToString;
  
  *(IPartialStringifier<A>... stringifiers) {
    addAll(this.stringifiers, stringifiers);
  }
  
  public S toString(A o) {
    for (stringifier : stringifiers) {
      S s = stringifier.toStringOpt(o);
      if (s != null) ret s;
    }
    ret defaultStringifier.toString(o);
  }
  
  toString {
    ret formatFunctionCall CombinedStringifier(
      listPlus((L) stringifiers, defaultStringifier)
    );
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034195
Snippet name: CombinedStringifier
Eternal ID of this version: #1034195/9
Text MD5: 4394631ea98fbf9f500678c4e79e703e
Transpilation MD5: a5b7305e248224bd9335398d00357daf
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-28 19:37:19
Source code size: 616 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 167 / 308
Version history: 8 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)