blob: ed21c809858a6884f0af6a815a45b87869266877 [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.
/// @assertion LinkedHashSet({bool equals(E e1, E e2), int hashCode(E e),
/// bool isValidKey(potentialKey)})
/// If the [equals] or [hashCode] methods won't work on all objects, but only on
/// some instances of [E], the [isValidKey] predicate can be used to restrict the
/// keys that the functions are applied to. Any key for which [isValidKey]
/// returns false is automatically assumed to not be in the set when asking
/// [contains].
/// @description Checks that [isValidKey] is ignored if [equals] and [hashCode]
/// are omitted
/// @author sgrekhov@unipro.ru
import "../../../Utils/expect.dart";
import "dart:collection";
bool isValidKey(var potentialKey) => potentialKey < 100;
main() {
LinkedHashSet<int> set = new LinkedHashSet<int>(isValidKey: isValidKey);
set.add(1);
Expect.isTrue(set.contains(1));
set.add(101);
Expect.isFalse(set.contains(101));
}