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

com.arextest.storage.compression.GenericCompressionBuilder Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
//package com.arextest.storage.compression;
//
//import com.arextest.common.utils.CompressionUtils;
//import com.arextest.model.mock.Mocker;
//import com.arextest.storage.model.annotations.FieldCompression;
//import com.arextest.storage.model.mocker.MockItem;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.collections4.CollectionUtils;
//import org.apache.commons.lang3.StringUtils;
//
//import javax.validation.constraints.NotNull;
//import java.lang.reflect.Field;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @author jmo
// * @since 2021/11/8
// */
//@Slf4j
//public final class GenericCompressionBuilder {
//    public static final GenericCompressionBuilder DEFAULT = new GenericCompressionBuilder<>();
//    private static final int DEFAULT_INITIAL_CAPACITY = 2;
//
//    public void compress(T instance, List fieldList) {
//        if (CollectionUtils.isEmpty(fieldList)) {
//            return;
//        }
//        for (int i = 0; i < fieldList.size(); i++) {
//            Field field = fieldList.get(i);
//            try {
//                String value = (String) field.get(instance);
//                if (StringUtils.isNotEmpty(value)) {
//                    field.set(instance, CompressionUtils.useZstdCompress(value));
//                }
//            } catch (IllegalAccessException e) {
//                LOGGER.error("field: {} compress error:{}", field, e.getMessage(), e);
//            }
//        }
//    }
//
//    public void decompress(T instance, List fieldList) {
//        if (CollectionUtils.isEmpty(fieldList)) {
//            return;
//        }
//        for (int i = 0; i < fieldList.size(); i++) {
//            Field field = fieldList.get(i);
//            try {
//                String value = (String) field.get(instance);
//
//                field.set(instance, CompressionUtils.useZstdDecompress(value));
//
//            } catch (IllegalAccessException e) {
//                LOGGER.error("field: {} decompress error:{}", field, e.getMessage(), e);
//            }
//        }
//    }
//
//    public List discoverCompression(@NotNull Class target) {
//        List fieldList = null;
//        Class current = target;
//        while (current != null) {
//            Field[] fields = current.getDeclaredFields();
//            for (int i = 0; i < fields.length; i++) {
//                Field field = fields[i];
//                if (field.getType() != String.class) {
//                    continue;
//                }
//                if (!field.isAnnotationPresent(FieldCompression.class)) {
//                    continue;
//                }
//                if (fieldList == null) {
//                    fieldList = new ArrayList<>(DEFAULT_INITIAL_CAPACITY);
//                }
//                field.setAccessible(true);
//                fieldList.add(field);
//            }
//            current = current.getSuperclass();
//        }
//        return fieldList;
//    }
//}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy