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

org.sfm.reflect.asm.CsvMapperKey Maven / Gradle / Ivy

package org.sfm.reflect.asm;

import org.sfm.csv.CsvColumnKey;
import org.sfm.csv.impl.CellSetter;
import org.sfm.csv.impl.CsvMapperCellHandler;
import org.sfm.csv.impl.DelayedCellSetterFactory;
import org.sfm.map.FieldMapperErrorHandler;
import org.sfm.reflect.Instantiator;

import java.lang.reflect.Type;
import java.util.Arrays;

public class CsvMapperKey {

    private final CsvColumnKey[] keys;
    private final Class[] setters;
    private final Class[] delayedSetters;
    private final Class instantiator;
    private final Type target;
    private final Class fieldErrorHandler;
    private final int maxMethodSize;



    public  CsvMapperKey(CsvColumnKey[] keys, CellSetter[] setters, DelayedCellSetterFactory[] delayedCellSetterFactories, Instantiator, T> instantiator, Type target, FieldMapperErrorHandler fieldErrorHandler, int maxMethodSize) {
        this.keys = keys;
        this.setters = getClassArray(setters);
        this.delayedSetters = getClassArray(delayedCellSetterFactories);
        this.instantiator = getClass(instantiator);
        this.target = target;
        this.fieldErrorHandler = getClass(fieldErrorHandler);
        this.maxMethodSize = maxMethodSize;

    }

    private Class[] getClassArray(Object[] objects) {
        Class[] classes = new Class[objects != null ? objects.length : 0];

        if(objects != null) {
            int i = 0;
            for(Object o : objects) {
                classes[i] = getClass(o);
                i++;
            }
        }

        return classes;
    }

    private Class getClass(Object o) {
        if (o != null) return o.getClass();
        return null;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CsvMapperKey that = (CsvMapperKey) o;

        if (maxMethodSize != that.maxMethodSize) return false;
        // Probably incorrect - comparing Object[] arrays with Arrays.equals
        if (!Arrays.equals(keys, that.keys)) return false;
        // Probably incorrect - comparing Object[] arrays with Arrays.equals
        if (!Arrays.equals(setters, that.setters)) return false;
        // Probably incorrect - comparing Object[] arrays with Arrays.equals
        if (!Arrays.equals(delayedSetters, that.delayedSetters)) return false;
        if (instantiator != null ? !instantiator.equals(that.instantiator) : that.instantiator != null) return false;
        if (target != null ? !target.equals(that.target) : that.target != null) return false;
        return !(fieldErrorHandler != null ? !fieldErrorHandler.equals(that.fieldErrorHandler) : that.fieldErrorHandler != null);

    }

    @Override
    public int hashCode() {
        int result = keys != null ? Arrays.hashCode(keys) : 0;
        result = 31 * result + (setters != null ? Arrays.hashCode(setters) : 0);
        result = 31 * result + (delayedSetters != null ? Arrays.hashCode(delayedSetters) : 0);
        result = 31 * result + (instantiator != null ? instantiator.hashCode() : 0);
        result = 31 * result + (target != null ? target.hashCode() : 0);
        result = 31 * result + (fieldErrorHandler != null ? fieldErrorHandler.hashCode() : 0);
        result = 31 * result + maxMethodSize;
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy