001 package org.hackystat.dailyprojectdata.resource.build; 002 003 import java.util.HashMap; 004 import java.util.HashSet; 005 import java.util.Map; 006 import java.util.Set; 007 008 /** 009 * Counts the number of successful and failed builds each user had. 010 * 011 * @author jsakuda 012 */ 013 public class MemberBuildCounter { 014 /** Mapping of users to the number of successful builds. */ 015 private Map<String, Integer> userToSuccessMap = new HashMap<String, Integer>(); 016 017 /** Mapping of users to the number of failed builds. */ 018 private Map<String, Integer> userToFailureMap = new HashMap<String, Integer>(); 019 020 /** All members with data in the counter. */ 021 private Set<String> members = new HashSet<String>(); 022 023 /** 024 * Adds a successful build for a user. 025 * 026 * @param user The user that had a successful build. 027 */ 028 public void addSuccessfulBuild(String user) { 029 if (this.userToSuccessMap.containsKey(user)) { 030 Integer count = this.userToSuccessMap.get(user) + 1; 031 this.userToSuccessMap.put(user, count); 032 } 033 else { 034 this.userToSuccessMap.put(user, 1); 035 } 036 this.members.add(user); 037 } 038 039 /** 040 * Adds a failed build for a user. 041 * 042 * @param user The user that had a failed build. 043 */ 044 public void addFailedBuild(String user) { 045 if (this.userToFailureMap.containsKey(user)) { 046 Integer count = this.userToFailureMap.get(user) + 1; 047 this.userToFailureMap.put(user, count); 048 } 049 else { 050 this.userToFailureMap.put(user, 1); 051 } 052 this.members.add(user); 053 } 054 055 /** 056 * Gets a mapping of users to the number of successful builds they had. 057 * 058 * @return Returns a mapping of users to the number of successful builds they had. 059 */ 060 public Map<String, Integer> getSuccessfulBuilds() { 061 return this.userToSuccessMap; 062 } 063 064 /** 065 * Gets a mapping of users to the number of failed builds they had. 066 * 067 * @return Returns a mapping of users to the number of failed builds they had. 068 */ 069 public Map<String, Integer> getFailedBuilds() { 070 return this.userToFailureMap; 071 } 072 073 /** 074 * Gets a set of all the members. 075 * 076 * @return Returns all the members. 077 */ 078 public Set<String> getMembers() { 079 return this.members; 080 } 081 }