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

35
LINES

< > BotCompany Repo | #1029594 // cSmartSetField_withConverter

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

Libraryless. Click here for Pure Java version (15546L/101K).

1  
sbool cSmartSetField_withConverter(Concept c, S field, O value, bool verbose default false) {
2  
  ret cSmartSetField_withConverter(c, field, value, new DefaultValueConverterForField, verbose);
3  
}
4  
5  
// returns true if change
6  
sbool cSmartSetField_withConverter(Concept c, S field, O value, ValueConverterForField converter, bool verbose default false) ctex {
7  
  Field f = setOpt_findField(c.getClass(), field);
8  
  
9  
  if (f != null) {
10  
    if (verbose) print("cSmartSetField_withConverter: setting " + f + " = " + value);
11  
    if (converter != null && value != null) {
12  
      OrError<O> result = converter.convertValue(c, f, value);
13  
      if (result == null) fail("Unknown conversion " + className(value) + " => " + f);
14  
      if (!result.ok()) fail("Unknown conversion " + className(value) + " => " + f + ": " + result.error());
15  
      value = result!;
16  
    }
17  
    if (verbose) print("cSmartSetField_withConverter: converted value=" + value);
18  
    
19  
    // convert L to RefL
20  
    if (value instanceof L && f.getType() == Concept.RefL.class) {
21  
      Concept.RefL l = cast f.get(c);
22  
      if (verbose) print("cSmartSetField_withConverter: RefL=" + l);
23  
      l.replaceWithList((L) value);
24  
      if (verbose) print("cSmartSetField_withConverter: backrefs=" + c.backRefs);
25  
      true;
26  
    }
27  
    
28  
    // convert concept to Ref
29  
    
30  
    if (value instanceof Concept && f.getType() == Concept.Ref.class)
31  
      ret ((Concept.Ref) f.get(c)).set((Concept) value);
32  
  }
33  
 
34  
  ret _csetField(c, field, value);
35  
}

Author comment

Began life as a copy of #1026010

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1029594
Snippet name: cSmartSetField_withConverter
Eternal ID of this version: #1029594/9
Text MD5: f3a62935680f1808b74995c27fde696b
Transpilation MD5: 20198c5174ecbf02e9ce1265df0dad44
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-05 18:08:41
Source code size: 1511 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 276 / 403
Version history: 8 change(s)
Referenced in: [show references]