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

org.simpleflatmapper.reflect.meta.MapKeyValueElementPropertyMeta 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.reflect.getter.NullGetter;

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

public class MapKeyValueElementPropertyMeta, K, V> extends PropertyMeta> {

	private final Type propertyType;
	private final MapSetter setter;

	public MapKeyValueElementPropertyMeta(Type ownerType,
										  ReflectionService reflectService,
										  Type propertyType) {
		super("entry", ownerType, reflectService);
		this.propertyType = propertyType;
		setter = new MapSetter();
	}

	@Override
	public Setter> getSetter() {
        return setter;
	}

    @Override
    public Getter> getGetter() {
        return NullGetter.getter();
    }

    @Override
	public Type getPropertyType() {
		return propertyType;
	}


	@Override
	public String getPath() {
		return getName();
	}

	@Override
	public PropertyMeta> withReflectionService(ReflectionService reflectionService) {
		return new MapKeyValueElementPropertyMeta(getOwnerType(), reflectionService, propertyType);
	}

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


	private static class MapSetter, K, V> implements Setter> {
		@Override
		public void set(T target, KeyValue value) throws Exception {
			target.put(value.getKey(), value.getValue());
		}
	}


    @Override
    public String toString() {
        return "MapKeyValueElementPropertyMeta{}";
    }

    public static class KeyValue {

		private final K key;
		private final V value;
		
		public KeyValue(K key, V value) {
			this.key = key;
			this.value = value;
		}

		public K getKey() {
			return key;
		}

		public V getValue() {
			return value;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy