@@ -145,59 +145,68 @@ else if(va < vb)
145
145
}
146
146
}
147
147
148
- public class StatListAdapter extends ArrayAdapter <AddressStats >{
148
+ public class StatListAdapter extends ArrayAdapter <AddressStats > {
149
149
private int mLayoutId = 0 ;
150
- private ArrayList <AddressStats > mStats = null ;
150
+ private final ArrayList <AddressStats > mStats ;
151
151
152
- public class StatsHolder {
152
+ public class StatsHolder {
153
153
TextView address ;
154
154
TextView description ;
155
155
}
156
156
157
- public StatListAdapter (int layoutId ){
157
+ public StatListAdapter (int layoutId ) {
158
158
super (Sniffer .this , layoutId );
159
159
160
160
mLayoutId = layoutId ;
161
- mStats = new ArrayList <AddressStats >();
161
+ mStats = new ArrayList <>();
162
162
}
163
163
164
- public AddressStats getStats (String address ){
165
- for (AddressStats stats : mStats ){
166
- if (stats .mAddress .equals (address ))
167
- return stats ;
164
+ public AddressStats getStats (String address ) {
165
+ synchronized (mStats ) {
166
+ for (AddressStats stats : mStats ) {
167
+ if (stats .mAddress .equals (address ))
168
+ return stats ;
169
+ }
168
170
}
169
171
170
172
return null ;
171
173
}
172
174
173
- public synchronized void addStats (AddressStats stats ){
175
+ public synchronized void addStats (AddressStats stats ) {
174
176
boolean found = false ;
175
177
176
- for (AddressStats sstats : mStats ){
177
- if (sstats .mAddress .equals (stats .mAddress )){
178
- sstats .mBytes = stats .mBytes ;
179
- sstats .mBandwidth = stats .mBandwidth ;
180
- sstats .mSampledTime = stats .mSampledTime ;
181
- sstats .mSampledBytes = stats .mSampledBytes ;
178
+ synchronized (mStats ) {
182
179
183
- found = true ;
184
- break ;
180
+ for (AddressStats sstats : mStats ) {
181
+ if (sstats .mAddress .equals (stats .mAddress )) {
182
+ sstats .mBytes = stats .mBytes ;
183
+ sstats .mBandwidth = stats .mBandwidth ;
184
+ sstats .mSampledTime = stats .mSampledTime ;
185
+ sstats .mSampledBytes = stats .mSampledBytes ;
186
+
187
+ found = true ;
188
+ break ;
189
+ }
185
190
}
186
- }
187
191
188
- if (!found )
189
- mStats .add (stats );
192
+ if (!found )
193
+ mStats .add (stats );
190
194
191
- Collections .sort (mStats );
195
+ Collections .sort (mStats );
196
+ }
192
197
}
193
198
194
- private synchronized AddressStats getByPosition (int position ){
195
- return mStats .get (position );
199
+ private synchronized AddressStats getByPosition (int position ) {
200
+ synchronized (mStats ) {
201
+ return mStats .get (position );
202
+ }
196
203
}
197
204
198
205
@ Override
199
206
public int getCount (){
200
- return mStats .size ();
207
+ synchronized (mStats ) {
208
+ return mStats .size ();
209
+ }
201
210
}
202
211
203
212
private String formatSize (long size ){
0 commit comments