Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: pkg/dart_messages/bin/message_id.dart

Issue 2916023004: Make pkg/dart_messages strong. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/dart_messages/analysis_options.yaml ('k') | pkg/dart_messages/bin/publish.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:math' as math; 5 import 'dart:math' as math;
6 6
7 import '../lib/shared_messages.dart' as shared_messages; 7 import 'package:dart_messages/shared_messages.dart' as shared_messages;
8 8
9 math.Random random = new math.Random(); 9 math.Random random = new math.Random();
10 10
11 const idLength = 6; 11 const idLength = 6;
12 final $A = "A".codeUnitAt(0); 12 final $A = "A".codeUnitAt(0);
13 final $Z = "Z".codeUnitAt(0); 13 final $Z = "Z".codeUnitAt(0);
14 14
15 String computeId() { 15 String computeId() {
16 List charCodes = []; 16 List<int> charCodes = [];
17 for (int i = 0; i < idLength; i++) { 17 for (int i = 0; i < idLength; i++) {
18 charCodes.add($A + random.nextInt($Z - $A)); 18 charCodes.add($A + random.nextInt($Z - $A));
19 } 19 }
20 return new String.fromCharCodes(charCodes); 20 return new String.fromCharCodes(charCodes);
21 } 21 }
22 22
23 /// Computes a random message ID that hasn't been used before. 23 /// Computes a random message ID that hasn't been used before.
24 void main() { 24 void main() {
25 var usedIds = 25 var usedIds =
26 shared_messages.MESSAGES.values.map((entry) => entry.id).toSet(); 26 shared_messages.MESSAGES.values.map((entry) => entry.id).toSet();
27 27
28 print("${usedIds.length} existing ids"); 28 print("${usedIds.length} existing ids");
29 29
30 var newId; 30 var newId;
31 do { 31 do {
32 newId = computeId(); 32 newId = computeId();
33 } while (usedIds.contains(newId)); 33 } while (usedIds.contains(newId));
34 print("Available id: $newId"); 34 print("Available id: $newId");
35 } 35 }
OLDNEW
« no previous file with comments | « pkg/dart_messages/analysis_options.yaml ('k') | pkg/dart_messages/bin/publish.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698