标签:笑傲 Java String import List ht new Integer 面霸
笑傲Java面试:面霸修炼手册
V:ititit111222333
package com.tarzan.recommend.Service; import com.tarzan.recommend.dto.ItemDTO; import com.tarzan.recommend.dto.RelateDTO; import com.tarzan.recommend.dto.UserDTO; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.assertj.core.util.Lists; import org.springframework.util.ResourceUtils; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.List; @Data @Slf4j public class FileDataSource { public final static String folderPath="F:\\ml-100k"; /** * 方法描述: 读取基础数据 * * @param * @Return {@link List< RelateDTO>} * @throws * @author tarzan * @date 2020年07月31日 16:53:40 */ public static List<RelateDTO> getData() { List<RelateDTO> relateList = Lists.newArrayList(); try { FileInputStream out = new FileInputStream(folderPath+"\\u.data"); InputStreamReader reader = new InputStreamReader(out, StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(reader); String line = null; while ((line = in.readLine()) != null) { String newline = line.replaceAll("[\t]", " "); String[] ht = newline.split(" "); Integer userId = Integer.parseInt(ht[0]); Integer movieId = Integer.parseInt(ht[1]); Integer rating = Integer.parseInt(ht[2]); RelateDTO dto = new RelateDTO(userId, movieId, rating); relateList.add(dto); } } catch (IOException e) { log.error(e.getMessage()); } return relateList; } /** * 方法描述: 读取用户数据 * * @param * @Return {@link List< UserDTO>} * @throws * @author tarzan * @date 2020年07月31日 16:54:51 */ public static List<UserDTO> getUserData() { List<UserDTO> userList = Lists.newArrayList(); try { FileInputStream out = new FileInputStream(folderPath+"\\u.user"); InputStreamReader reader = new InputStreamReader(out, StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(reader); String line = null; while ((line = in.readLine()) != null) { String newline = line.replaceAll("[\t]", " "); String[] ht = newline.split("\\|"); Integer id = Integer.parseInt(ht[0]); Integer age = Integer.parseInt(ht[1]); String sex = ht[2]; String profession = ht[3]; String postcode = ht[4]; UserDTO dto = new UserDTO(id, age, sex, profession, postcode); userList.add(dto); } } catch (IOException e) { log.error(e.getMessage()); } return userList; } /** * 方法描述: 读取电影数据 * * @param * @Return {@link List< ItemDTO>} * @throws * @author tarzan * @date 2020年07月31日 16:54:22 */ public static List<ItemDTO> getItemData() { List<ItemDTO> itemList = Lists.newArrayList(); try { FileInputStream out = new FileInputStream(folderPath+"\\u.item"); InputStreamReader reader = new InputStreamReader(out, StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(reader); String line = null; while ((line = in.readLine()) != null) { String newline = line.replaceAll("[\t]", " "); String[] ht = newline.split("\\|"); Integer id = Integer.parseInt(ht[0]); String name = ht[1]; String date = ht[2]; String link = ht[3]; ItemDTO dto = new ItemDTO(id, name, date, link); itemList.add(dto); } } catch (IOException e) { log.error(e.getMessage()); } return itemList; } }
标签:笑傲,Java,String,import,List,ht,new,Integer,面霸 来源: https://blog.51cto.com/15063244/2670099
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。