Skip to content

Commit

Permalink
CLDR-16369 Fix some comments and warnings in VoteResolver (#3348)
Browse files Browse the repository at this point in the history
-The comment for VoteResolver.VoteStatus.provisionalOrWorse was incorrect

-The comment (see class def for null user) was unhelpful

-The reference to ticket/10973 was obsolete

-Fix a few warnings from IntelliJ
  • Loading branch information
btangmu authored Oct 18, 2023
1 parent ed61527 commit 032935e
Showing 1 changed file with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public String getTranscript() {
* @param fmt
* @param args
*/
private final void annotateTranscript(String fmt, Object... args) {
private void annotateTranscript(String fmt, Object... args) {
if (DEBUG) {
System.out.println("Transcript: " + String.format(fmt, args));
}
Expand All @@ -108,15 +108,17 @@ private final void annotateTranscript(String fmt, Object... args) {
* <p>Status corresponds to icons as follows: A checkmark means it’s approved and is slated to
* be used. A cross means it’s a missing value. Green/orange check: The item has enough votes to
* be used in CLDR. Red/orange/black X: The item does not have enough votes to be used in CLDR,
* by most implementations (or is completely missing). Reference:
* http://cldr.unicode.org/translation/getting-started/guide
* by most implementations (or is completely missing). Reference: <a
* href="https://cldr.unicode.org/translation/getting-started/guide">guide</a>
*
* <p>When the item is inherited, i.e., winningValue is INHERITANCE_MARKER (↑↑↑), then
* orange/red X are replaced by orange/red up-arrow. That change is made only on the client.
*
* <p>Status.approved: green check Status.contributed: orange check Status.provisional: orange X
* (or orange up-arrow if inherited) Status.unconfirmed: red X (or red up-arrow if inherited
* Status.missing: black X
*
* <p>Not to be confused with VoteResolver.VoteStatus
*/
public enum Status {
missing,
Expand Down Expand Up @@ -296,10 +298,10 @@ public boolean canVoteWithCount(Organization org, int withVotes) {
/**
* Get the ordered immutable set of different vote counts a user of this level can vote with
*
* @param org the given organization
* @param ignoredOrg the given organization
* @return the set, or null if the user has no choice of vote count
*/
public ImmutableSet<Integer> getVoteCountMenu(Organization org) {
public ImmutableSet<Integer> getVoteCountMenu(Organization ignoredOrg) {
// Right now, the organization does not affect the menu.
// but update the API to future proof.
return voteCountMenu;
Expand Down Expand Up @@ -434,30 +436,31 @@ public boolean canDeleteUsers() {
}
}

/** See VoteResolver getStatusForOrganization to see how this is computed. */
/**
* See getStatusForOrganization to see how this is computed.
*
* <p>Not to be confused with VoteResolver.Status
*/
public enum VoteStatus {
/**
* The value for the path is either contributed or approved, and the user's organization
* didn't vote. (see class def for null user)
* didn't vote.
*/
ok_novotes,

/**
* The value for the path is either contributed or approved, and the user's organization
* chose the winning value. (see class def for null user)
* chose the winning value.
*/
ok,

/**
* The user's organization chose the winning value for the path, but that value is neither
* contributed nor approved. (see class def for null user)
*/
/** The winning value is neither contributed nor approved. */
provisionalOrWorse,

/**
* The user's organization's choice is not winning. There may be insufficient votes to
* overcome a previously approved value, or other organizations may be voting against it.
* (see class def for null user)
* The user's organization's choice is not winning, and the winning value is either
* contributed or approved. There may be insufficient votes to overcome a previously
* approved value, or other organizations may be voting against it.
*/
losing,

Expand Down Expand Up @@ -589,9 +592,11 @@ private class OrganizationToValueAndVote<T> {
/** The result of {@link #getTotals(EnumSet)} */
private final Counter<T> totals = new Counter<>(true);

private Map<String, Long> nameTime = new LinkedHashMap<>();
// map an organization to what it voted for.
private final Map<String, Long> nameTime = new LinkedHashMap<>();

/** map an organization to the value it voted for. */
private final Map<Organization, T> orgToAdd = new EnumMap<>(Organization.class);

private T baileyValue;
private boolean baileySet; // was the bailey value set

Expand Down Expand Up @@ -654,7 +659,7 @@ private void addInternal(T value, final VoterInfo info, final int votes, Date ti
if (DROP_HARD_INHERITANCE) {
value = changeBaileyToInheritance(value);
}
/** All votes are added here, even if they will later lose an intra-org dispute. */
/* All votes are added here, even if they will later lose an intra-org dispute. */
allVotesIncludingIntraOrgDispute.add(value, votes, time.getTime());
nameTime.put(info.getName(), time.getTime());
if (DEBUG) {
Expand Down Expand Up @@ -1331,8 +1336,7 @@ private HashMap<T, Long> makeVoteCountMap(Set<T> sortedValues) {
*/
private boolean combineInheritanceWithBaileyForVoting(
Set<T> sortedValues, HashMap<T, Long> voteCount) {
if (organizationToValueAndVote == null
|| organizationToValueAndVote.baileySet == false
if (organizationToValueAndVote.baileySet == false
|| organizationToValueAndVote.baileyValue == null) {
return false;
}
Expand Down Expand Up @@ -1380,8 +1384,7 @@ private void reallyCombineInheritanceWithBailey(
* Sort again
*/
List<T> list = new ArrayList<>(sortedValues);
Collections.sort(
list,
list.sort(
(v1, v2) -> {
long c1 = voteCount.get(v1);
long c2 = voteCount.get(v2);
Expand Down Expand Up @@ -1412,9 +1415,6 @@ private void reallyCombineInheritanceWithBailey(
*
* <p>http://unicode.org/repos/cldr/tags/latest/common/annotations/
*
* <p>This function is where the essential algorithm needs to be implemented for
* http://unicode.org/cldr/trac/ticket/10973
*
* @param sortedValues the set of sorted values
* @param voteCount the hash giving the vote count for each value in sortedValues
* <p>public for unit testing, see TestAnnotationVotes.java
Expand Down

0 comments on commit 032935e

Please sign in to comment.