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

org.vfdtech.implementations.PojoUtil Maven / Gradle / Ivy

Go to download

A utilities service with generic tools implementation. Can be plugged into your java project

There is a newer version: 0.3.5
Show newest version
package org.vfdtech.implementations;

import lombok.NoArgsConstructor;
import org.apache.commons.lang3.tuple.Pair;
import org.vfdtech.interfaces.IPojoUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Spliterator;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PojoUtil implements IPojoUtil {
    @Override
    public HashMap convertObjectToHashMap(Object object) {
        return null;
    }

    public static   Map> groupListBy(List listOfObjects, String groupBy) {
        groupBy= groupBy.substring(0,1).toUpperCase().concat(groupBy.substring(1));
        String finalGroupBy = groupBy;
        return listOfObjects.stream().collect(Collectors.groupingBy(m -> {
            try {
                return m.getClass().getMethod("get".concat(finalGroupBy)).invoke(m);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return finalGroupBy;
        }));

    }

    @Override
    public  T convertObjectToAny(Object object, Class returnClass) {
        return null;
    }

    @Override
    public List> getNonEmptyFields(Object object, Class classToConvertTo) {
        return null;
    }

    @Override
    public String getRandomString(String delimiter, String... prefix) {
        return null;
    }

    @Override
    public  List mergeList(List> y) {
        return null;
    }

    @Override
    public Integer getRandomInt(int maxNum) {
        return null;
    }

    @Override
    public String removeNonDigitsChars(CharSequence input) {
        return null;
    }

    @NoArgsConstructor
    public static class CustomForEach {

        public static  void forEach(
                Stream stream,
                BiConsumer consumer
        ) {
            Spliterator spliterator = stream.spliterator();
            boolean hadNext = true;
            Breaker breaker = new Breaker();

            while (hadNext && !breaker.get()) {
                hadNext =
                        spliterator.tryAdvance(
                                elem -> {
                                    consumer.accept(elem, breaker);
                                }
                        );
            }
        }

        public static class Breaker {

            private boolean shouldBreak = false;

            public void stop() {
                shouldBreak = true;
            }

            boolean get() {
                return shouldBreak;
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy