| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * An object containing a (row, column) reference. | |
| 7 * | |
| 8 * Objects of this class are immutable: they do not change after creation. | |
| 9 */ | |
| 10 class RowCol implements Hashable { | |
| 11 | |
| 12 static int hashOneValue(int val) { | |
| 13 final int fnvPrime = 0x01000193; | |
| 14 int output = fnvPrime; | |
| 15 int octet1 = val & 0xff; | |
| 16 output ^= octet1; | |
| 17 output *= fnvPrime; | |
| 18 int octet2 = (val >> 8) & 0xff; | |
| 19 output ^= octet2; | |
| 20 output *= fnvPrime; | |
| 21 int octet3 = (val >> 16) & 0xff; | |
| 22 output ^= octet3; | |
| 23 | |
| 24 return output; | |
| 25 } | |
| 26 | |
| 27 final int _col; | |
| 28 final int _row; | |
| 29 | |
| 30 int get col() => _col; | |
| 31 | |
| 32 int get row() => _row; | |
| 33 | |
| 34 RowCol(this._row, this._col) { } | |
| 35 | |
| 36 bool operator ==(RowCol other) { | |
| 37 if (!(other is RowCol)) { | |
| 38 return false; | |
| 39 } | |
| 40 return other._row == _row && other._col == _col; | |
| 41 } | |
| 42 | |
| 43 RowCol operator +(RowCol other) => new RowCol(_row + other._row, _col + other.
_col); | |
| 44 | |
| 45 int hashCode() => (51 + hashOneValue(_row)) * 51 + hashOneValue(_col); | |
| 46 | |
| 47 bool isValidCell() => _row > 0 && _col > 0; | |
| 48 | |
| 49 String toA1String() => "${StringUtils.columnString(_col)}${_row}"; | |
| 50 | |
| 51 String toString() => "R${_row}C${_col}"; | |
| 52 | |
| 53 RowCol translate(int deltaRow, int deltaCol) => new RowCol(_row + deltaRow, _c
ol + deltaCol); | |
| 54 } | |
| 55 | |
| OLD | NEW |