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

org.zodiac.netty.http.headers.StringArrayHeader Maven / Gradle / Ivy

package org.zodiac.netty.http.headers;

import java.util.Objects;

import org.zodiac.sdk.toolkit.util.lang.StrUtil;

final class StringArrayHeader extends AbstractHeader {

    StringArrayHeader(CharSequence name) {
        super(String[].class, name);
    }

    @Override
    public String toString(String... value) {
        Objects.requireNonNull(value, "value");
        StringBuilder stringBuilder = new StringBuilder();
        for (int i=0; i < value.length; i++) {
            stringBuilder.append(value[i]);
            if (i != value.length-1) {
                stringBuilder.append(',');
            }
        }
        return stringBuilder.toString();
    }

    @Override
    public String[] toValue(CharSequence value) {
        Objects.requireNonNull(value, "value");
        CharSequence[] result = StrUtil.splitToArray(value, ',');
        String[] rr = new String[result.length];
        for (int i = 0; i < result.length; i++) {
            rr[i] = result[i] instanceof String ? (String) result[i] :
                    result[i].toString();
        }
        return rr;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy