Libraryless. Click here for Pure Java version (20319L/123K).
1 | concept Entity > NamedConcept { |
2 | } |
3 | |
4 | abstract concept AbstractJavaObjectEntity<A> > Entity { |
5 | abstract A object(); |
6 | |
7 | toString { |
8 | S s = super.toString(); |
9 | O o = object(); |
10 | if (o != null) |
11 | s += " " + str_pcall(o); |
12 | ret s; |
13 | } |
14 | } |
15 | |
16 | concept TransientJavaObjectEntity<A> > AbstractJavaObjectEntity<A> { |
17 | gettable transient A object; |
18 | } |
19 | |
20 | concept PersistentJavaObjectEntity<A> > AbstractJavaObjectEntity<A> { |
21 | gettable A object; |
22 | } |
23 | |
24 | concept ConceptEntity<A extends Concept> extends AbstractJavaObjectEntity<A> { |
25 | new Ref<A> concept; |
26 | |
27 | *(A concept) { this.concept.set(concept); } |
28 | |
29 | A object() { ret concept!; } |
30 | } |
31 | |
32 | concept FieldInObjectEntity > Entity { |
33 | new Ref<AbstractJavaObjectEntity<?>> objectEntity; |
34 | S fieldName; |
35 | |
36 | *(AbstractJavaObjectEntity objectEntity, S *fieldName) { |
37 | this.objectEntity.set(objectEntity); |
38 | } |
39 | |
40 | O value() { ret !objectEntity.has() ? null : getOpt(objectEntity->object(), fieldName); } |
41 | |
42 | toString { |
43 | S s = super.toString() + " " + fieldName + " in " + objectEntity; |
44 | O value = value(); |
45 | if (value != null) |
46 | s += appendBracketed("value of type " + className(value)); |
47 | ret s; |
48 | } |
49 | } |
50 | |
51 | concept DeclaredFieldEntity > Entity { |
52 | Class theClass; |
53 | S fieldName; |
54 | |
55 | *(Class *theClass, S *fieldName) {} |
56 | |
57 | Field fieldObject() { ret findFieldOfClass(theClass, fieldName); } |
58 | |
59 | toString { |
60 | var fieldObject = fieldObject(); |
61 | ret super.toString() + " " + (fieldObject != null ? str(fieldObject) |
62 | : "[field not found: " + className(theClass) + "." + fieldName + "]"); |
63 | } |
64 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1034593 |
Snippet name: | Entity etc. |
Eternal ID of this version: | #1034593/16 |
Text MD5: | 6e891775dd5485e0e9efec1f5a4a16db |
Transpilation MD5: | c0342ea189530a9f8affc30846ab082e |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-19 09:52:04 |
Source code size: | 1610 bytes / 64 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 171 / 785 |
Version history: | 15 change(s) |
Referenced in: | [show references] |