DataUtil.java 966 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package com.gyee.wisdom.adapter.common.util;
  2. import com.gyee.wisdom.adapter.model.adapter.ToData;
  3. import java.util.Collection;
  4. import java.util.List;
  5. import java.util.Optional;
  6. import java.util.stream.Collectors;
  7. public abstract class DataUtil {
  8. private DataUtil() {
  9. }
  10. public static <T> List<T> convertDataList(Collection<? extends ToData<T>> toDataList) {
  11. return toDataList.stream().map(ToData::toData).collect(Collectors.toList());
  12. }
  13. public static <T> T getData(ToData<T> data) {
  14. return Optional.ofNullable(data).isPresent() ? data.toData() : null;
  15. }
  16. public static String convertStringToSql(String ...content){
  17. if (content == null)
  18. return null;
  19. StringBuilder sb = new StringBuilder();
  20. for (String data : content){
  21. sb.append("'").append(data).append("',");
  22. }
  23. String sql = sb.toString();
  24. return sql.substring(0, sql.length() - 1);
  25. }
  26. }