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

org.simpleflatmapper.reflect.meta.ArrayElementPropertyMeta Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

The newest version!
package org.simpleflatmapper.reflect.meta;

import org.simpleflatmapper.reflect.Getter;
import org.simpleflatmapper.reflect.ReflectionService;
import org.simpleflatmapper.reflect.Setter;
import org.simpleflatmapper.util.IntFactory;

import java.lang.reflect.Type;

public class ArrayElementPropertyMeta extends PropertyMeta {

	private final int index;
	private final ArrayClassMeta arrayMetaData;
	private final IntFactory> setterFactory;
	private final IntFactory> getterFactory;

	@SuppressWarnings("unchecked")
	public ArrayElementPropertyMeta(String name, Type ownerType, ReflectionService reflectService,
									int index,
									ArrayClassMeta arrayMetaData,
									IntFactory> setterFactory,
									IntFactory> getterFactory) {
		super(name, ownerType, reflectService);
		if (index < 0) throw new IllegalArgumentException("Invalid array index " + index);
		this.index = index;
		this.arrayMetaData = arrayMetaData;
		this.setterFactory = setterFactory;
		this.getterFactory = getterFactory;
	}

	@Override
	public Setter getSetter() {
        return setterFactory.newInstance(index);
	}

    @Override
    public Getter getGetter() {
        return getterFactory.newInstance(index);
    }

    @Override
	public Type getPropertyType() {
		return arrayMetaData.getElementTarget();
	}

	public int getIndex() {
		return index;
	}

	@Override
	public String getPath() {
		return  "[" + index + "]";
	}

	@Override
	public PropertyMeta withReflectionService(ReflectionService reflectionService) {
		return new ArrayElementPropertyMeta(getName(), getOwnerType(), reflectionService, index, arrayMetaData.withReflectionService(reflectionService), setterFactory, getterFactory);
	}

	@Override
	public PropertyMeta toNonMapped() {
		throw new UnsupportedOperationException();
	}

	@Override
    public String toString() {
        return "ArrayElementPropertyMeta{" +
                "index=" + index +
                '}';
    }


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

		ArrayElementPropertyMeta that = (ArrayElementPropertyMeta) o;

		if (index != that.index) return false;
		return arrayMetaData != null ? arrayMetaData.equals(that.arrayMetaData) : that.arrayMetaData == null;
	}

	@Override
	public int hashCode() {
		int result = index;
		result = 31 * result + (arrayMetaData != null ? arrayMetaData.hashCode() : 0);
		return result;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy