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

com.yuehuanghun.mybatis.milu.tool.converter.impl.StringConverter Maven / Gradle / Ivy

There is a newer version: 1.18.0
Show newest version
package com.yuehuanghun.mybatis.milu.tool.converter.impl;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.yuehuanghun.mybatis.milu.tool.converter.Converter;

public class StringConverter implements Converter {

	@Override
	public String convert(Object target) {
		if(target == null) {
			return null;
		}
		if(target instanceof Collection) {
			Collection c = (Collection) target;
			return c.stream().map(String::valueOf).collect(Collectors.joining(","));
			
		} else if(target.getClass().isArray()){
			int length = Array.getLength(target);
			StringJoiner joiner = new StringJoiner(",");
			IntStream.range(0, length).forEach(i -> {
				joiner.add(String.valueOf(Array.get(target, i)));
			});
		}
		return target.toString();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy