OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of protobuf; | 5 part of protobuf; |
6 | 6 |
7 class PbList<E> extends Object with ListMixin<E> implements List<E> { | 7 class PbList<E> extends Object with ListMixin<E> implements List<E> { |
8 | 8 |
9 PbList() : _wrappedList = <E>[]; | 9 PbList() : _wrappedList = <E>[]; |
10 | 10 |
11 PbList.from(List from) : _wrappedList = new List<E>.from(from); | 11 PbList.from(List from) : _wrappedList = new List<E>.from(from); |
12 | 12 |
13 bool operator ==(other) => | 13 bool operator ==(other) => |
14 (other is PbList) && _areListsEqual(other, this); | 14 (other is PbList) && _areListsEqual(other, this); |
15 | 15 |
16 int get hashCode => _wrappedList.hashCode; | 16 int get hashCode { |
| 17 int hash = 0; |
| 18 _wrappedList.forEach((value) { |
| 19 hash = (hash + value.hashCode) & 0x3fffffff; |
| 20 hash = (hash + hash << 10) & 0x3fffffff; |
| 21 hash = (hash ^ hash >> 6) & 0x3fffffff; |
| 22 }); |
| 23 hash = (hash + hash << 3) & 0x3fffffff; |
| 24 hash = (hash ^ hash >> 11) & 0x3fffffff; |
| 25 hash = (hash + hash << 15) & 0x3fffffff; |
| 26 return hash; |
| 27 } |
17 | 28 |
18 /** | 29 /** |
19 * Returns an [Iterator] for the list. | 30 * Returns an [Iterator] for the list. |
20 */ | 31 */ |
21 Iterator<E> get iterator => _wrappedList.iterator; | 32 Iterator<E> get iterator => _wrappedList.iterator; |
22 | 33 |
23 /** | 34 /** |
24 * Returns the element at the given [index] in the list or throws | 35 * Returns the element at the given [index] in the list or throws |
25 * an [IndexOutOfRangeException] if [index] is out of bounds. | 36 * an [IndexOutOfRangeException] if [index] is out of bounds. |
26 */ | 37 */ |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 * [:-3.4E38, 3.4E38:], i.e., with the IEEE single-precision range. | 200 * [:-3.4E38, 3.4E38:], i.e., with the IEEE single-precision range. |
190 */ | 201 */ |
191 class PbFloatList extends PbList<double> { | 202 class PbFloatList extends PbList<double> { |
192 void _validateElement(double val) { | 203 void _validateElement(double val) { |
193 if (!_isFloat32(val)) { | 204 if (!_isFloat32(val)) { |
194 throw new ArgumentError('Illegal to add value (${val}):' | 205 throw new ArgumentError('Illegal to add value (${val}):' |
195 ' out of range for float'); | 206 ' out of range for float'); |
196 } | 207 } |
197 } | 208 } |
198 } | 209 } |
OLD | NEW |