スタッツ画面打率TOP10を実装。
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | package cx.myhome.ckoshien.action; |
| 2 | 2 | |
| 3 | +import java.util.ArrayList; | |
| 4 | +import java.util.Collections; | |
| 3 | 5 | import java.util.List; |
| 4 | 6 | |
| 5 | 7 | import javax.annotation.Resource; |
| @@ -12,10 +14,13 @@ | ||
| 12 | 14 | import cx.myhome.ckoshien.dto.PitchingResultDto; |
| 13 | 15 | import cx.myhome.ckoshien.entity.League; |
| 14 | 16 | import cx.myhome.ckoshien.form.ResultForm; |
| 17 | +import cx.myhome.ckoshien.logic.ResultLogic; | |
| 15 | 18 | import cx.myhome.ckoshien.service.BattingSumService; |
| 16 | 19 | import cx.myhome.ckoshien.service.LeagueService; |
| 17 | 20 | import cx.myhome.ckoshien.service.PitchingService; |
| 18 | 21 | import cx.myhome.ckoshien.service.ResultService; |
| 22 | +import cx.myhome.ckoshien.util.HomerunComparator; | |
| 23 | +import cx.myhome.ckoshien.util.RbiComparator; | |
| 19 | 24 | |
| 20 | 25 | public class ResultAction { |
| 21 | 26 |
| @@ -38,6 +43,10 @@ | ||
| 38 | 43 | public int length; |
| 39 | 44 | public List<GameResultDto> opponentList; |
| 40 | 45 | public List<GameResultDto> resultList2; |
| 46 | +public List<BattingResultDto> averageTop10; | |
| 47 | +public List<BattingResultDto> homerunTop10; | |
| 48 | +public ResultLogic resultLogic; | |
| 49 | +public List<BattingResultDto> rbiTop10; | |
| 41 | 50 | |
| 42 | 51 | |
| 43 | 52 | @Execute(validator = false) |
| @@ -53,7 +62,7 @@ | ||
| 53 | 62 | }catch(NumberFormatException e){ |
| 54 | 63 | return "index&redirect=true"; |
| 55 | 64 | } |
| 56 | - | |
| 65 | + System.setProperty("java.util.Arrays.useLegacyMergeSort", "true"); | |
| 57 | 66 | resultList=resultService.findGameResult(Integer.parseInt(resultForm.id)); |
| 58 | 67 | resultList2=resultList; |
| 59 | 68 | length=resultList.size(); |
| @@ -60,6 +69,26 @@ | ||
| 60 | 69 | opponentList=resultService.findOpponentResult(Integer.parseInt(resultForm.id)); |
| 61 | 70 | battingResultList=battingSumService.findByPeriod(league.beginDate, league.endDate); |
| 62 | 71 | pitchingResultList=pitchingService.findByPeriod(league.beginDate, league.endDate); |
| 72 | + resultLogic=new ResultLogic(); | |
| 73 | + //打率TOP10 | |
| 74 | + averageTop10=resultLogic.returnAverageTop10(battingResultList); | |
| 75 | +// Java7のソートにバグがありexceptionが発生するのでコメントアウト | |
| 76 | +// //HRTOP10 | |
| 77 | +// homerunTop10=new ArrayList<BattingResultDto>(); | |
| 78 | +// for(int i=0;i<battingResultList.size();i++){ | |
| 79 | +// homerunTop10.add(battingResultList.get(i)); | |
| 80 | +// } | |
| 81 | +// Collections.sort(homerunTop10, new HomerunComparator()); | |
| 82 | +// Collections.reverse(homerunTop10); | |
| 83 | +// homerunTop10=resultLogic.returnHomerunTop10(homerunTop10); | |
| 84 | +// //打点TOP10 | |
| 85 | +// rbiTop10=new ArrayList<BattingResultDto>(); | |
| 86 | +// for(int i=0;i<battingResultList.size();i++){ | |
| 87 | +// rbiTop10.add(battingResultList.get(i)); | |
| 88 | +// } | |
| 89 | +// Collections.sort(rbiTop10, new RbiComparator()); | |
| 90 | +// Collections.reverse(rbiTop10); | |
| 91 | +// rbiTop10=resultLogic.returnRbiTop10(rbiTop10); | |
| 63 | 92 | return "stats.jsp"; |
| 64 | 93 | } |
| 65 | 94 | } |
| @@ -0,0 +1,102 @@ | ||
| 1 | +package cx.myhome.ckoshien.logic; | |
| 2 | + | |
| 3 | +import java.util.ArrayList; | |
| 4 | +import java.util.List; | |
| 5 | + | |
| 6 | +import cx.myhome.ckoshien.dto.BattingResultDto; | |
| 7 | + | |
| 8 | +public class ResultLogic { | |
| 9 | + public List<BattingResultDto> averageTop10; | |
| 10 | + public BattingResultDto battingResultDto; | |
| 11 | + public List<BattingResultDto> homerunTop10; | |
| 12 | + public List<BattingResultDto> rbiTop10; | |
| 13 | + | |
| 14 | + public List<BattingResultDto> returnAverageTop10(List<BattingResultDto> battingResultList){ | |
| 15 | + int j=0; | |
| 16 | + int k=0; | |
| 17 | + averageTop10=new ArrayList<BattingResultDto>(); | |
| 18 | + for(int i=0;i<battingResultList.size();i++){ | |
| 19 | + battingResultDto=new BattingResultDto(); | |
| 20 | + if(battingResultList.get(i).tpa>=42){ | |
| 21 | + j++; | |
| 22 | + if (i>=1&&!(battingResultList.get(i-1).average==battingResultList.get(i).average)){ | |
| 23 | + battingResultDto.rank=j; | |
| 24 | + k=j; | |
| 25 | + } | |
| 26 | + convert2BattingResultDto(battingResultList,i); | |
| 27 | + if (battingResultDto.rank==null||battingResultDto.rank<=10){ | |
| 28 | + if (k>=11){ | |
| 29 | + break; | |
| 30 | + } | |
| 31 | + averageTop10.add(battingResultDto); | |
| 32 | + } | |
| 33 | + } | |
| 34 | + } | |
| 35 | + return averageTop10; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public List<BattingResultDto> returnHomerunTop10(List<BattingResultDto> battingResultList){ | |
| 39 | + int j=0; | |
| 40 | + int k=0; | |
| 41 | + homerunTop10=new ArrayList<BattingResultDto>(); | |
| 42 | + for(int i=0;i<battingResultList.size();i++){ | |
| 43 | + battingResultDto=new BattingResultDto(); | |
| 44 | + j++; | |
| 45 | + if (i==0){ | |
| 46 | + battingResultDto.rank=1; | |
| 47 | + } | |
| 48 | + if (i>=1 && (!battingResultList.get(i-1).homerun.equals(battingResultList.get(i).homerun))){ | |
| 49 | + battingResultDto.rank=j; | |
| 50 | + k=j; | |
| 51 | + } | |
| 52 | + convert2BattingResultDto(battingResultList,i); | |
| 53 | + if (battingResultDto.rank==null||battingResultDto.rank<=10){ | |
| 54 | + if (k>=11){ | |
| 55 | + break; | |
| 56 | + } | |
| 57 | + homerunTop10.add(battingResultDto); | |
| 58 | + | |
| 59 | + } | |
| 60 | + } | |
| 61 | + return homerunTop10; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public List<BattingResultDto> returnRbiTop10(List<BattingResultDto> battingResultList){ | |
| 65 | + int j=0; | |
| 66 | + int k=0; | |
| 67 | + rbiTop10=new ArrayList<BattingResultDto>(); | |
| 68 | + for(int i=0;i<battingResultList.size();i++){ | |
| 69 | + battingResultDto=new BattingResultDto(); | |
| 70 | + j++; | |
| 71 | + if (i==0){ | |
| 72 | + battingResultDto.rank=1; | |
| 73 | + } | |
| 74 | + if (i>=1 && (!battingResultList.get(i-1).rbi.equals(battingResultList.get(i).rbi))){ | |
| 75 | + battingResultDto.rank=j; | |
| 76 | + k=j; | |
| 77 | + } | |
| 78 | + convert2BattingResultDto(battingResultList,i); | |
| 79 | + if (battingResultDto.rank==null||battingResultDto.rank<=10){ | |
| 80 | + if (k>=11){ | |
| 81 | + break; | |
| 82 | + } | |
| 83 | + rbiTop10.add(battingResultDto); | |
| 84 | + | |
| 85 | + } | |
| 86 | + } | |
| 87 | + return rbiTop10; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public void convert2BattingResultDto(List<BattingResultDto> battingResultList,int i){ | |
| 91 | + battingResultDto.atBats=battingResultList.get(i).atBats; | |
| 92 | + battingResultDto.average=battingResultList.get(i).average; | |
| 93 | + battingResultDto.fourBall=battingResultList.get(i).fourBall; | |
| 94 | + battingResultDto.hit=battingResultList.get(i).hit; | |
| 95 | + battingResultDto.homerun=battingResultList.get(i).homerun; | |
| 96 | + battingResultDto.name=battingResultList.get(i).name; | |
| 97 | + battingResultDto.rbi=battingResultList.get(i).rbi; | |
| 98 | + battingResultDto.strikeOut=battingResultList.get(i).strikeOut; | |
| 99 | + battingResultDto.tpa=battingResultList.get(i).tpa; | |
| 100 | + battingResultDto.twobase=battingResultList.get(i).twobase; | |
| 101 | + } | |
| 102 | +} |
| @@ -0,0 +1,24 @@ | ||
| 1 | +package cx.myhome.ckoshien.util; | |
| 2 | + | |
| 3 | +import java.util.Comparator; | |
| 4 | + | |
| 5 | +import cx.myhome.ckoshien.dto.BattingResultDto; | |
| 6 | + | |
| 7 | +public class RbiComparator implements Comparator<BattingResultDto>{ | |
| 8 | + | |
| 9 | + @Override | |
| 10 | + public int compare(BattingResultDto o1, BattingResultDto o2) { | |
| 11 | + if (o1.rbi > o2.rbi) { | |
| 12 | + return 1; | |
| 13 | + | |
| 14 | + } else if (o1.rbi == o2.rbi) { | |
| 15 | + return 0; | |
| 16 | + | |
| 17 | + } else { | |
| 18 | + return -1; | |
| 19 | + | |
| 20 | + } | |
| 21 | + | |
| 22 | + } | |
| 23 | + | |
| 24 | +} |
| @@ -0,0 +1,24 @@ | ||
| 1 | +package cx.myhome.ckoshien.util; | |
| 2 | + | |
| 3 | +import java.util.Comparator; | |
| 4 | + | |
| 5 | +import cx.myhome.ckoshien.dto.BattingResultDto; | |
| 6 | + | |
| 7 | +public class HomerunComparator implements Comparator<BattingResultDto>{ | |
| 8 | + | |
| 9 | + @Override | |
| 10 | + public int compare(BattingResultDto o1, BattingResultDto o2) { | |
| 11 | + if (o1.homerun > o2.homerun) { | |
| 12 | + return 1; | |
| 13 | + | |
| 14 | + } else if (o1.homerun == o2.homerun) { | |
| 15 | + return 0; | |
| 16 | + | |
| 17 | + } else { | |
| 18 | + return -1; | |
| 19 | + | |
| 20 | + } | |
| 21 | + | |
| 22 | + } | |
| 23 | + | |
| 24 | +} |
| @@ -23,20 +23,32 @@ | ||
| 23 | 23 | @Required |
| 24 | 24 | public String lastTeam; |
| 25 | 25 | @Required |
| 26 | + @IntRange(min=0,max=40) | |
| 26 | 27 | public String firstRun; |
| 27 | 28 | @Required |
| 29 | + @IntRange(min=0,max=40) | |
| 28 | 30 | public String lastRun; |
| 29 | 31 | @Required |
| 32 | + @IntRange(min=0,max=20) | |
| 30 | 33 | public String top1st; |
| 31 | 34 | @Required |
| 35 | + @IntRange(min=0,max=20) | |
| 32 | 36 | public String bottom1st; |
| 37 | + @IntRange(min=0,max=20) | |
| 33 | 38 | public String top2nd; |
| 39 | + @IntRange(min=0,max=20) | |
| 34 | 40 | public String bottom2nd; |
| 41 | + @IntRange(min=0,max=20) | |
| 35 | 42 | public String top3rd; |
| 43 | + @IntRange(min=0,max=20) | |
| 36 | 44 | public String bottom3rd; |
| 45 | + @IntRange(min=0,max=20) | |
| 37 | 46 | public String top4th; |
| 47 | + @IntRange(min=0,max=20) | |
| 38 | 48 | public String bottom4th; |
| 49 | + @IntRange(min=0,max=20) | |
| 39 | 50 | public String top5th; |
| 51 | + @IntRange(min=0,max=20) | |
| 40 | 52 | public String bottom5th; |
| 41 | 53 | |
| 42 | 54 |
| @@ -44,16 +56,24 @@ | ||
| 44 | 56 | public List<String> playerRecordId; |
| 45 | 57 | public List<String> playerId; |
| 46 | 58 | //打席数 |
| 59 | + @IntRange(min=1,max=8) | |
| 47 | 60 | public List<String> tpa; |
| 48 | 61 | //打数 |
| 62 | + @IntRange(min=0,max=8) | |
| 49 | 63 | public List<String> atBats; |
| 50 | 64 | //安打 |
| 65 | + @IntRange(min=0,max=8) | |
| 51 | 66 | public List<String> hit; |
| 52 | 67 | //打点 |
| 68 | + @IntRange(min=0,max=10) | |
| 53 | 69 | public List<String> rbi; |
| 70 | + @IntRange(min=0,max=8) | |
| 54 | 71 | public List<String> fourBall; |
| 72 | + @IntRange(min=0,max=8) | |
| 55 | 73 | public List<String> strikeOut; |
| 74 | + @IntRange(min=0,max=8) | |
| 56 | 75 | public List<String> twoBase; |
| 76 | + @IntRange(min=0,max=8) | |
| 57 | 77 | public List<String> homerun; |
| 58 | 78 | // |
| 59 | 79 | public List<String> myTeamId; |
| @@ -62,15 +82,25 @@ | ||
| 62 | 82 | |
| 63 | 83 | //投球成績関連 |
| 64 | 84 | public List<String> p_playerId; |
| 85 | + @IntRange(min=0,max=5) | |
| 65 | 86 | public List<String> inning1; |
| 87 | + @IntRange(min=0,max=2) | |
| 66 | 88 | public List<String> inning2; |
| 89 | + @IntRange(min=1,max=48) | |
| 67 | 90 | public List<String> pa; |
| 91 | + @IntRange(min=0,max=40) | |
| 68 | 92 | public List<String> p_hit; |
| 93 | + @IntRange(min=0,max=10) | |
| 69 | 94 | public List<String> p_homerun; |
| 95 | + @IntRange(min=0,max=20) | |
| 70 | 96 | public List<String> p_fourBall; |
| 97 | + @IntRange(min=0,max=15) | |
| 71 | 98 | public List<String> p_strikeOut; |
| 99 | + @IntRange(min=0,max=40) | |
| 72 | 100 | public List<String> runs; |
| 101 | + @IntRange(min=0,max=1) | |
| 73 | 102 | public List<String> complete; |
| 103 | + @IntRange(min=0,max=1) | |
| 74 | 104 | public List<String> shutout; |
| 75 | 105 | public List<String> result; |
| 76 | 106 | public List<String> p_myTeamId; |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | |
| 3 | 3 | public class PitchingResultDto { |
| 4 | 4 | public Integer playerId; |
| 5 | + public Integer rank; | |
| 5 | 6 | public String name; |
| 6 | 7 | public Integer gameCount; |
| 7 | 8 | public Double era; |
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | private static final long serialVersionUID = 1L; |
| 12 | 12 | |
| 13 | 13 | public Integer playerId; |
| 14 | + public Integer rank; | |
| 14 | 15 | public String name; |
| 15 | 16 | |
| 16 | 17 | public Double average; |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | |
| 3 | 3 | public class GameResultDto { |
| 4 | 4 | public Integer teamId; |
| 5 | + public Integer rank; | |
| 5 | 6 | public String teamName; |
| 6 | 7 | public String shortName; |
| 7 | 8 | public Integer gameCount; |