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

45
LINES

< > BotCompany Repo | #1023406 // InputProcessor1 - calls a number of property makers on a string input. properties can have any type

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

Libraryless. Click here for Pure Java version (2465L/16K).

sclass InputProcessor1 {
  Map<S, virtual F1<S, O>> propertyMakers = ciMap();
  
  sclass Out > PropertiesAndErrors {
    InputProcessor1 inputProcessor;
    S input;
    
    bool hasProperty(S name) {
      ret properties.containsKey(name) || containsKey(propertyErrors, name);
    }
    
    void triggerProperty(S name) {
      if (inputProcessor == null || hasProperty(name)) ret;
      O f = inputProcessor.propertyMakers.get(name);
      if (f == null) ret;
      propertiesAndErrors_callF(this, name, f, input);
    }
    
    O getProperty(S name) {
      if (properties.containsKey(name)) ret properties.get(name);
      if (containsKey(propertyErrors, name)) throw throwPersistableThrowable(mapGet(propertyErrors, name));
      triggerProperty(name);
      if (containsKey(propertyErrors, name)) throw throwPersistableThrowable(mapGet(propertyErrors, name));
      ret properties.get(name);
    }
    
    Out detach() { inputProcessor = null; this; }
  }

  Out process(S input) {
    Out out = dontProcess(input);
    for (S name : keys(propertyMakers))
      out.triggerProperty(name);
    ret out;
  }
  
  // you can query properties on demand
  Out dontProcess(S input) {
    ret nu Out(inputProcessor := this, +input);
  }
  
  void addStandardFunctions(S... names) {
    putAllAsKeyAndValue(propertyMakers, names);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023406
Snippet name: InputProcessor1 - calls a number of property makers on a string input. properties can have any type
Eternal ID of this version: #1023406/23
Text MD5: aa9e1d54998b2d5e72276b13b6c8d996
Transpilation MD5: 190777caa2bbc0886a127e75afbfae62
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-06-18 02:00:19
Source code size: 1383 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 270 / 840
Version history: 22 change(s)
Referenced in: [show references]