[MediaWiki-commits] [Gerrit] apps...wikipedia[master]: Hygiene: replace array with Set for user groups
jenkins-bot has submitted this change and it was merged. Change subject: Hygiene: replace array with Set for user groups .. Hygiene: replace array with Set for user groups Change-Id: I91f1728ce1c958865ca5ca8aa9a8b48eadadbc09 --- M app/src/main/java/org/wikipedia/login/User.java M app/src/main/java/org/wikipedia/server/Protection.java 2 files changed, 9 insertions(+), 16 deletions(-) Approvals: BearND: Looks good to me, approved jenkins-bot: Verified diff --git a/app/src/main/java/org/wikipedia/login/User.java b/app/src/main/java/org/wikipedia/login/User.java index 1bd191c..8316fd0 100644 --- a/app/src/main/java/org/wikipedia/login/User.java +++ b/app/src/main/java/org/wikipedia/login/User.java @@ -84,15 +84,8 @@ return userID; } -public boolean isAllowed(@NonNull String[] allowedGroups) { -for (String allowedGroup: allowedGroups) { -for (String group: groups) { -if (allowedGroup != null && allowedGroup.equals(group)) { -return true; -} -} -} -return false; +public boolean isAllowed(@NonNull Set allowedGroups) { +return !allowedGroups.isEmpty() && !Collections.disjoint(allowedGroups, groups); } @NonNull diff --git a/app/src/main/java/org/wikipedia/server/Protection.java b/app/src/main/java/org/wikipedia/server/Protection.java index 90fdedf..3612a08 100644 --- a/app/src/main/java/org/wikipedia/server/Protection.java +++ b/app/src/main/java/org/wikipedia/server/Protection.java @@ -3,21 +3,21 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import java.util.Collections; +import java.util.Set; + /** Protection settings for a page */ public class Protection { -@SuppressWarnings("MismatchedReadAndWriteOfArray") private String[] edit = new String[]{}; +@SuppressWarnings("MismatchedReadAndWriteOfArray") private Set edit = Collections.emptySet(); // TODO should send them all, but callers need to be updated, too, (future patch) @Nullable public String getFirstAllowedEditorRole() { -if (edit.length > 0) { -return edit[0]; -} -return null; +return edit.isEmpty() ? null : edit.iterator().next(); } @NonNull -public String[] getEditRoles() { -return edit.clone(); +public Set getEditRoles() { +return Collections.unmodifiableSet(edit); } } \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/316384 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I91f1728ce1c958865ca5ca8aa9a8b48eadadbc09 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Niedzielski Gerrit-Reviewer: BearND Gerrit-Reviewer: Brion VIBBER Gerrit-Reviewer: Dbrant Gerrit-Reviewer: Mholloway Gerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] apps...wikipedia[master]: Hygiene: replace array with Set for user groups
Niedzielski has uploaded a new change for review. https://gerrit.wikimedia.org/r/316384 Change subject: Hygiene: replace array with Set for user groups .. Hygiene: replace array with Set for user groups Change-Id: I91f1728ce1c958865ca5ca8aa9a8b48eadadbc09 --- M app/src/main/java/org/wikipedia/login/User.java M app/src/main/java/org/wikipedia/server/Protection.java 2 files changed, 9 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/84/316384/1 diff --git a/app/src/main/java/org/wikipedia/login/User.java b/app/src/main/java/org/wikipedia/login/User.java index 1bd191c..8316fd0 100644 --- a/app/src/main/java/org/wikipedia/login/User.java +++ b/app/src/main/java/org/wikipedia/login/User.java @@ -84,15 +84,8 @@ return userID; } -public boolean isAllowed(@NonNull String[] allowedGroups) { -for (String allowedGroup: allowedGroups) { -for (String group: groups) { -if (allowedGroup != null && allowedGroup.equals(group)) { -return true; -} -} -} -return false; +public boolean isAllowed(@NonNull Set allowedGroups) { +return !allowedGroups.isEmpty() && !Collections.disjoint(allowedGroups, groups); } @NonNull diff --git a/app/src/main/java/org/wikipedia/server/Protection.java b/app/src/main/java/org/wikipedia/server/Protection.java index 90fdedf..3612a08 100644 --- a/app/src/main/java/org/wikipedia/server/Protection.java +++ b/app/src/main/java/org/wikipedia/server/Protection.java @@ -3,21 +3,21 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import java.util.Collections; +import java.util.Set; + /** Protection settings for a page */ public class Protection { -@SuppressWarnings("MismatchedReadAndWriteOfArray") private String[] edit = new String[]{}; +@SuppressWarnings("MismatchedReadAndWriteOfArray") private Set edit = Collections.emptySet(); // TODO should send them all, but callers need to be updated, too, (future patch) @Nullable public String getFirstAllowedEditorRole() { -if (edit.length > 0) { -return edit[0]; -} -return null; +return edit.isEmpty() ? null : edit.iterator().next(); } @NonNull -public String[] getEditRoles() { -return edit.clone(); +public Set getEditRoles() { +return Collections.unmodifiableSet(edit); } } \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/316384 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I91f1728ce1c958865ca5ca8aa9a8b48eadadbc09 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Niedzielski ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits