/**
 * Copyright 2018 incub8 Software Labs GmbH
 * Copyright 2018 protel Hotelsoftware GmbH
 *
 * 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 com.github.mizool.core.converter;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

import lombok.experimental.UtilityClass;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

@UtilityClass
public class Converters
{
    public <D, P> List<D> fromPojos(List<P> pojos, Function<P, D> converter)
    {
        List<D> results = null;
        if (pojos != null && !pojos.isEmpty())
        {
            results = pojos.stream().map(converter).collect(ImmutableList.toImmutableList());
        }
        return results;
    }

    public <D, P> List<P> toPojos(List<D> values, Function<D, P> converter)
    {
        List<P> pojos;
        if (values != null)
        {
            pojos = values.stream().map(converter).collect(ImmutableList.toImmutableList());
        }
        else
        {
            pojos = Collections.emptyList();
        }
        return pojos;
    }

    public <D, P> Set<D> fromPojos(Set<P> pojos, Function<P, D> converter)
    {
        Set<D> results = null;
        if (pojos != null && !pojos.isEmpty())
        {
            results = pojos.stream().map(converter).collect(ImmutableSet.toImmutableSet());
        }

        return results;
    }

    public <D, P> Set<P> toPojos(Set<D> values, Function<D, P> converter)
    {
        Set<P> pojos;
        if (values != null)
        {
            pojos = values.stream().map(converter).collect(ImmutableSet.toImmutableSet());
        }
        else
        {
            pojos = Collections.emptySet();
        }
        return pojos;
    }
}
@@ -14,16 +14,21 @@
 ght 2018
+-2019
  incub8 
@@ -63,16 +63,21 @@
 ght 2018
+-2019
  protel 
@@ -1007,24 +1007,797 @@
 , P%3E List%3CD%3E
+ toDtos(List%3CP%3E pojos, Function%3CP, D%3E converter)%0A    %7B%0A        List%3CD%3E results;%0A        if (pojos != null)%0A        %7B%0A            results = pojos.stream().map(converter).collect(ImmutableList.toImmutableList());%0A        %7D%0A        else%0A        %7B%0A            results = Collections.emptyList();%0A        %7D%0A        return results;%0A    %7D%0A%0A    public %3CR, P%3E List%3CR%3E toRecords(List%3CP%3E pojos, Function%3CP, R%3E converter)%0A    %7B%0A        List%3CR%3E results = null;%0A        if (pojos != null && !pojos.isEmpty())%0A        %7B%0A            results = pojos.stream().map(converter).collect(ImmutableList.toImmutableList());%0A        %7D%0A        return results;%0A    %7D%0A%0A    /**%0A     * @deprecated Use %7B@link Converters#toRecords(List, Function)%7D instead.%0A     */%0A    @Deprecated%0A    public %3CR, P%3E List%3CR%3E
  fromPojos(L
@@ -1814,33 +1814,33 @@
 os, Function%3CP, 
-D
+R
 %3E converter)%0A   
@@ -1847,33 +1847,33 @@
  %7B%0A        List%3C
-D
+R
 %3E results = null
@@ -2443,16 +2443,778 @@
 %3E Set%3CD%3E
+ toDtos(Set%3CP%3E pojos, Function%3CP, D%3E converter)%0A    %7B%0A        Set%3CD%3E results;%0A        if (pojos != null)%0A        %7B%0A            results = pojos.stream().map(converter).collect(ImmutableSet.toImmutableSet());%0A        %7D%0A        else%0A        %7B%0A            results = Collections.emptySet();%0A        %7D%0A        return results;%0A    %7D%0A%0A    public %3CR, P%3E Set%3CR%3E toRecords(Set%3CP%3E pojos, Function%3CP, R%3E converter)%0A    %7B%0A        Set%3CR%3E results = null;%0A        if (pojos != null && !pojos.isEmpty())%0A        %7B%0A            results = pojos.stream().map(converter).collect(ImmutableSet.toImmutableSet());%0A        %7D%0A%0A        return results;%0A    %7D%0A%0A    /**%0A     * @deprecated Use %7B@link Converters#toRecords(Set, Function)%7D instead.%0A     */%0A    @Deprecated%0A    public %3CR, P%3E Set%3CR%3E
  fromPoj
@@ -3234,33 +3234,33 @@
 os, Function%3CP, 
-D
+R
 %3E converter)%0A   
@@ -3266,33 +3266,33 @@
   %7B%0A        Set%3C
-D
+R
 %3E results = null

Split the fromPojos methods into toDto and toRecord to allow them to be used in both cases.