??Java Steams????????????
???????? ???????[ 2017/5/3 10:05:27 ] ??????????????????? Java
	?????????????????????????Java 8 Streams??????????????????????????????£???????????????????????????????????????????????Щ??????????????????????е???????????????????????????????????????t??????????????????????κ?????
	????????????????У?????????????????Java 8 Streams????????SQL??Ч??????????????и????????????????????Щ??????????????????Щ??????Щ????????????????????????????????????????
	????https://dzone.com/articles/java-streams-groupingby-examples
	????https://dzone.com/articles/using-java-collectors
	???????????????????“??????”???????????????????????????????Excel?????????????????????????????????ο??????????
	????http://www.novixys.com/blog/excel-pivot-table-using-apache-poi/
	??????CSV???????POJO
	?????????????μ?POJO??????Java????Plain Ordinary Java Object??????????????????乤???
	public class Player {
	private int year;
	private String teamID;
	private String lgID;
	private String playerID;
	private int salary;
	// defined getters and setters here
	}
	?????????????????????????CSV???????????????????????Σ????ж??е???Σ????????????л???????????????????????????????????????????????CSV?????????????????????б???С???????????????????????????д??26428?У?
	????yearID??teamID??lgID??playerID??salary
	????1985??ATL??NL??barkele01??870000
	????1985??ATL??NL??bedrost01??550000
	????1985??ATL??NL??benedbr01??545000
	????1985??ATL??NL??campri01??633333
	????1985??ATL??NL??ceronri01??625000
	????...
	??????????????????????????Streams????CSV???????
	Pattern pattern = Pattern.compile("??");
	try (BufferedReader in = new BufferedReader(new FileReader(filename));){
	List<Player> players = in
	.lines()
	.skip(1)
	.map(line -> {
	String[] arr = pattern.split(line);
	return new Player(Integer.parseInt(arr[0])??
	arr[1]??
	arr[2]??
	arr[3]??
	Integer.parseInt(arr[4]));
	})
	.collect(Collectors.toList());
	}
	?????????????????е???
	????????????????????????????????????????????????Щ???????????????з????????????????SQL???????Щ?н???????“GROUP BY”??????С?
	public class YearTeam
	{
	public int year;
	public String teamID;
	public YearTeam(int year??String teamID) {
	this.year = year;
	this.teamID = teamID;
	}
	@Override
	public boolean equals(Object other)
	{
	if ( other == null ) return false;
	if ( this == other ) return true;
	if ( other instanceof YearTeam ) {
	YearTeam yt = (YearTeam)other;
	if ( year == yt.year && teamID.equals(yt.teamID) )
	return true;
	}
	return false;
	}
	@Override
	public int hashCode()
	{
	int hash = 1;
	hash = hash * 17 + year;
	hash = hash * 31 + teamID.hashCode();
	return hash;
	}
	@Override
	public String toString()
	{
	StringBuilder sbuf = new StringBuilder();
	sbuf.append('[').append(year).append("?? ").append(teamID)
	.append(']');
	return sbuf.toString();
	}
	}
	???????????????????????Щ??α????????“public?????У?”????????????????????????ó????????????????????“private????У?”?????????????????getter??/??setter??
	?????????????д??equals()??hashCode()???????????洢???Map?????????????key????????á?
	??????Streams????????
	???????????????CSV???????????д??????POJO??????????????????????е?????????????з??顣
	????Map<YearTeam??List<Player>> grouped = in
	????.lines()
	????.skip(1)
	????.map(line -> {
	????String[] arr = pattern.split(line);
	????return new Player(Integer.parseInt(arr[0])??
	????arr[1]??
	????arr[2]??
	????arr[3]??
	????Integer.parseInt(arr[4]));
	????})
	????.collect(Collectors.groupingBy(x-> new YearTeam(x.getYear()?? x.getTeamID())));
	???????????Щ????????????????????????Map????????У?????????????????????顣
	??????????????????CSV
	?????????????????????????????????CSV??????????????????????Excel????????????????????????????????????summingLong()??Java 8 Streams????????averagingLong()????????????????????????????????????????????summarizingLong()????????????????????????????????e?!
	????CSV?е????????
	???????????teamID??????????????е????????????????????????????????????????????????TreeSet???????????????????С?
	????Set<String> teams = grouped
	????.keySet()
	????.stream()
	????.map(x -> x.teamID)
	????.collect(Collectors.toCollection(TreeSet::new));
	????System.out.print('??');
	????teams.stream().forEach(t -> System.out.print(t + "??"));
	????System.out.println();
	???????????
	????????????????????????????????????????????????????????????????б??????????????????????????????????
	Set<Integer> years = grouped
	.keySet()
	.stream()
	.map(x -> x.year)
	.collect(Collectors.toSet());
	years
	.stream()
	.forEach(y -> {
	System.out.print(y + "??");
	teams.stream().forEach(t -> {
	YearTeam yt = new YearTeam(y?? t);
	List<Player> players = grouped.get(yt);
	if ( players != null ) {
	long total = players
	.stream()
	.collect(Collectors.summingLong(Player::getSalary));
	System.out.print(total);
	}
	System.out.print('??');
	});
	System.out.println();
	});
	???????????Excel?????
	???????????CSV????????Excel?в?????????????
	??????Excel??????????????????б????????Щ????????????(?????????????????????“MON”????????Excel????????????????????“????”?е????ɡ??????????????????????)
	??????????????????Java??????Collections??????????????????????????????????????????????????????!
	???????
	?????????????????????????????????????????????????????????????Excel??????????????????????????????Java 8 Streams??????????????????????????????????????????????ù????
??????
					
					???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44
					
			
								
								
								
								
								
								
								
								
								
								
				
sales@spasvo.com