From 823ee1a8e5fcdfee7054fd40f719f5b3139a4227 Mon Sep 17 00:00:00 2001 From: Konstantin Sobolev Date: Fri, 27 Oct 2017 16:39:49 -0700 Subject: [PATCH] asm: renamed `on` to `from` map asm: map extractor now takes projection as an extra argument --- .../types/AnonListTypeNameAsmImpl.java | 2 +- .../types/AnonMapTypeNameAsmImpl.java | 2 +- .../epigraph/types/DataTypeAsmImpl.java | 4 +-- .../epigraph/types/DataTypeNameAsmImpl.java | 2 +- .../epigraph/types/DatumTypeAsmImpl.java | 16 ++++----- .../epigraph/types/EntityTypeAsmImpl.java | 6 ++-- .../epigraph/types/FieldAsmImpl.java | 4 +-- .../epigraph/types/ListTypeAsmImpl.java | 10 +++--- .../epigraph/types/MapTypeAsmImpl.java | 12 +++---- .../types/NameString_Type_MapAsmImpl.java | 4 +-- .../epigraph/types/PrimitiveTypeAsmImpl.java | 8 ++--- .../epigraph/types/RecordTypeAsmImpl.java | 8 ++--- .../resources/epigraph/types/TagAsmImpl.java | 4 +-- .../resources/epigraph/types/TypeAsmImpl.java | 8 ++--- .../epigraph/types/TypeNameAsmImpl.java | 6 ++-- .../library/AsmBasedBooksReadOperation.java | 3 +- .../examples/library/BookRecordAsmImpl.java | 2 +- .../java/service/assemblers/MapAsmGen.scala | 7 ++-- .../main/java/ws/epigraph/assembly/Asm.java | 4 +-- .../main/java/ws/epigraph/util/Function2.java | 33 +++++++++++++++++++ .../main/java/ws/epigraph/util/Tuple2.java | 7 ++++ todo.md | 1 + 22 files changed, 98 insertions(+), 55 deletions(-) create mode 100644 java/util/src/main/java/ws/epigraph/util/Function2.java diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/AnonListTypeNameAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/AnonListTypeNameAsmImpl.java index 9891aaf48..66820f405 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/AnonListTypeNameAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/AnonListTypeNameAsmImpl.java @@ -27,7 +27,7 @@ public final class AnonListTypeNameAsmImpl extends AnonListTypeNameAsm tn.elementTypeName), + DataTypeNameAsmImpl.INSTANCE.from(tn -> tn.elementTypeName), TypeNameAsmImpl.TYPE_NAME_ASM ); } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/AnonMapTypeNameAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/AnonMapTypeNameAsmImpl.java index 1794877da..0e17e3199 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/AnonMapTypeNameAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/AnonMapTypeNameAsmImpl.java @@ -30,7 +30,7 @@ private AnonMapTypeNameAsmImpl() { super( new AnonMapTypeNameRecordAsm<>( TypeNameAsmImpl.INSTANCE, - DataTypeNameAsmImpl.INSTANCE.on(tn -> tn.valueTypeName) + DataTypeNameAsmImpl.INSTANCE.from(tn -> tn.valueTypeName) ), TypeNameAsmImpl.TYPE_NAME_ASM ); diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DataTypeAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DataTypeAsmImpl.java index 84de5a25b..d985b8102 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DataTypeAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DataTypeAsmImpl.java @@ -28,8 +28,8 @@ public final class DataTypeAsmImpl extends DataTypeAsm { private DataTypeAsmImpl() { super( - TagAsmImpl.INSTANCE.on(DataTypeApi::retroTag), - TypeAsmImpl.INSTANCE.on(DataTypeApi::type) + TagAsmImpl.INSTANCE.from(DataTypeApi::retroTag), + TypeAsmImpl.INSTANCE.from(DataTypeApi::type) ); } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DataTypeNameAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DataTypeNameAsmImpl.java index d7d98be07..436d567b3 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DataTypeNameAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DataTypeNameAsmImpl.java @@ -37,7 +37,7 @@ private DataTypeNameAsmImpl() { .map(retro -> NameString.create(retro).asValue()) .orElse(NameString.type.createValue(null)) ), - TypeNameAsmImpl.INSTANCE.on(dtn -> dtn.typeName) + TypeNameAsmImpl.INSTANCE.from(dtn -> dtn.typeName) ); } } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DatumTypeAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DatumTypeAsmImpl.java index fc68595fc..33caef480 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DatumTypeAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/DatumTypeAsmImpl.java @@ -47,16 +47,16 @@ public DatumTypeAsmImpl() { throw new RuntimeException("unknown kind: " + t.kind()); } }, - TypeAsmImpl.ABSTRACT_ASM.on(t -> (DatumTypeApi) t), // abstract - AnnotationsAsmImpl.INSTANCE.on(DatumTypeApi::annotations), // annotations - INSTANCE.on(DatumTypeApi::metaType), // meta - TypeNameAsmImpl.INSTANCE.on(DatumTypeApi::name), // name + TypeAsmImpl.ABSTRACT_ASM.from(t -> (DatumTypeApi) t), // abstract + AnnotationsAsmImpl.INSTANCE.from(DatumTypeApi::annotations), // annotations + INSTANCE.from(DatumTypeApi::metaType), // meta + TypeNameAsmImpl.INSTANCE.from(DatumTypeApi::name), // name new DatumType_ListAsm<>(DatumTypeApi::supertypes, INSTANCE), // supertypes //tails - RecordTypeAsmImpl.INSTANCE.on(t -> (RecordTypeApi) t), // record - MapTypeAsmImpl.INSTANCE.on(t -> (MapTypeApi) t), // map - ListTypeAsmImpl.INSTANCE.on(t -> (ListTypeApi) t), // list - PrimitiveTypeAsmImpl.INSTANCE.on(t -> (PrimitiveTypeApi) t) // primitive + RecordTypeAsmImpl.INSTANCE.from(t -> (RecordTypeApi) t), // record + MapTypeAsmImpl.INSTANCE.from(t -> (MapTypeApi) t), // map + ListTypeAsmImpl.INSTANCE.from(t -> (ListTypeApi) t), // list + PrimitiveTypeAsmImpl.INSTANCE.from(t -> (PrimitiveTypeApi) t) // primitive ); } } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/EntityTypeAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/EntityTypeAsmImpl.java index df819138d..0365ca2e1 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/EntityTypeAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/EntityTypeAsmImpl.java @@ -29,9 +29,9 @@ public final class EntityTypeAsmImpl extends EntityTypeAsm { private EntityTypeAsmImpl() { super( - TypeAsmImpl.ABSTRACT_ASM.on(t -> (EntityTypeApi) t), // abstract - AnnotationsAsmImpl.INSTANCE.on(EntityTypeApi::annotations), // annotations - QualifiedTypeNameAsmImpl.INSTANCE.on(EntityTypeApi::name), // name + TypeAsmImpl.ABSTRACT_ASM.from(t -> (EntityTypeApi) t), // abstract + AnnotationsAsmImpl.INSTANCE.from(EntityTypeApi::annotations), // annotations + QualifiedTypeNameAsmImpl.INSTANCE.from(EntityTypeApi::name), // name new EntityType_ListAsm<>(EntityTypeApi::supertypes, INSTANCE), // supertypes new Tag_ListAsm<>(EntityTypeApi::tags, TagAsmImpl.INSTANCE) // tags ); diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/FieldAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/FieldAsmImpl.java index 5edbf6620..c0d539c54 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/FieldAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/FieldAsmImpl.java @@ -29,9 +29,9 @@ public final class FieldAsmImpl extends Field_Asm { private FieldAsmImpl() { super( - AnnotationsAsmImpl.INSTANCE.on(FieldApi::annotations), + AnnotationsAsmImpl.INSTANCE.from(FieldApi::annotations), (f, p, c) -> FieldName.create().setString(NameString.create(f.name())), - DataTypeAsmImpl.INSTANCE.on(FieldApi::dataType) + DataTypeAsmImpl.INSTANCE.from(FieldApi::dataType) ); } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/ListTypeAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/ListTypeAsmImpl.java index 0595549e4..fadcd7904 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/ListTypeAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/ListTypeAsmImpl.java @@ -28,12 +28,12 @@ public final class ListTypeAsmImpl extends ListTypeAsm { private ListTypeAsmImpl() { super( - TypeAsmImpl.ABSTRACT_ASM.on(t -> (ListTypeApi) t), // abstract - AnnotationsAsmImpl.INSTANCE.on(ListTypeApi::annotations), // annotations - DatumTypeAsmImpl.INSTANCE.on(ListTypeApi::metaType), // meta - TypeNameAsmImpl.INSTANCE.on(ListTypeApi::name), // name + TypeAsmImpl.ABSTRACT_ASM.from(t -> (ListTypeApi) t), // abstract + AnnotationsAsmImpl.INSTANCE.from(ListTypeApi::annotations), // annotations + DatumTypeAsmImpl.INSTANCE.from(ListTypeApi::metaType), // meta + TypeNameAsmImpl.INSTANCE.from(ListTypeApi::name), // name new ListType_ListAsm<>(ListTypeApi::supertypes, INSTANCE), // supertypes - DataTypeAsmImpl.INSTANCE.on(ListTypeApi::elementType) // element type + DataTypeAsmImpl.INSTANCE.from(ListTypeApi::elementType) // element type ); } } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/MapTypeAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/MapTypeAsmImpl.java index 1ce1cb024..40c6678bf 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/MapTypeAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/MapTypeAsmImpl.java @@ -28,13 +28,13 @@ public final class MapTypeAsmImpl extends MapTypeAsm { private MapTypeAsmImpl() { super( - TypeAsmImpl.ABSTRACT_ASM.on(t -> (MapTypeApi) t), // abstract - AnnotationsAsmImpl.INSTANCE.on(MapTypeApi::annotations), // annotations - DatumTypeAsmImpl.INSTANCE.on(MapTypeApi::keyType), // key type - DatumTypeAsmImpl.INSTANCE.on(MapTypeApi::metaType), // meta - TypeNameAsmImpl.INSTANCE.on(MapTypeApi::name), // name + TypeAsmImpl.ABSTRACT_ASM.from(t -> (MapTypeApi) t), // abstract + AnnotationsAsmImpl.INSTANCE.from(MapTypeApi::annotations), // annotations + DatumTypeAsmImpl.INSTANCE.from(MapTypeApi::keyType), // key type + DatumTypeAsmImpl.INSTANCE.from(MapTypeApi::metaType), // meta + TypeNameAsmImpl.INSTANCE.from(MapTypeApi::name), // name new MapType_ListAsm<>(MapTypeApi::supertypes, INSTANCE), // supertypes - DataTypeAsmImpl.INSTANCE.on(MapTypeApi::valueType) // value type + DataTypeAsmImpl.INSTANCE.from(MapTypeApi::valueType) // value type ); } } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/NameString_Type_MapAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/NameString_Type_MapAsmImpl.java index c468b866b..2c1adf3dd 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/NameString_Type_MapAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/NameString_Type_MapAsmImpl.java @@ -19,9 +19,9 @@ import epigraph.schema.NameString; import ws.epigraph.services._resources.epigraph.operations.read.types.output.NameString_Type_MapAsm; import ws.epigraph.types.TypeApi; +import ws.epigraph.util.Function2; import java.util.Map; -import java.util.function.Function; /** * @author Konstantin Sobolev @@ -34,7 +34,7 @@ public final class NameString_Type_MapAsmImpl private NameString_Type_MapAsmImpl() { super( NameString::create, - Function.identity(), + Function2.identity1(), TypeAsmImpl.INSTANCE ); } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/PrimitiveTypeAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/PrimitiveTypeAsmImpl.java index c8b0efec4..74645a2f1 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/PrimitiveTypeAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/PrimitiveTypeAsmImpl.java @@ -28,10 +28,10 @@ public final class PrimitiveTypeAsmImpl extends PrimitiveTypeAsm (PrimitiveTypeApi) t), // abstract - AnnotationsAsmImpl.INSTANCE.on(PrimitiveTypeApi::annotations), // annotations - DatumTypeAsmImpl.INSTANCE.on(PrimitiveTypeApi::metaType), // meta - QualifiedTypeNameAsmImpl.INSTANCE.on(PrimitiveTypeApi::name), // name + TypeAsmImpl.ABSTRACT_ASM.from(t -> (PrimitiveTypeApi) t), // abstract + AnnotationsAsmImpl.INSTANCE.from(PrimitiveTypeApi::annotations), // annotations + DatumTypeAsmImpl.INSTANCE.from(PrimitiveTypeApi::metaType), // meta + QualifiedTypeNameAsmImpl.INSTANCE.from(PrimitiveTypeApi::name), // name new PrimitiveType_ListAsm<>(PrimitiveTypeApi::supertypes, INSTANCE) // supertypes ); diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/RecordTypeAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/RecordTypeAsmImpl.java index 2b0522486..9f4b97675 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/RecordTypeAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/RecordTypeAsmImpl.java @@ -29,11 +29,11 @@ public final class RecordTypeAsmImpl extends RecordTypeAsm { private RecordTypeAsmImpl() { super( - TypeAsmImpl.ABSTRACT_ASM.on(t -> (RecordTypeApi) t), // abstract - AnnotationsAsmImpl.INSTANCE.on(RecordTypeApi::annotations), // annotations + TypeAsmImpl.ABSTRACT_ASM.from(t -> (RecordTypeApi) t), // abstract + AnnotationsAsmImpl.INSTANCE.from(RecordTypeApi::annotations), // annotations new Field_ListAsm<>(RecordTypeApi::immediateFields, FieldAsmImpl.INSTANCE), // declared fields - DatumTypeAsmImpl.INSTANCE.on(RecordTypeApi::metaType), // meta - QualifiedTypeNameAsmImpl.INSTANCE.on(RecordTypeApi::name), // name + DatumTypeAsmImpl.INSTANCE.from(RecordTypeApi::metaType), // meta + QualifiedTypeNameAsmImpl.INSTANCE.from(RecordTypeApi::name), // name new RecordType_ListAsm<>(RecordTypeApi::supertypes, INSTANCE) // supertypes ); } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TagAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TagAsmImpl.java index 15c433cab..ab544e9e0 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TagAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TagAsmImpl.java @@ -29,9 +29,9 @@ public final class TagAsmImpl extends Tag_Asm { private TagAsmImpl() { super( - AnnotationsAsmImpl.INSTANCE.on(TagApi::annotations), + AnnotationsAsmImpl.INSTANCE.from(TagApi::annotations), (tag, projection, ctx) -> TagName.create().setString(NameString.create(tag.name())), - DatumTypeAsmImpl.INSTANCE.on(TagApi::type) + DatumTypeAsmImpl.INSTANCE.from(TagApi::type) ); } } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TypeAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TypeAsmImpl.java index f64896002..c741aacc8 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TypeAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TypeAsmImpl.java @@ -36,12 +36,12 @@ private TypeAsmImpl() { super( t -> (t.kind() == TypeKind.ENTITY) ? epigraph.schema.EntityType.type : epigraph.schema.DatumType.type, // (output) type extractor ABSTRACT_ASM, // abstract - AnnotationsAsmImpl.INSTANCE.on(TypeApi::annotations), // annotations - TypeNameAsmImpl.INSTANCE.on(TypeApi::name), // name + AnnotationsAsmImpl.INSTANCE.from(TypeApi::annotations), // annotations + TypeNameAsmImpl.INSTANCE.from(TypeApi::name), // name new Type_ListAsm<>(TypeApi::supertypes, TypeAsmImpl.INSTANCE), // supertypes //tails - EntityTypeAsmImpl.INSTANCE.on(t -> (EntityTypeApi) t), // entity - DatumTypeAsmImpl.INSTANCE.on(t -> (DatumTypeApi) t) // datum + EntityTypeAsmImpl.INSTANCE.from(t -> (EntityTypeApi) t), // entity + DatumTypeAsmImpl.INSTANCE.from(t -> (DatumTypeApi) t) // datum ); } } diff --git a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TypeNameAsmImpl.java b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TypeNameAsmImpl.java index 8b0c70f2f..e556fb401 100644 --- a/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TypeNameAsmImpl.java +++ b/builtin-services/builtin-services-service/src/main/java/ws/epigraph/services/resources/epigraph/types/TypeNameAsmImpl.java @@ -46,9 +46,9 @@ private TypeNameAsmImpl() { else throw new IllegalArgumentException(tn.getClass().getName()); }, TYPE_NAME_ASM, - QualifiedTypeNameAsmImpl.INSTANCE.on(tn -> (QualifiedTypeName) tn), - AnonListTypeNameAsmImpl.INSTANCE.on(tn -> (AnonListTypeName) tn), - AnonMapTypeNameAsmImpl.INSTANCE.on(tn -> (AnonMapTypeName) tn) + QualifiedTypeNameAsmImpl.INSTANCE.from(tn -> (QualifiedTypeName) tn), + AnonListTypeNameAsmImpl.INSTANCE.from(tn -> (AnonListTypeName) tn), + AnonMapTypeNameAsmImpl.INSTANCE.from(tn -> (AnonMapTypeName) tn) ); } diff --git a/examples/library/library-service/src/main/java/ws/epigraph/examples/library/AsmBasedBooksReadOperation.java b/examples/library/library-service/src/main/java/ws/epigraph/examples/library/AsmBasedBooksReadOperation.java index cabba7c24..672148193 100644 --- a/examples/library/library-service/src/main/java/ws/epigraph/examples/library/AsmBasedBooksReadOperation.java +++ b/examples/library/library-service/src/main/java/ws/epigraph/examples/library/AsmBasedBooksReadOperation.java @@ -22,6 +22,7 @@ import ws.epigraph.examples.library._resources.books.operations.read._default.output.BookId_BookRecord_MapAsm; import ws.epigraph.examples.library._resources.books.operations.read._default.output.OutputBooksFieldProjection; import ws.epigraph.schema.operations.ReadOperationDeclaration; +import ws.epigraph.util.Function2; import java.util.concurrent.CompletableFuture; import java.util.function.Function; @@ -42,7 +43,7 @@ public class AsmBasedBooksReadOperation extends AbstractReadOperation { BookId_BookRecord_Map.Value value = new BookId_BookRecord_MapAsm<>( Function.identity(), // key converter - Function.identity(), // map extractor + Function2.identity1(), // map extractor BookRecordAsmImpl.INSTANCE // items assembler ).assemble(BooksBackend.getBooks(), projection.dataProjection(), new AsmContext()); diff --git a/examples/library/library-service/src/main/java/ws/epigraph/examples/library/BookRecordAsmImpl.java b/examples/library/library-service/src/main/java/ws/epigraph/examples/library/BookRecordAsmImpl.java index 032739c0b..98c6bfc77 100644 --- a/examples/library/library-service/src/main/java/ws/epigraph/examples/library/BookRecordAsmImpl.java +++ b/examples/library/library-service/src/main/java/ws/epigraph/examples/library/BookRecordAsmImpl.java @@ -29,7 +29,7 @@ public final class BookRecordAsmImpl extends BookRecordAsm AuthorsBackend.get(bd.authorId)), + AuthorAsmImpl.INSTANCE.from(bd -> AuthorsBackend.get(bd.authorId)), // text new TextAsm<>(PlainTextAsm.INSTANCE), diff --git a/java/codegen/src/main/scala/ws/epigraph/java/service/assemblers/MapAsmGen.scala b/java/codegen/src/main/scala/ws/epigraph/java/service/assemblers/MapAsmGen.scala index 8b23fff82..a7a33502f 100644 --- a/java/codegen/src/main/scala/ws/epigraph/java/service/assemblers/MapAsmGen.scala +++ b/java/codegen/src/main/scala/ws/epigraph/java/service/assemblers/MapAsmGen.scala @@ -46,6 +46,7 @@ class MapAsmGen( private val kt = importManager.use(lqn2(keyCType, nsString)) private val it = importManager.use(lqn2(itemCType, nsString)) private val elementGenName = importManager.use(g.elementGen.fullClassName) + private val fun2 = importManager.use(classOf[ws.epigraph.util.Function2[_, _, _]].getName) import Imports._ @@ -62,7 +63,7 @@ else { $t.Builder b = $t.create(); ctx.visited.put(key, b.asValue()); $elementGenName itemsProjection = p.itemsProjection(); - $mp map = mapExtractor.apply(dto); + $mp map = mapExtractor.apply(dto, p); for ($mp.Entry entry: map.entrySet()) { $kt k = keyConverter.apply(entry.getKey()); b.put${if (isEntity) "$" else "_"}(k, itemAsm.assemble(entry.getValue(), itemsProjection, ctx)); @@ -96,7 +97,7 @@ ${JavaGenUtils.generatedAnnotation(this)} public class $shortClassName implements $assembler { ${if (hasTails) s" private final $notNull $func typeExtractor;\n" else "" }\ private final $notNull $keysConverterType keyConverter; - private final $notNull $func> mapExtractor; + private final $notNull $fun2> mapExtractor; private final $notNull $itemAsmType itemAsm; ${if (hasTails) tps.map { tp => s" private final $notNull ${tp.assemblerType} ${tp.assembler};"}.mkString("\n //tail assemblers\n","\n","") else "" }\ ${if (hasMeta) s" //meta assembler\n private final $notNull $metaAsmType metaAsm;" else ""} @@ -114,7 +115,7 @@ ${if (hasMeta) s"\n * @param metaAsm metadata assembler" else ""} public $shortClassName( ${if (hasTails) s" $notNull $func typeExtractor,\n" else "" }\ $notNull $keysConverterType keyConverter, - $notNull $func> mapExtractor, + $notNull $fun2> mapExtractor, $notNull $itemAsmType itemAsm\ ${if (hasTails) tps.map { tp => s" $notNull ${tp.assemblerType} ${tp.assembler}"}.mkString(",\n", ",\n", "") else ""}\ ${if (hasMeta) s",\n $notNull $metaAsmType metaAsm" else ""} diff --git a/java/core/src/main/java/ws/epigraph/assembly/Asm.java b/java/core/src/main/java/ws/epigraph/assembly/Asm.java index a6b5393f3..0cb4adcb0 100644 --- a/java/core/src/main/java/ws/epigraph/assembly/Asm.java +++ b/java/core/src/main/java/ws/epigraph/assembly/Asm.java @@ -48,7 +48,7 @@ public interface Asm { * * @return composed assembler */ - default @NotNull Asm on(@NotNull Function f) { + default @NotNull Asm from(@NotNull Function f) { return (dto, projection, ctx) -> assemble(f.apply(dto), projection, ctx); } @@ -62,7 +62,7 @@ public interface Asm { * * @return composed assembler */ - default @NotNull Asm on(@NotNull Function f, @NotNull Function ef) { + default @NotNull Asm from(@NotNull Function f, @NotNull Function ef) { return (dto, projection, ctx) -> { D d; try { diff --git a/java/util/src/main/java/ws/epigraph/util/Function2.java b/java/util/src/main/java/ws/epigraph/util/Function2.java new file mode 100644 index 000000000..557f47848 --- /dev/null +++ b/java/util/src/main/java/ws/epigraph/util/Function2.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017 Sumo Logic + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ws.epigraph.util; + +/** + * @author Konstantin Sobolev + */ +@FunctionalInterface +public interface Function2 { + C apply(A a, B b); + + static Function2 identity1() { + return (x, a) -> x; + } + + static Function2 identity2() { + return (x, a) -> a; + } +} diff --git a/java/util/src/main/java/ws/epigraph/util/Tuple2.java b/java/util/src/main/java/ws/epigraph/util/Tuple2.java index 5bd60e002..e07caf9ff 100644 --- a/java/util/src/main/java/ws/epigraph/util/Tuple2.java +++ b/java/util/src/main/java/ws/epigraph/util/Tuple2.java @@ -16,6 +16,7 @@ package ws.epigraph.util; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import java.util.Objects; @@ -32,6 +33,12 @@ public Tuple2(final T1 _1, final T2 _2) { this._2 = _2; } + @Contract(pure = true) + public T1 first() { return _1; } + + @Contract(pure = true) + public T2 second() { return _2; } + public static @NotNull Tuple2 of(T1 _1, T2 _2) { return new Tuple2<>(_1, _2); } @Override diff --git a/todo.md b/todo.md index 8bbb8c0ea..c52932117 100644 --- a/todo.md +++ b/todo.md @@ -128,6 +128,7 @@ # Cleanup - [ ] check out artifactory-tools to clean up old light-psi versions + - see `ArtifactoryClient` - [ ] DataType(Api): type should be EntityType ? - [ ] Rename Data/Var/Union type to some common name