Commit 246821de authored by Marcin Wiacek's avatar Marcin Wiacek Committed by Commit Bot

Migrate DetailsField to @IntDef

@IntDef annotation are preferred way for declaring set of int values.

1. they need less space in APK than enum, see
https://developer.android.com/topic/performance/reduce-apk-size#remove-enums
2. they give more control over allowed values than "static final" values

Main goal of patch is replacing DetailsField enum to the style common with other @IntDef:

1. with @IntDef first, @Retention second
   and related @interface third
2. with values inside @interface
3. with @Retention(RetentionPolicy.SOURCE)
4. without "static final" in the @interface


Change-Id: I4e551520fd51c23a60f5d9d561fb23f6f0e93909
Reviewed-on: https://chromium-review.googlesource.com/c/1350901Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Commit-Queue: Marcin Wiącek <marcin@mwiacek.com>
Cr-Commit-Position: refs/heads/master@{#611498}
parent 39536eb8
......@@ -4,10 +4,13 @@
package org.chromium.chrome.browser.autofill_assistant;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import org.json.JSONObject;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
......@@ -22,7 +25,17 @@ import java.util.Set;
* Java side equivalent of autofill_assistant::DetailsProto.
*/
class Details {
enum DetailsField { TITLE, URL, DATE, DESCRIPTION, MID, IS_FINAL }
@IntDef({DetailsField.TITLE, DetailsField.URL, DetailsField.DATE, DetailsField.DESCRIPTION,
DetailsField.MID, DetailsField.IS_FINAL})
@Retention(RetentionPolicy.SOURCE)
public @interface DetailsField {
int TITLE = 0;
int URL = 1;
int DATE = 2;
int DESCRIPTION = 3;
int MID = 4;
int IS_FINAL = 5;
}
private final String mTitle;
private final String mUrl;
......@@ -32,7 +45,7 @@ class Details {
private final String mMid;
private final boolean mIsFinal;
/** Contains the fields that have changed when merging with other Details object. */
private final Set<DetailsField> mFieldsChanged;
private final Set<Integer> mFieldsChanged;
// NOTE: When adding a new field, update the isEmpty and toJSONObject methods.
static final Details EMPTY_DETAILS =
......@@ -41,7 +54,7 @@ class Details {
private static final String RFC_3339_FORMAT_WITHOUT_TIMEZONE = "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
Details(String title, String url, @Nullable Date date, String description, String mId,
boolean isFinal, Set<DetailsField> fieldsChanged) {
boolean isFinal, Set<Integer> fieldsChanged) {
this.mTitle = title;
this.mUrl = url;
this.mDate = date;
......@@ -91,7 +104,7 @@ class Details {
return mIsFinal;
}
Set<DetailsField> getFieldsChanged() {
Set<Integer> getFieldsChanged() {
return mFieldsChanged;
}
......@@ -154,7 +167,7 @@ class Details {
Collections.emptySet());
}
Set<DetailsField> changedFields = new HashSet<>();
Set<Integer> changedFields = new HashSet<>();
String title = oldDetails.getTitle();
String mId = oldDetails.getMid();
......@@ -186,4 +199,4 @@ class Details {
boolean isFinal = newDetails.isFinal();
return new Details(title, url, date, description, mId, isFinal, changedFields);
}
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment