All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.envimate.mapmate.deserialization.builder.scanner.DataTransferObjectPackageScanner Maven / Gradle / Ivy

Go to download

MapMate is a modern mapping framework in the scope of mapping data in Json, XML, or YAML format into DTOs composed and vice versa.

There is a newer version: 1.6.8
Show newest version
/*
 * Copyright (C) 2017 [Richard Hauswald, Nune Isabekyan] (envimate GmbH - https://envimate.com/)
 */

package com.envimate.mapmate.deserialization.builder.scanner;

import com.envimate.mapmate.deserialization.DeserializableDataTransferObject;
import com.envimate.mapmate.deserialization.DeserializableDefinitions;
import com.envimate.mapmate.deserialization.methods.DeserializationDTOMethod;
import com.envimate.mapmate.filters.ClassFilter;
import com.envimate.mapmate.filters.ScanablePackage;
import com.envimate.mapmate.reflections.PackageName;

import java.util.List;
import java.util.Set;

import static com.envimate.mapmate.deserialization.DeserializableDataTransferObject.deserializableDataTransferObject;
import static com.envimate.mapmate.deserialization.DeserializableDefinitions.withTheDataTransferObjects;
import static com.envimate.mapmate.filters.ScanablePackage.scannablePackage;
import static java.util.stream.Collectors.toSet;

public final class DataTransferObjectPackageScanner implements PackageScanner {
    private final List classFilters;
    private final DeserializationDTOMethod deserializationDTOMethod;

    private DataTransferObjectPackageScanner(final List classFilters,
                                            final DeserializationDTOMethod deserializationDTOMethod) {
        this.classFilters = classFilters;
        this.deserializationDTOMethod = deserializationDTOMethod;
    }

    public static PackageScanner theDataTransferObjectPackageScanner(final List classFilters,
                                                                     final DeserializationDTOMethod deserializationDTOMethod) {
        return new DataTransferObjectPackageScanner(classFilters, deserializationDTOMethod);
    }

    @Override
    public DeserializableDefinitions scan(final PackageName packageName) {
        final ScanablePackage scanablePackage = scannablePackage(packageName, this.classFilters);
        final List> types = scanablePackage.getTypes();
        final Set dataTransferObjects = types.stream()
                .map(type -> deserializableDataTransferObject(type, this.deserializationDTOMethod))
                .collect(toSet());
        return withTheDataTransferObjects(dataTransferObjects);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy