31 lines
628 B
JavaScript
Raw Normal View History

import {MapWrapper, Map} from 'facade/collection';
import {FIELD, int, isPresent} from 'facade/lang';
var _allKeys = MapWrapper.create();
var _id:int = 0;
export class Key {
2014-10-12 17:03:22 -04:00
@FIELD('final token')
@FIELD('final id:int')
constructor(token, id:int) {
this.token = token;
this.id = id;
}
static get(token) {
2014-10-10 16:31:27 -04:00
if (token instanceof Key) return token;
if (MapWrapper.contains(_allKeys, token)) {
return MapWrapper.get(_allKeys, token);
}
var newKey = new Key(token, ++_id);
MapWrapper.set(_allKeys, token, newKey);
return newKey;
}
static numberOfKeys() {
return _id;
}
2014-10-09 12:09:50 -04:00
}