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

io.github.avivcarmis.confEager.properties.utils.ConfEagerPropertyPrimitiveArray Maven / Gradle / Ivy

package io.github.avivcarmis.confEager.properties.utils;

import io.github.avivcarmis.confEager.ConfEager;
import io.github.avivcarmis.confEager.ConfEagerProperty;

import java.lang.reflect.Array;
import java.util.LinkedList;
import java.util.List;

abstract public class ConfEagerPropertyPrimitiveArray extends ConfEagerProperty {

    private final ConfEagerValueMapper _mapper;

    private final Class _tClass;

    public ConfEagerPropertyPrimitiveArray(ConfEager.DefaultValue defaultValue, ConfEager.PropertyName propertyName, ConfEagerValueMapper mapper, Class tClass) {
        super(defaultValue, propertyName);
        _mapper = mapper;
        _tClass = tClass;
    }

    public ConfEagerPropertyPrimitiveArray(ConfEager.PropertyName propertyName, ConfEager.DefaultValue defaultValue, ConfEagerValueMapper mapper, Class tClass) {
        super(propertyName, defaultValue);
        _mapper = mapper;
        _tClass = tClass;
    }

    public ConfEagerPropertyPrimitiveArray(ConfEager.PropertyName propertyName, ConfEagerValueMapper mapper, Class tClass) {
        super(propertyName);
        _mapper = mapper;
        _tClass = tClass;
    }

    public ConfEagerPropertyPrimitiveArray(ConfEager.DefaultValue defaultValue, ConfEagerValueMapper mapper, Class tClass) {
        super(defaultValue);
        _mapper = mapper;
        _tClass = tClass;
    }

    public ConfEagerPropertyPrimitiveArray(ConfEagerValueMapper mapper, Class tClass) {
        _mapper = mapper;
        _tClass = tClass;
    }

    @Override
    protected T[] map(String value) {
        List list = new LinkedList<>();
        for (String s : value.split(",")) {
            String trimmed = s.trim();
            if (trimmed.isEmpty()) {
                continue;
            }
            list.add(_mapper.map(trimmed));
        }
        @SuppressWarnings("unchecked") T[] array = (T[]) Array.newInstance(_tClass, list.size());
        list.toArray(array);
        return array;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy