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

Side by Side Diff: samples/chat/chat_server_lib.dart

Issue 8619008: Initializing formals can't be optional parameters (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #library("chat_server"); 5 #library("chat_server");
6 #import("http.dart"); 6 #import("http.dart");
7 #import("../../client/json/dart_json.dart"); 7 #import("../../client/json/dart_json.dart");
8 8
9 typedef void RequestHandler(HTTPRequest request, HTTPResponse response); 9 typedef void RequestHandler(HTTPRequest request, HTTPResponse response);
10 10
11 class ChatServer extends IsolatedServer { 11 class ChatServer extends IsolatedServer {
12 ChatServer() : super() { 12 ChatServer() : super() {
13 addHandler("/", 13 addHandler("/",
14 (HTTPRequest request, HTTPResponse response) 14 (HTTPRequest request, HTTPResponse response)
15 => redirectPageHandler(request, response, "dart_client/index.html ")); 15 => redirectPageHandler(request, response, "dart_client/index.html "));
16 addHandler("/js_client/index.html", 16 addHandler("/js_client/index.html",
17 (HTTPRequest request, HTTPResponse response) => fileHandler(reque st, response)); 17 (HTTPRequest request, HTTPResponse response) => fileHandler(reque st, response));
18 addHandler("/js_client/code.js", 18 addHandler("/js_client/code.js",
19 (HTTPRequest request, HTTPResponse response) => fileHandler(reque st, response)); 19 (HTTPRequest request, HTTPResponse response) => fileHandler(reque st, response));
20 addHandler("/dart_client/index.html", 20 addHandler("/dart_client/index.html",
21 (HTTPRequest request, HTTPResponse response) => fileHandler(reque st, response)); 21 (HTTPRequest request, HTTPResponse response) => fileHandler(reque st, response));
22 addHandler("/out/dart_client/chat.dart.app.js", 22 addHandler("/out/dart_client/chat.dart.app.js",
23 (HTTPRequest request, HTTPResponse response) => fileHandler(reque st, response)); 23 (HTTPRequest request, HTTPResponse response) => fileHandler(reque st, response));
24 addHandler("/favicon.ico", 24 addHandler("/favicon.ico",
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 649
650 // Calculate the rate of events over a given time range. The time 650 // Calculate the rate of events over a given time range. The time
651 // range is split over a number of buckets where each bucket collects 651 // range is split over a number of buckets where each bucket collects
652 // the number of events happening in that time sub-range. The first 652 // the number of events happening in that time sub-range. The first
653 // constructor arument specifies the time range in milliseconds. The 653 // constructor arument specifies the time range in milliseconds. The
654 // buckets are in the list _buckets organized at a circular buffer 654 // buckets are in the list _buckets organized at a circular buffer
655 // with _currentBucket marking the bucket where an event was last 655 // with _currentBucket marking the bucket where an event was last
656 // recorded. A current sum of the content of all buckets except the 656 // recorded. A current sum of the content of all buckets except the
657 // one pointed a by _currentBucket is kept in _sum. 657 // one pointed a by _currentBucket is kept in _sum.
658 class Rate { 658 class Rate {
659 Rate([int this._timeRange = 1000, int buckets = 10]) 659 Rate([int timeRange = 1000, int buckets = 10])
660 : _buckets = new List(buckets + 1), // Current bucket is not in the sum. 660 : _timeRange = timeRange,
661 _buckets = new List(buckets + 1), // Current bucket is not in the sum.
661 _currentBucket = 0, 662 _currentBucket = 0,
662 _currentBucketTime = new Date.now().value, 663 _currentBucketTime = new Date.now().value,
663 _sum = 0 { 664 _sum = 0 {
664 _bucketTimeRange = (_timeRange / buckets).toInt(); 665 _bucketTimeRange = (_timeRange / buckets).toInt();
665 for (int i = 0; i < _buckets.length; i++) { 666 for (int i = 0; i < _buckets.length; i++) {
666 _buckets[i] = 0; 667 _buckets[i] = 0;
667 } 668 }
668 } 669 }
669 670
670 // Record the specified number of events. 671 // Record the specified number of events.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 } 704 }
704 } 705 }
705 706
706 int _timeRange; 707 int _timeRange;
707 List<int> _buckets; 708 List<int> _buckets;
708 int _currentBucket; 709 int _currentBucket;
709 int _currentBucketTime; 710 int _currentBucketTime;
710 num _bucketTimeRange; 711 num _bucketTimeRange;
711 int _sum; 712 int _sum;
712 } 713 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698