Line data Source code
1 : // Copyright (c) 2016, 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 : import 'dart:collection'; 6 : 7 : import 'equality.dart'; 8 : import 'wrappers.dart'; 9 : 10 : /// A [Set] whose key equality is determined by an [Equality] object. 11 : class EqualitySet<E> extends DelegatingSet<E> { 12 : /// Creates a set with equality based on [equality]. 13 0 : EqualitySet(Equality<E> equality) 14 0 : : super(LinkedHashSet( 15 0 : equals: equality.equals, 16 0 : hashCode: equality.hash, 17 0 : isValidKey: equality.isValidKey)); 18 : 19 : /// Creates a set with equality based on [equality] that contains all 20 : /// elements in [other]. 21 : /// 22 : /// If [other] has multiple values that are equivalent according to 23 : /// [equality], the first one reached during iteration takes precedence. 24 0 : EqualitySet.from(Equality<E> equality, Iterable<E> other) 25 0 : : super(LinkedHashSet( 26 0 : equals: equality.equals, 27 0 : hashCode: equality.hash, 28 0 : isValidKey: equality.isValidKey)) { 29 0 : addAll(other); 30 : } 31 : }