OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.omnibox; | 5 package org.chromium.chrome.browser.omnibox; |
6 | 6 |
7 import android.text.TextUtils; | 7 import android.text.TextUtils; |
8 | 8 |
9 import com.google.common.annotations.VisibleForTesting; | 9 import com.google.common.annotations.VisibleForTesting; |
10 | 10 |
11 /** | 11 /** |
12 * Container class with information about each omnibox suggestion item. | 12 * Container class with information about each omnibox suggestion item. |
13 */ | 13 */ |
14 @VisibleForTesting | 14 @VisibleForTesting |
15 public class OmniboxSuggestion { | 15 public class OmniboxSuggestion { |
16 | 16 |
17 private final Type mType; | 17 private final Type mType; |
18 private final String mDisplayText; | 18 private final String mDisplayText; |
19 private final String mDescription; | 19 private final String mDescription; |
20 private final String mAnswerContents; | |
21 private final String mAnswerType; | |
20 private final String mFillIntoEdit; | 22 private final String mFillIntoEdit; |
21 private final String mUrl; | 23 private final String mUrl; |
22 private final String mFormattedUrl; | 24 private final String mFormattedUrl; |
23 private final int mRelevance; | 25 private final int mRelevance; |
24 private final int mTransition; | 26 private final int mTransition; |
25 private final boolean mIsStarred; | 27 private final boolean mIsStarred; |
26 private final boolean mIsDeletable; | 28 private final boolean mIsDeletable; |
27 | 29 |
28 /** | 30 /** |
29 * This should be kept in sync with AutocompleteMatch::Type | 31 * This should be kept in sync with AutocompleteMatch::Type |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 81 |
80 /** | 82 /** |
81 * @return The ID of the type used by the native code. | 83 * @return The ID of the type used by the native code. |
82 */ | 84 */ |
83 public int nativeType() { | 85 public int nativeType() { |
84 return mNativeType; | 86 return mNativeType; |
85 } | 87 } |
86 } | 88 } |
87 | 89 |
88 public OmniboxSuggestion(int nativeType, int relevance, int transition, | 90 public OmniboxSuggestion(int nativeType, int relevance, int transition, |
89 String text, String description, String fillIntoEdit, String url, | 91 String text, String description, String answerContents, |
92 String answerType, String fillIntoEdit, String url, | |
90 String formattedUrl, boolean isStarred, boolean isDeletable) { | 93 String formattedUrl, boolean isStarred, boolean isDeletable) { |
91 mType = Type.getTypeFromNativeType(nativeType); | 94 mType = Type.getTypeFromNativeType(nativeType); |
92 mRelevance = relevance; | 95 mRelevance = relevance; |
93 mTransition = transition; | 96 mTransition = transition; |
94 mDisplayText = text; | 97 mDisplayText = text; |
95 mDescription = description; | 98 mDescription = description; |
99 mAnswerContents = answerContents; | |
100 mAnswerType = answerType; | |
96 mFillIntoEdit = TextUtils.isEmpty(fillIntoEdit) ? text : fillIntoEdit; | 101 mFillIntoEdit = TextUtils.isEmpty(fillIntoEdit) ? text : fillIntoEdit; |
97 mUrl = url; | 102 mUrl = url; |
98 mFormattedUrl = formattedUrl; | 103 mFormattedUrl = formattedUrl; |
99 mIsStarred = isStarred; | 104 mIsStarred = isStarred; |
100 mIsDeletable = isDeletable; | 105 mIsDeletable = isDeletable; |
101 } | 106 } |
102 | 107 |
108 public OmniboxSuggestion(int nativeType, int relevance, int transition, | |
109 String text, String description, String fillIntoEdit, String url, | |
110 String formattedUrl, boolean isStarred, boolean isDeletable) { | |
Maria
2014/05/20 01:05:00
Please delete this constructor after after submitt
groby-ooo-7-16
2014/05/20 22:32:14
That was the plan. Filed crbug/375482 to track, ad
| |
111 this(nativeType, relevance, transition, text, description, null, null, f illIntoEdit, url, | |
112 formattedUrl, isStarred, isDeletable); | |
113 } | |
114 | |
103 public Type getType() { | 115 public Type getType() { |
104 return mType; | 116 return mType; |
105 } | 117 } |
106 | 118 |
107 public int getTransition() { | 119 public int getTransition() { |
108 return mTransition; | 120 return mTransition; |
109 } | 121 } |
110 | 122 |
111 public String getDisplayText() { | 123 public String getDisplayText() { |
112 return mDisplayText; | 124 return mDisplayText; |
113 } | 125 } |
114 | 126 |
115 public String getDescription() { | 127 public String getDescription() { |
116 return mDescription; | 128 return mDescription; |
117 } | 129 } |
118 | 130 |
131 public String getAnswerContents() { | |
132 return mAnswerContents; | |
133 } | |
134 | |
135 public String getAnswerType() { | |
136 return mAnswerType; | |
137 } | |
138 | |
119 public String getFillIntoEdit() { | 139 public String getFillIntoEdit() { |
120 return mFillIntoEdit; | 140 return mFillIntoEdit; |
121 } | 141 } |
122 | 142 |
123 public String getUrl() { | 143 public String getUrl() { |
124 return mUrl; | 144 return mUrl; |
125 } | 145 } |
126 | 146 |
127 public String getFormattedUrl() { | 147 public String getFormattedUrl() { |
128 return mFormattedUrl; | 148 return mFormattedUrl; |
(...skipping 14 matching lines...) Expand all Loading... | |
143 return mIsDeletable; | 163 return mIsDeletable; |
144 } | 164 } |
145 | 165 |
146 @Override | 166 @Override |
147 public String toString() { | 167 public String toString() { |
148 return mType + " relevance=" + mRelevance + " \"" + mDisplayText + "\" -> " + mUrl; | 168 return mType + " relevance=" + mRelevance + " \"" + mDisplayText + "\" -> " + mUrl; |
149 } | 169 } |
150 | 170 |
151 @Override | 171 @Override |
152 public int hashCode() { | 172 public int hashCode() { |
153 return 37 * mType.mNativeType + mDisplayText.hashCode() + mFillIntoEdit. hashCode() + | 173 int hash = 37 * mType.mNativeType + mDisplayText.hashCode() + mFillIntoE dit.hashCode() + |
154 (mIsStarred ? 1 : 0) + (mIsDeletable ? 1 : 0); | 174 (mIsStarred ? 1 : 0) + (mIsDeletable ? 1 : 0); |
175 if (mAnswerContents != null) | |
176 hash = hash + mAnswerContents.hashCode(); | |
David Trainor- moved to gerrit
2014/05/20 18:13:56
{} around if block or put on same line.
groby-ooo-7-16
2014/05/20 22:32:14
Done.
| |
177 return hash; | |
155 } | 178 } |
156 | 179 |
157 @Override | 180 @Override |
158 public boolean equals(Object obj) { | 181 public boolean equals(Object obj) { |
159 if (!(obj instanceof OmniboxSuggestion)) { | 182 if (!(obj instanceof OmniboxSuggestion)) { |
160 return false; | 183 return false; |
161 } | 184 } |
162 | 185 |
163 OmniboxSuggestion suggestion = (OmniboxSuggestion) obj; | 186 OmniboxSuggestion suggestion = (OmniboxSuggestion) obj; |
187 | |
188 boolean answersAreEqual = | |
189 (mAnswerContents == null && suggestion.mAnswerContents == null) || | |
190 (mAnswerContents != null && | |
191 suggestion.mAnswerContents != null && | |
192 mAnswerContents.equals(suggestion.mAnswerContents)); | |
164 return mType == suggestion.mType | 193 return mType == suggestion.mType |
165 && mFillIntoEdit.equals(suggestion.mFillIntoEdit) | 194 && mFillIntoEdit.equals(suggestion.mFillIntoEdit) |
166 && mDisplayText.equals(suggestion.mDisplayText) | 195 && mDisplayText.equals(suggestion.mDisplayText) |
196 && answersAreEqual | |
197 && mAnswerContents.equals(suggestion.mAnswerContents) | |
Maria
2014/05/20 01:05:00
this line seems unnecessary since we already check
groby-ooo-7-16
2014/05/20 22:32:14
Forgot to delete - thanks for catching!
| |
167 && mIsStarred == suggestion.mIsStarred | 198 && mIsStarred == suggestion.mIsStarred |
168 && mIsDeletable == suggestion.mIsDeletable; | 199 && mIsDeletable == suggestion.mIsDeletable; |
169 } | 200 } |
170 } | 201 } |
OLD | NEW |