blob: ea09f60e5be654116006136dad0873a613b4f2bf [file] [log] [blame]
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of observable.src.records;
/// A [ChangeRecord] that denotes adding or removing values from a [Set].
class SetChangeRecord<E> implements ChangeRecord {
/// Whether this is a removal operation.
final bool isRemove;
/// Element added or removed in the operation.
final E element;
const SetChangeRecord.add(this.element) : isRemove = false;
const SetChangeRecord.remove(this.element) : isRemove = true;
/// Whether this is an add operation.
bool get isAdd => !isRemove;
/// Apply the change operation to [set].
void apply(Set<E> set) {
if (isRemove) {
} else {
bool operator ==(Object o) =>
o is SetChangeRecord<E> && element == o.element && isRemove == o.isRemove;
int get hashCode => quiver.hash2(element, isRemove);
String toString() {
return '#<SetChangeRecord ${isRemove ? 'remove' : 'add'} $element>';