@@ -579,8 +579,8 @@ public int hashCode() {
579579 * @param <T>
580580 */
581581 static class MaxCounter <T > extends Counter <T > {
582- public MaxCounter (boolean b ) {
583- super (b );
582+ public MaxCounter (boolean naturalOrdering ) {
583+ super (naturalOrdering );
584584 }
585585
586586 /** Add, but only to bring up to the maximum value. */
@@ -589,6 +589,8 @@ public MaxCounter<T> add(T obj, long countValue, long time) {
589589 long value = getCount (obj );
590590 if ((value <= countValue )) {
591591 super .add (obj , countValue - value , time ); // only add the difference!
592+ } else {
593+ super .add (obj , 0 , time ); // just add a participant
592594 }
593595 return this ;
594596 }
@@ -780,19 +782,23 @@ public Counter<T> getTotals(EnumSet<Organization> conflictedOrganizations) {
780782 }
781783 }
782784 }
783- // This is deprecated, but preserve it until the method is removed.
784- /*
785- * TODO: explain the above comment, and follow through. What is deprecated (orgToAdd, or getOrgVote)?
786- * Preserve until which method is removed (getOrgVote)?
787- */
785+
786+ // temporarily make the top voted value this org's value.
787+ // TODO: may not be needed, see below
788788 orgToAdd .put (org , value );
789789
790- // We add the max vote for each of the organizations choices
791- long maxCount = 0 ;
790+ /** does this org vote by time (TC) or by number of votes (others)? */
791+ final boolean votesByTime = orgVotesByTime (org );
792+
792793 T considerItem = null ;
793794 long considerCount = 0 ;
794- long maxtime = 0 ;
795795 long considerTime = 0 ;
796+ int considerParticipation = 0 ;
797+
798+ // We add the max vote for each of the organizations choices
799+ long maxCount = 0 ;
800+ long maxtime = 0 ;
801+
796802 for (T item : items .keySet ()) {
797803 if (DEBUG ) {
798804 System .out .println (
@@ -802,6 +808,7 @@ public Counter<T> getTotals(EnumSet<Organization> conflictedOrganizations) {
802808 }
803809 long count = items .getCount (item );
804810 long time = items .getTime (item );
811+ int participation = votesByTime ? 0 : items .getParticipation (item );
805812 if (count > maxCount ) {
806813 maxCount = count ;
807814 maxtime = time ;
@@ -823,9 +830,21 @@ public Counter<T> getTotals(EnumSet<Organization> conflictedOrganizations) {
823830 + "MAXCOUNT: "
824831 + maxCount );
825832 }
826- considerCount = items .getCount (considerItem );
827- considerTime = items .getTime (considerItem );
828- } else if ((time > maxtime ) && (count == maxCount )) {
833+ considerCount = items .getCount (considerItem ); // TODO: == maxCount == count?
834+ considerTime = items .getTime (considerItem ); // TODO: == maxtime == time?
835+ } else if (!votesByTime
836+ && (count == maxCount )
837+ && (participation > considerParticipation )) {
838+ // tell the 'losing' item
839+ if (considerItem != null ) {
840+ annotateTranscript (
841+ "---- Org is not voting for '%s' with %d votes: there is an item '%s' with %d votes" ,
842+ considerItem , considerParticipation , item , participation );
843+ }
844+ considerItem = item ;
845+ } else if ((time > maxtime )
846+ && (count == maxCount )
847+ && (votesByTime || (participation == considerParticipation ))) {
829848 maxtime = time ;
830849 // tell the 'losing' item
831850 if (considerItem != null ) {
@@ -844,10 +863,12 @@ public Counter<T> getTotals(EnumSet<Organization> conflictedOrganizations) {
844863 + new Timestamp (considerTime ));
845864 }
846865 }
866+ considerParticipation = participation ;
847867 }
848868 annotateTranscript (
849869 "--- %s vote is for '%s' with strength %d" ,
850870 org .getDisplayName (), considerItem , considerCount );
871+ // TODO: is this ever not reached if there is a value?
851872 orgToAdd .put (org , considerItem );
852873 totals .add (considerItem , considerCount , considerTime );
853874
@@ -906,21 +927,18 @@ public String toString() {
906927 }
907928
908929 /**
909- * This is now deprecated, since the organization may have multiple votes.
930+ * Get the winning vote for this organization
910931 *
911932 * @param org
912933 * @return
913- * @deprecated
914934 */
915- @ Deprecated
916935 public T getOrgVote (Organization org ) {
917936 return orgToAdd .get (org );
918937 }
919938
920- public T getOrgVoteRaw (Organization orgOfUser ) {
921- return orgToAdd .get (orgOfUser );
922- }
923-
939+ /**
940+ * @return all possible votes from the org, including ones which are disputed.
941+ */
924942 public Map <T , Long > getOrgToVotes (Organization org ) {
925943 Map <T , Long > result = new LinkedHashMap <>();
926944 MaxCounter <T > counter = orgToVotes .get (org );
@@ -1912,17 +1930,36 @@ public EnumSet<Organization> getConflictedOrganizations() {
19121930 * @return
19131931 */
19141932 public T getOrgVote (Organization org ) {
1933+ if (!resolved ) {
1934+ resolveVotes ();
1935+ }
19151936 return organizationToValueAndVote .getOrgVote (org );
19161937 }
19171938
1939+ /**
1940+ * @return a map of all votes for this organization
1941+ */
19181942 public Map <T , Long > getOrgToVotes (Organization org ) {
1943+ if (!resolved ) {
1944+ resolveVotes ();
1945+ }
19191946 return organizationToValueAndVote .getOrgToVotes (org );
19201947 }
19211948
19221949 public Map <String , Long > getNameTime () {
1950+ if (!resolved ) {
1951+ resolveVotes ();
1952+ }
19231953 return organizationToValueAndVote .getNameTime ();
19241954 }
19251955
1956+ /**
1957+ * @return true if this organization's votes are ordered by time (as with TC orgs)
1958+ */
1959+ private static boolean orgVotesByTime (Organization org ) {
1960+ return (org .isTCOrg ());
1961+ }
1962+
19261963 /**
19271964 * Get a String representation of this VoteResolver. This is sent to the client as
19281965 * "voteResolver.raw" and is used only for debugging.
@@ -2172,7 +2209,7 @@ public VoteStatus getStatusForOrganization(Organization orgOfUser) {
21722209 // If the value is provisional, it needs more votes.
21732210 return VoteStatus .provisionalOrWorse ;
21742211 }
2175- T orgVote = organizationToValueAndVote .getOrgVoteRaw (orgOfUser );
2212+ T orgVote = organizationToValueAndVote .getOrgVote (orgOfUser );
21762213 if (!equalsOrgVote (winningValue , orgVote )) {
21772214 // We voted and lost
21782215 return VoteStatus .losing ;
0 commit comments