jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/334739 )
Change subject: Hygiene: reorder PageTitle members and add annotations
......................................................................
Hygiene: reorder PageTitle members and add annotations
Reorder member variables and methods according to exposure and add a
couple missing annotations
Change-Id: Ib437ac91c2115b9dfc939a58d17776dd130b76e6
---
M app/src/main/java/org/wikipedia/page/PageTitle.java
1 file changed, 92 insertions(+), 98 deletions(-)
Approvals:
jenkins-bot: Verified
Mholloway: Looks good to me, approved
diff --git a/app/src/main/java/org/wikipedia/page/PageTitle.java
b/app/src/main/java/org/wikipedia/page/PageTitle.java
index 00754f6..caa5ab0 100644
--- a/app/src/main/java/org/wikipedia/page/PageTitle.java
+++ b/app/src/main/java/org/wikipedia/page/PageTitle.java
@@ -35,6 +35,19 @@
public class PageTitle implements Parcelable {
private static final String LANGUAGE_CODE_KEY = "languageCode";
+ public static final Parcelable.Creator<PageTitle> CREATOR
+ = new Parcelable.Creator<PageTitle>() {
+ @Override
+ public PageTitle createFromParcel(Parcel in) {
+ return new PageTitle(in);
+ }
+
+ @Override
+ public PageTitle[] newArray(int size) {
+ return new PageTitle[size];
+ }
+ };
+
/**
* The localised namespace of the page as a string, or null if the page is
in mainspace.
*
@@ -142,6 +155,26 @@
this.properties = properties;
}
+ public PageTitle(JSONObject json) {
+ this.namespace = json.optString("namespace", null);
+ this.text = json.optString("text", null);
+ this.fragment = json.optString("fragment", null);
+ if (json.has("site")) {
+ if (json.has(LANGUAGE_CODE_KEY)) {
+ wiki = new WikiSite(json.optString("site"),
json.optString(LANGUAGE_CODE_KEY));
+ } else {
+ // TODO: remove in September 2016.
+ wiki = new WikiSite(json.optString("site"));
+ }
+ } else {
+ L.logRemoteErrorIfProd(new RemoteLogException("wiki is
null").put("json", json.toString()));
+ wiki = WikipediaApp.getInstance().getWikiSite();
+ }
+ this.properties = json.has("properties") ? new
PageProperties(json.optJSONObject("properties")) : null;
+ this.thumbUrl = json.optString("thumbUrl", null);
+ this.description = json.optString("description", null);
+ }
+
@Nullable
public String getNamespace() {
return namespace;
@@ -160,7 +193,7 @@
return wiki;
}
- public String getText() {
+ @NonNull public String getText() {
return text.replace(" ", "_");
}
@@ -176,8 +209,7 @@
this.thumbUrl = thumbUrl;
}
- @Nullable
- public String getDescription() {
+ @Nullable public String getDescription() {
return description;
}
@@ -185,7 +217,7 @@
this.description = description;
}
- public String getDisplayText() {
+ @NonNull public String getDisplayText() {
return getPrefixedText().replace("_", " ");
}
@@ -214,20 +246,6 @@
return md5string(toIdentifierJSON().toString());
}
- /** Please keep the ID stable. */
- private JSONObject toIdentifierJSON() {
- try {
- JSONObject json = new JSONObject();
- json.put("namespace", getNamespace());
- json.put("text", getText());
- json.put("fragment", getFragment());
- json.put("site", wiki.authority());
- return json;
- } catch (JSONException e) {
- throw new RuntimeException(e);
- }
- }
-
public JSONObject toJSON() {
try {
JSONObject json = toIdentifierJSON();
@@ -239,40 +257,6 @@
json.put("description", getDescription());
return json;
} catch (JSONException e) {
- throw new RuntimeException(e);
- }
- }
-
- public PageTitle(JSONObject json) {
- this.namespace = json.optString("namespace", null);
- this.text = json.optString("text", null);
- this.fragment = json.optString("fragment", null);
- if (json.has("site")) {
- if (json.has(LANGUAGE_CODE_KEY)) {
- wiki = new WikiSite(json.optString("site"),
json.optString(LANGUAGE_CODE_KEY));
- } else {
- // TODO: remove in September 2016.
- wiki = new WikiSite(json.optString("site"));
- }
- } else {
- L.logRemoteErrorIfProd(new RemoteLogException("wiki is
null").put("json", json.toString()));
- wiki = WikipediaApp.getInstance().getWikiSite();
- }
- this.properties = json.has("properties") ? new
PageProperties(json.optJSONObject("properties")) : null;
- this.thumbUrl = json.optString("thumbUrl", null);
- this.description = json.optString("description", null);
- }
-
- private String getUriForDomain(String domain) {
- try {
- return String.format(
- "%1$s://%2$s/wiki/%3$s%4$s",
- getWikiSite().scheme(),
- domain,
- URLEncoder.encode(getPrefixedText(), "utf-8"),
- (this.fragment != null && this.fragment.length() > 0) ?
("#" + this.fragment) : ""
- );
- } catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
@@ -330,23 +314,67 @@
return namespace().talk();
}
- @Override
- public int describeContents() {
+ @Override public void writeToParcel(Parcel parcel, int flags) {
+ parcel.writeString(namespace);
+ parcel.writeString(text);
+ parcel.writeString(fragment);
+ parcel.writeParcelable(wiki, flags);
+ parcel.writeParcelable(properties, flags);
+ parcel.writeString(thumbUrl);
+ parcel.writeString(description);
+ }
+
+ @Override public boolean equals(Object o) {
+ if (!(o instanceof PageTitle)) {
+ return false;
+ }
+
+ PageTitle other = (PageTitle)o;
+ // Not using namespace directly since that can be null
+ return other.getPrefixedText().equals(getPrefixedText()) &&
other.wiki.equals(wiki);
+ }
+
+ @Override public int hashCode() {
+ int result = getPrefixedText().hashCode();
+ result = 31 * result + wiki.hashCode();
+ return result;
+ }
+
+ @Override public String toString() {
+ return getPrefixedText();
+ }
+
+ @Override public int describeContents() {
return 0;
}
- public static final Parcelable.Creator<PageTitle> CREATOR
- = new Parcelable.Creator<PageTitle>() {
- @Override
- public PageTitle createFromParcel(Parcel in) {
- return new PageTitle(in);
+ /** Please keep the ID stable. */
+ private JSONObject toIdentifierJSON() {
+ try {
+ JSONObject json = new JSONObject();
+ json.put("namespace", getNamespace());
+ json.put("text", getText());
+ json.put("fragment", getFragment());
+ json.put("site", wiki.authority());
+ return json;
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
}
+ }
- @Override
- public PageTitle[] newArray(int size) {
- return new PageTitle[size];
+ private String getUriForDomain(String domain) {
+ try {
+ return String.format(
+ "%1$s://%2$s/wiki/%3$s%4$s",
+ getWikiSite().scheme(),
+ domain,
+ URLEncoder.encode(getPrefixedText(), "utf-8"),
+ (this.fragment != null && this.fragment.length() > 0) ?
("#" + this.fragment) : ""
+ );
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
}
- };
+ }
private PageTitle(Parcel in) {
namespace = in.readString();
@@ -357,38 +385,4 @@
thumbUrl = in.readString();
description = in.readString();
}
-
- @Override
- public void writeToParcel(Parcel parcel, int flags) {
- parcel.writeString(namespace);
- parcel.writeString(text);
- parcel.writeString(fragment);
- parcel.writeParcelable(wiki, flags);
- parcel.writeParcelable(properties, flags);
- parcel.writeString(thumbUrl);
- parcel.writeString(description);
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof PageTitle)) {
- return false;
- }
-
- PageTitle other = (PageTitle)o;
- // Not using namespace directly since that can be null
- return other.getPrefixedText().equals(getPrefixedText()) &&
other.wiki.equals(wiki);
- }
-
- @Override
- public int hashCode() {
- int result = getPrefixedText().hashCode();
- result = 31 * result + wiki.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return getPrefixedText();
- }
-}
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/334739
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib437ac91c2115b9dfc939a58d17776dd130b76e6
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits