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

Side by Side Diff: 2-1-starter/lib/server/piratesapi.dart

Issue 1056193003: Rename methods to better match new terminology and get rid of json data file. (Closed) Base URL: https://github.com/dart-lang/one-hour-codelab.git@server2
Patch Set: Created 5 years, 8 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 | « 2-1-starter/lib/server/piratenames.json ('k') | 2-2-simple/lib/common/messages.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 library pirate.server; 5 library pirate.server;
6 6
7 import 'dart:convert' show JSON;
8 import 'dart:io';
9 import 'package:rpc/rpc.dart'; 7 import 'package:rpc/rpc.dart';
10 8
11 import '../common/messages.dart'; 9 import '../common/messages.dart';
12 import '../common/utils.dart'; 10 import '../common/utils.dart';
13 11
14 class PiratesApi { 12 class PiratesApi {
15 final Map<int, Pirate> _alivePirates = {}; 13 final Map<int, Pirate> _pirateCrew = {};
16 PirateShanghaier _shanghaier; 14 final PirateShanghaier _shanghaier = new PirateShanghaier(properPirateNames);
17 Map<String, List<String>> _properPirates;
18
19 PiratesApi() {
20 var namesFile = new File(
21 Platform.script.resolve('../lib/server/piratenames.json').toFilePath());
22 _properPirates = JSON.decode(namesFile.readAsStringSync());
23 _shanghaier = new PirateShanghaier(_properPirates);
24 }
25 15
26 List<Pirate> listPirates() { 16 List<Pirate> listPirates() {
27 return _alivePirates.values.toList(); 17 return _pirateCrew.values.toList();
28 } 18 }
29 19
30 Pirate shanghaiAPirate() { 20 Pirate shanghaiAPirate() {
31 var pirate = _shanghaier.shanghaiAPirate(); 21 var pirate = _shanghaier.shanghaiAPirate();
32 if (pirate == null) { 22 if (pirate == null) {
33 throw new InternalServerError('Ran out of pirates!'); 23 throw new InternalServerError('Ran out of pirates!');
34 } 24 }
35 _alivePirates[pirate.toString().hashCode] = pirate; 25 _pirateCrew[pirate.toString().hashCode] = pirate;
36 return pirate; 26 return pirate;
37 } 27 }
38 } 28 }
OLDNEW
« no previous file with comments | « 2-1-starter/lib/server/piratenames.json ('k') | 2-2-simple/lib/common/messages.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698