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).

1  
sclass InputProcessor1 {
2  
  Map<S, virtual F1<S, O>> propertyMakers = ciMap();
3  
  
4  
  sclass Out > PropertiesAndErrors {
5  
    InputProcessor1 inputProcessor;
6  
    S input;
7  
    
8  
    bool hasProperty(S name) {
9  
      ret properties.containsKey(name) || containsKey(propertyErrors, name);
10  
    }
11  
    
12  
    void triggerProperty(S name) {
13  
      if (inputProcessor == null || hasProperty(name)) ret;
14  
      O f = inputProcessor.propertyMakers.get(name);
15  
      if (f == null) ret;
16  
      propertiesAndErrors_callF(this, name, f, input);
17  
    }
18  
    
19  
    O getProperty(S name) {
20  
      if (properties.containsKey(name)) ret properties.get(name);
21  
      if (containsKey(propertyErrors, name)) throw throwPersistableThrowable(mapGet(propertyErrors, name));
22  
      triggerProperty(name);
23  
      if (containsKey(propertyErrors, name)) throw throwPersistableThrowable(mapGet(propertyErrors, name));
24  
      ret properties.get(name);
25  
    }
26  
    
27  
    Out detach() { inputProcessor = null; this; }
28  
  }
29  
30  
  Out process(S input) {
31  
    Out out = dontProcess(input);
32  
    for (S name : keys(propertyMakers))
33  
      out.triggerProperty(name);
34  
    ret out;
35  
  }
36  
  
37  
  // you can query properties on demand
38  
  Out dontProcess(S input) {
39  
    ret nu Out(inputProcessor := this, +input);
40  
  }
41  
  
42  
  void addStandardFunctions(S... names) {
43  
    putAllAsKeyAndValue(propertyMakers, names);
44  
  }
45  
}

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: 271 / 842
Version history: 22 change(s)
Referenced in: [show references]