blob: 52c2ec3d4cedd8d320254edcf1645f1a153883b1 [file] [log] [blame]
// Copyright (c) 2020, 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.
import 'package:current_results/src/generated/query.pb.dart' as query_api;
import 'package:current_results/src/generated/result.pb.dart' as api;
class Result {
final String name;
final String configuration;
final String commitHash;
final String result;
final bool flaky;
final String expected;
final Duration time;
Result(this.name, this.configuration, this.commitHash, this.result,
this.flaky, this.expected, this.time);
Result.fromApi(api.Result other)
: this(
unique(other.name),
unique(other.configuration),
unique(other.commitHash),
unique(other.result),
other.flaky,
unique(other.expected),
Duration(milliseconds: other.timeMs));
Result.nameOnly(String name) : this(name, null, null, null, null, null, null);
static final uniqueStrings = <String>{};
static String unique(String string) =>
uniqueStrings.lookup(string) ??
(uniqueStrings.add(string) ? string : string);
query_api.Result toQueryResult() => query_api.Result()
..name = name
..configuration = configuration
..result = result
..timeMs = time.inMilliseconds
..expected = expected
..flaky = flaky;
static query_api.Result toApi(Result result) => result.toQueryResult();
Map<String, dynamic> toMap() => {
'name': name,
'configuration': configuration,
'commitHash': commitHash,
'result': result,
'flaky': flaky,
'expected': expected,
'time': time,
};
@override
String toString() => toMap().toString();
}