From 5768b6d57dc33e8942968272b42bed7319e48dd3 Mon Sep 17 00:00:00 2001 From: Adrien Cadet Date: Wed, 5 Nov 2014 19:13:52 +0100 Subject: [PATCH 1/2] Adds Ludivine --- Gruntfile.js | 2 +- README.md | 2 + app/dependencies.ts | 19 +-- .../Action.ts => helpers/ActionHelper.ts} | 22 +-- app/helpers/VersionHelper.ts | 2 +- app/libs/ludivine.1.1.0.min.ts | 1 + .../business/impl/TagBookmarkBusiness.ts | 24 +-- app/models/business/impl/TagBusiness.ts | 2 +- app/models/dao/ITagBookmarkDAO.ts | 2 +- app/models/dao/impl/BookmarkDAO.ts | 10 +- app/models/dao/impl/TagBookmarkDAO.ts | 20 +-- app/models/dao/impl/TagDAO.ts | 10 +- app/presenters/IntroPresenter.ts | 144 +++++++++--------- app/presenters/MainPresenter/SearchBar.ts | 4 +- .../overlay-menus/BookmarkFormMenu.ts | 2 +- app/presenters/TourPresenter.ts | 8 +- app/presenters/utils/Notifier.ts | 4 +- app/system/Exception.ts | 49 ------ app/system/Func.ts | 21 --- app/system/Guid.ts | 58 ------- app/system/Log.ts | 57 ------- app/system/Pair.ts | 49 ------ app/system/Timer.ts | 52 ------- app/system/collections/IDictionary.ts | 44 ------ app/system/collections/IList.ts | 74 --------- app/system/collections/Queue.ts | 65 -------- app/system/collections/impl/ArrayList.ts | 140 ----------------- app/system/collections/impl/Dictionary.ts | 109 ------------- .../collections/utils/CollectionException.ts | 3 - .../ActiveRecord/ActiveRecordObject.ts | 40 ++--- .../ActiveRecord/IActiveRecordObject.ts | 6 +- app/system/strings/StringBuffer.ts | 27 ---- 32 files changed, 148 insertions(+), 924 deletions(-) rename app/{system/Action.ts => helpers/ActionHelper.ts} (60%) create mode 100755 app/libs/ludivine.1.1.0.min.ts delete mode 100644 app/system/Exception.ts delete mode 100644 app/system/Func.ts delete mode 100644 app/system/Guid.ts delete mode 100644 app/system/Log.ts delete mode 100644 app/system/Pair.ts delete mode 100644 app/system/Timer.ts delete mode 100644 app/system/collections/IDictionary.ts delete mode 100644 app/system/collections/IList.ts delete mode 100644 app/system/collections/Queue.ts delete mode 100644 app/system/collections/impl/ArrayList.ts delete mode 100644 app/system/collections/impl/Dictionary.ts delete mode 100644 app/system/collections/utils/CollectionException.ts delete mode 100644 app/system/strings/StringBuffer.ts diff --git a/Gruntfile.js b/Gruntfile.js index 5712f1f..da649b2 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -140,7 +140,7 @@ module.exports = function (grunt) { atBegin : true } }, - testing : { + test : { files : ['**/*.ts'], tasks : ['ts:testing', 'shell:testing', 'clean:build'], options : { diff --git a/README.md b/README.md index 05c072a..6af4304 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,6 @@ using it. Please open a ticket in tracker to notify me :) I'll appreciate. * Based on Node-Webkit framework * Uses TypeScript to produce JS code + - [Ludivine](https://github.com/acadet/ludivine) as core + - [Oscar](https://github.com/acadet/oscar) for testing * HTML5/CSS3/SASS for front-end \ No newline at end of file diff --git a/app/dependencies.ts b/app/dependencies.ts index 9107464..c732a98 100644 --- a/app/dependencies.ts +++ b/app/dependencies.ts @@ -2,24 +2,17 @@ /// /// +/// // System part /// /// -/// -/// -/// -/// /// /// -/// /// /// /// -/// -/// -/// /// /// /// @@ -28,15 +21,6 @@ /// /// -// Collections parts - -/// -/// -/// -/// -/// -/// - // Storage part /// @@ -56,6 +40,7 @@ // Helpers part +/// /// /// /// diff --git a/app/system/Action.ts b/app/helpers/ActionHelper.ts similarity index 60% rename from app/system/Action.ts rename to app/helpers/ActionHelper.ts index e2d53b8..541a5bb 100644 --- a/app/system/Action.ts +++ b/app/helpers/ActionHelper.ts @@ -1,25 +1,5 @@ /// -interface Action0 { - () : void; -} - -interface Action { - (t : T) : void; -} - -interface Action2 { - (t : T, u : U) : void; -} - -interface Action3 { - (t : T, u : U, v : V) : void; -} - -interface Action4 { - (t : T, u : U, v : V, w : W) : void; -} - class ActionHelper { static getValueOrDefaultNoArgs(action : Action0) : Action0 { var mock : Action0; @@ -38,4 +18,4 @@ class ActionHelper { return (TSObject.exists(action)) ? action : mock; } -} +} \ No newline at end of file diff --git a/app/helpers/VersionHelper.ts b/app/helpers/VersionHelper.ts index f425f72..9940a0c 100644 --- a/app/helpers/VersionHelper.ts +++ b/app/helpers/VersionHelper.ts @@ -21,7 +21,7 @@ class VersionHelper { //region Public Methods - static isUpToDate(callback : Action, errorHandler : Action = null) : void { + static isUpToDate(callback : Action, errorHandler? : Action) : void { var get : GetRequest; if (Environment.isOnline()) { diff --git a/app/libs/ludivine.1.1.0.min.ts b/app/libs/ludivine.1.1.0.min.ts new file mode 100755 index 0000000..5f06b55 --- /dev/null +++ b/app/libs/ludivine.1.1.0.min.ts @@ -0,0 +1 @@ +interface Action0 { () : void; } interface Action { (t : T) : void; } interface Action2 { (t : T, u : U) : void; } interface Action3 { (t : T, u : U, v : V) : void; } interface Action4 { (t : T, u : U, v : V, w : W) : void; }class Exception { private _error : any; constructor(msg : string, name : string = 'Exception') { this._error = new Error(msg); this._error.name = name; } getMessage() : string { return this._error.message; } getName() : string { return this._error.name; } getStackTrace() : string { return this._error.stack; } toString() : string { return this._error.name + ': ' + this._error.message; } }interface Func0 { () : U; } interface Func { (t: T) : U; } interface Func2 { (t : T, u : U) : V; } interface Func3 { (t : T, u : U, v : V) : W } interface Func4 { (t : T, u : U, v : V, w : W) : X }class Guid { static _randomString(length : number) : string { if (length < 1) { return null; } else { var charSet : string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var outcome : string = ''; for (var i = 0; i < length; i++) { var index : number; index = Math.floor(Math.random() * charSet.length); outcome += charSet.charAt(index); } return outcome; } } static newGuid() : string { var outcome : StringBuffer; outcome = new StringBuffer(); outcome.append(Guid._randomString(8)); outcome.append('-'); outcome.append(Guid._randomString(4)); outcome.append('-'); outcome.append(Guid._randomString(4)); outcome.append('-'); outcome.append(Guid._randomString(4)); outcome.append('-'); outcome.append(Guid._randomString(12)); return outcome.toString(); } }class KeyValuePair { private _key : T; private _value : U; constructor(key? : T, value? : U) { this._key = key; this._value = value; } getKey() : T { return this._key; } setKey(key : T) : void { this._key = key; } getValue() : U { return this._value; } setValue(value : U) : void { this._value = value; } }enum LogLevel { Debug = 0, Test = 1, Production = 2, Opaque = 3 } class Log { private static _currentLevel : LogLevel = LogLevel.Debug; static setLevel(level : LogLevel) : void { Log._currentLevel = level; } static debug(msg : string) : void { if (this._currentLevel <= LogLevel.Debug) { console.log('DEBUG: ' + msg); } } static inform(msg : string) : void { if (this._currentLevel <= LogLevel.Test) { console.log('%cINFORM: ' + msg, 'color: DeepSkyBlue;'); } } static warn(msg : string) : void { if (this._currentLevel <= LogLevel.Production) { console.log('%cWARN: ' + msg, 'color: orange;'); } } static error(error : Exception) : void { console.error('Error: ' + error.toString()); } }class PeriodicTimer { private _timer : any; constructor(handler : Action, period : number, argument? : T) { this._timer = setInterval( () => { handler(argument); }, period ); } stop() : void { clearInterval(this._timer); } }class StringBuffer { private _content : Array; constructor(first : string = '') { this._content = new Array(); this._content.push(first); } append(s: string) : StringBuffer { this._content.push(s); return this; } toString() : string { var result : string = ''; for (var i = 0; i < this._content.length; i++) { result += this._content[i]; } return result; } }class Timer { private _timer : any; constructor(handler : Action, delay : number, argument? : T) { this._timer = setTimeout( () => { handler(argument); }, delay ); } stop() : void { clearTimeout(this._timer); } }class ArrayList implements IList { private _content : Array; constructor(source? : ICollection) { this._content = new Array(); if (source !== null && source !== undefined) { source.forEach(x => this.add(x)); } } insertAt(index : number, value : T) : void { if (index < 0) { throw new CollectionException('Unbound index'); } if (index >= this._content.length) { this.add(value); } else { var tmp : T; tmp = this._content[index]; this._content[index] = value; this.insertAt(index + 1, tmp); } } add(value : T) : void { this._content.push(value); } getAt(index : number) : T { if (index < 0 || index >= this._content.length) { throw new CollectionException('Unbound index'); } return this._content[index]; } getLength() : number { return this._content.length; } remove(value : T) : void { var a : Array; var size : number; var done : boolean; size = this.getLength(); if (size === 0) { return; } a = new Array(); done = false; for (var i = 0; i < size; i++) { var e : T; e = this._content[i]; if (e !== value) { a.push(e); } else { if (done) { a.push(e); } else { done = true; } } } this._content = a; } removeAt(index : number) : void { var size : number; var a : Array; size = this.getLength(); if (index < 0 || index >= size) { throw new CollectionException('Unbound index'); } a = new Array(); for (var i = 0; i < size; i++) { if (i !== index) { a.push(this.getAt(i)); } } this._content = a; } removeIf(func : Func) : void { var a : Array; var size : number; size = this.getLength(); if (size === 0) { return; } a = new Array(); for (var i = 0; i < size; i++) { var e : T; e = this._content[i]; if (!func(e)) { a.push(e); } } this._content = a; } orderBy(getter : Func) : ISortableCollection { var a : Array; var outcome : ArrayList; outcome = new ArrayList(); if (this.getLength() === 0) { return outcome; } a = new Array(); this.forEach(e => a.push(e)); CollectionUtils.ArrayUtils.sort(a, getter); for (var i = 0; i < a.length; i++) { outcome.add(a[i]); } return outcome; } orderByDesc(getter : Func) : ISortableCollection { var a : Array; var outcome : ArrayList; outcome = new ArrayList(); if (this.getLength() === 0) { return outcome; } a = new Array(); this.forEach(e => a.push(e)); CollectionUtils.ArrayUtils.sort(a, getter, false); for (var i = 0; i < a.length; i++) { outcome.add(a[i]); } return outcome; } reverse() : ISortableCollection { var outcome : ArrayList; outcome = new ArrayList(); for (var i = this.getLength() - 1; i >= 0; i--) { outcome.add(this.getAt(i)); } return outcome; } find(selector : Func) : T { var size : number; size = this.getLength(); for (var i = 0; i < size; i++) { var e : T; e = this.getAt(i); if (selector(e)) { return e; } } return null; } forEach(action : Action) : void { var size : number; size = this.getLength(); for (var i = 0; i < size; i++) { action(this.getAt(i)); } } map(action : Func) : ICollection { var outcome : ArrayList; outcome = new ArrayList(); this.forEach(e => outcome.add(action(e))); return outcome; } max(getter : Func) : T { var max : number; var current : T; if (this.getLength() === 0) { return null; } current = this.getAt(0); max = getter(current); this.forEach( (e) => { var value : number; value = getter(e); if (value > max) { max = value; current = e; } } ); return current; } min(getter : Func) : T { var min : number; var current : T; if (this.getLength() === 0) { return null; } current = this.getAt(0); min = getter(current); this.forEach( (e) => { var value : number; value = getter(e); if (value < min) { min = value; current = e; } } ); return current; } select(selector : Func) : ICollection { var outcome : ArrayList; outcome = new ArrayList(); this.forEach( (e) => { if (selector(e)) { outcome.add(e); } } ); return outcome; } sum(getter : Func) : number { var acc : number; acc = 0; this.forEach(e => acc += getter(e)); return acc; } toArray() : Array { var outcome : Array; outcome = new Array(); this.forEach(x => outcome.push(x)); return outcome; } toDictionary(keyGetter : Func, valueGetter : Func) : IDictionary { var outcome : IDictionary; outcome = new Dictionary(); this.forEach(x => outcome.add(keyGetter(x), valueGetter(x))); return outcome; } toList() : IList { return new ArrayList(this); } }class Dictionary implements IDictionary { private _content : Array>; constructor(source? : ICollection>) { this._content = new Array>(); if (source !== null && source !== undefined) { source.forEach(x => this.add(x.getKey(), x.getValue())); } } add(key : K, value : V) : void { if (this.hasKey(key)) { throw new CollectionException('Unable to add value: key already exists'); } else { this._content.push(new KeyValuePair(key, value)); } } get(key : K) : V { var size : number; size = this._content.length; for (var i = 0; i < size; i++) { var pair : KeyValuePair; pair = this._content[i]; if (pair.getKey() === key) { return pair.getValue(); } } throw new CollectionException('No value found for provided key'); } getSize() : number { return this._content.length; } hasKey(key : K) : boolean { var size : number; size = this._content.length; for (var i = 0; i < size; i++) { var pair : KeyValuePair; pair = this._content[i]; if (pair.getKey() === key) { return true; } } return false; } remove(key : K) : void { var size : number; var a : Array>; a = new Array>(); size = this._content.length; for (var i = 0; i < size; i++) { var pair : KeyValuePair; pair = this._content[i]; if (pair.getKey() !== key) { a.push(pair); } } if (a.length === size) { throw new CollectionException('Unable to remove pair: key does not exist'); } this._content = a; } removeIf(func : Func, boolean>) : void { var size : number; var a : Array>; a = new Array>(); size = this._content.length; for (var i = 0; i < size; i++) { var pair : KeyValuePair; pair = this._content[i]; if (!func(pair)) { a.push(pair); } } this._content = a; } find(selector : Func, boolean>) : KeyValuePair { var size : number; size = this._content.length; for (var i = 0; i < size; i++) { var pair : KeyValuePair; pair = this._content[i]; if (selector(pair)) { return pair; } } return null; } forEach(action : Action>) : void { var size : number; size = this._content.length; for (var i = 0; i < size; i++) { action(this._content[i]); } } map(action : Func, KeyValuePair>) : ICollection> { var outcome : Dictionary; outcome = new Dictionary(); this.forEach( (pair) => { var result : KeyValuePair; result = action(pair); outcome.add(result.getKey(), result.getValue()); } ); return outcome; } max(getter : Func, number>) : KeyValuePair { var max : number; var e : KeyValuePair; if (this.getSize() === 0) { return null; } e = this._content[0]; max = getter(e); this.forEach( (x) => { var value : number; value = getter(x); if (value > max) { max = value; e = x; } } ); return e; } min(getter : Func, number>) : KeyValuePair { var min : number; var e : KeyValuePair; if (this.getSize() === 0) { return null; } e = this._content[0]; min = getter(e); this.forEach( (x) => { var value : number; value = getter(x); if (value < min) { min = value; e = x; } } ); return e; } select(selector : Func, boolean>) : ICollection> { var outcome : Dictionary; outcome = new Dictionary(); this.forEach( (pair) => { if (selector(pair)) { outcome.add(pair.getKey(), pair.getValue()); } } ); return outcome; } sum(getter : Func, number>) : number { var acc : number; acc = 0; this.forEach(x => acc += getter(x)); return acc; } toArray() : Array> { var outcome : Array>; outcome = new Array>(); this.forEach(x => outcome.push(x)); return outcome; } toDictionary( keyGetter : Func, A>, valueGetter : Func, B>) : IDictionary { var outcome : IDictionary; outcome = new Dictionary(); this.forEach(x => outcome.add(keyGetter(x), valueGetter(x))); return outcome; } toList() : IList> { return new ArrayList>(this); } }module LinkedListUtils { export class LinkedListElement { private _content : T; private _next : LinkedListElement; constructor(content? : T) { this._content = content; this._next = null; } getContent() : T { return this._content; } setContent(value : T) : void { this._content = value; } getNext() : LinkedListElement { return this._next; } setNext(value : LinkedListElement) : void { this._next = value; } hasNext() : boolean { return this._next !== null && this._next !== undefined; } } } class LinkedList implements IList { private _head : LinkedListUtils.LinkedListElement; private _tail : LinkedListUtils.LinkedListElement; private _size : number; constructor(source? : ICollection) { this._size = 0; if (source !== null && source !== undefined) { source.forEach(x => this.add(x)); } } insertAt(index : number, value : T) : void { if (index < 0) { throw new CollectionException('Unbound index'); } if (index >= this.getLength()) { this.add(value); } else { var prev : LinkedListUtils.LinkedListElement, current : LinkedListUtils.LinkedListElement; var e : LinkedListUtils.LinkedListElement; e = new LinkedListUtils.LinkedListElement(value); current = this._head; for (var i = 0; i < this.getLength(); i++) { if (i === index) { if (i === 0) { e.setNext(this._head); this._head = e; } else { prev.setNext(e); e.setNext(current); } this._size++; return; } prev = current; current = current.getNext(); } } } add(value : T) : void { var e : LinkedListUtils.LinkedListElement; e = new LinkedListUtils.LinkedListElement(value); if (this.getLength() === 0) { this._head = e; this._tail = e; } else { this._tail.setNext(e); this._tail = e; } this._size++; } getAt(index : number) : T { var e : LinkedListUtils.LinkedListElement; if (index < 0 || index >= this._size) { throw new CollectionException('Unbound index'); } e = this._head; for (var i = 0; i < this.getLength(); i++) { if (i === index) { return e.getContent(); } e = e.getNext(); } } getLength() : number { return this._size; } remove(value : T) : void { var prev : LinkedListUtils.LinkedListElement, current : LinkedListUtils.LinkedListElement; current = this._head; prev = null; for (var i = 0; i < this.getLength(); i++) { if (current.getContent() === value) { if (i === 0) { this._head = current.getNext(); } else { prev.setNext(current.getNext()); } if (i === this.getLength() - 1) { this._tail = prev; } this._size--; return; } prev = current; current = current.getNext(); } } removeAt(index : number) : void { var prev : LinkedListUtils.LinkedListElement, current : LinkedListUtils.LinkedListElement; if (index < 0 || index >= this.getLength()) { throw new CollectionException('Unbound index'); } current = this._head; prev = null; for (var i = 0; i < this.getLength(); i++) { if (i === index) { if (i === 0) { this._head = current.getNext(); } else { prev.setNext(current.getNext()); } if (i === this.getLength() - 1) { this._tail = prev; } this._size--; return; } prev = current; current = current.getNext(); } } removeIf(func : Func) : void { var prev : LinkedListUtils.LinkedListElement, current : LinkedListUtils.LinkedListElement; prev = null; current = this._head; for (var i = 0; i < this.getLength(); i++) { if (func(current.getContent())) { if (prev === null || prev === undefined) { this._head = current.getNext(); } else { prev.setNext(current.getNext()); } if (i === this.getLength() - 1) { this._tail = prev; } this._size--; } else { prev = current; } current = current.getNext(); } } orderBy(getter : Func) : ISortableCollection { var a : Array; var size : number; var outcome : LinkedList; outcome = new LinkedList(); if (this.getLength() === 0) { return outcome; } a = this.toArray(); CollectionUtils.ArrayUtils.sort(a, getter); size = a.length; for (var i = 0; i < size; i++) { outcome.add(a[i]); } return outcome; } orderByDesc(getter : Func) : ISortableCollection { var a : Array; var size : number; var outcome : LinkedList; outcome = new LinkedList(); if (this.getLength() === 0) { return outcome; } a = this.toArray(); CollectionUtils.ArrayUtils.sort(a, getter, false); size = a.length; for (var i = 0; i < size; i++) { outcome.add(a[i]); } return outcome; } reverse() : ISortableCollection { var outcome : LinkedList; var a : Array; outcome = new LinkedList(); a = this.toArray(); for (var i = a.length - 1; i >= 0; i--) { outcome.add(a[i]); } return outcome; } find(selector : Func) : T { var cursor : LinkedListUtils.LinkedListElement; var e : T; if (this.getLength() === 0) { return null; } cursor = this._head; while (cursor.hasNext()) { e = cursor.getContent(); if (selector(e)) { return e; } cursor = cursor.getNext(); } e = cursor.getContent(); if (selector(e)) { return e; } else { return null; } } forEach(action : Action) : void { var cursor : LinkedListUtils.LinkedListElement; if (this.getLength() === 0) { return; } cursor = this._head; while (cursor.hasNext()) { action(cursor.getContent()); cursor = cursor.getNext(); } action(cursor.getContent()); } map(action : Func) : ICollection { var outcome : LinkedList; outcome = new LinkedList(); this.forEach(x => outcome.add(action(x))); return outcome; } max(getter : Func) : T { var max : number; var current : T; if (this.getLength() === 0) { return null; } current = this._head.getContent(); max = getter(current); this.forEach( (e) => { var value : number; value = getter(e); if (value > max) { max = value; current = e; } } ); return current; } min(getter : Func) : T { var min : number; var current : T; if (this.getLength() === 0) { return null; } current = this._head.getContent(); min = getter(current); this.forEach( (e) => { var value : number; value = getter(e); if (value < min) { min = value; current = e; } } ); return current; } select(selector : Func) : ICollection { var outcome : LinkedList; outcome = new LinkedList(); this.forEach( (e) => { if (selector(e)) { outcome.add(e); } } ); return outcome; } sum(getter : Func) : number { var acc : number; acc = 0; this.forEach(x => acc += getter(x)); return acc; } toArray() : Array { var outcome : Array; outcome = new Array(); this.forEach(x => outcome.push(x)); return outcome; } toDictionary(keyGetter : Func, valueGetter : Func) : IDictionary { var outcome : IDictionary; outcome = new Dictionary(); this.forEach(x => outcome.add(keyGetter(x), valueGetter(x))); return outcome; } toList() : IList { return new ArrayList(this); } }module QueueUtils { export class QueueElement { private _content : T; private _next : QueueElement; constructor(content? : T) { this._content = content; this._next = null; } getContent() : T { return this._content; } setContent(value : T) : void { this._content = value; } getNext() : QueueElement { return this._next; } setNext(value : QueueElement) : void { this._next = value; } hasNext() : boolean { return (this._next !== null && this._next !== undefined); } } } class Queue implements ISortableCollection { private _top : QueueUtils.QueueElement; private _bottom : QueueUtils.QueueElement; private _size : number; constructor(source? : ICollection) { this._size = 0; if (source !== null && source !== undefined) { source.forEach(x => this.push(x)); } } getSize() : number { return this._size; } top() : T { if (this._size === 0) { return null; } else { return this._top.getContent(); } } pop() : T { if (this._size === 0) { return null; } else { var outcome : T; outcome = this._top.getContent(); if (this._size === 1) { this._top = null; this._bottom = null; } else { this._top = this._top.getNext(); } this._size--; return outcome; } } push(value : T) : void { var e : QueueUtils.QueueElement; e = new QueueUtils.QueueElement(value); if (this._size === 0) { this._top = e; this._bottom = e; } else { this._bottom.setNext(e); this._bottom = e; } this._size++; } orderBy(getter : Func) : ISortableCollection { var a : Array; var outcome : Queue; outcome = new Queue(); if (this.getSize() === 0) { return outcome; } a = new Array(); this.forEach(e => a.push(e)); CollectionUtils.ArrayUtils.sort(a, getter); for (var i = 0; i < a.length; i++) { outcome.push(a[i]); } return outcome; } orderByDesc(getter : Func) : ISortableCollection { var a : Array; var outcome : Queue; outcome = new Queue(); if (this.getSize() === 0) { return outcome; } a = new Array(); this.forEach(e => a.push(e)); CollectionUtils.ArrayUtils.sort(a, getter, false); for (var i = 0; i < a.length; i++) { outcome.push(a[i]); } return outcome; } reverse() : ISortableCollection { var outcome : Queue; var a : Array; outcome = new Queue(); if (this.getSize() === 0) { return outcome; } a = new Array(); this.forEach(x => a.push(x)); for (var i = a.length - 1; i >= 0; i--) { outcome.push(a[i]); } return outcome; } find(selector : Func) : T { var cursor : QueueUtils.QueueElement; var e : T; if (this.getSize() === 0) { return null; } cursor = this._top; while (cursor.hasNext()) { e = cursor.getContent(); if (selector(e)) { return e; } cursor = cursor.getNext(); } e = cursor.getContent(); if (selector(e)) { return e; } return null; } forEach(action : Action) : void { var cursor : QueueUtils.QueueElement; if (this.getSize() === 0) { return; } cursor = this._top; while (cursor.hasNext()) { action(cursor.getContent()); cursor = cursor.getNext(); } action(cursor.getContent()); } map(action : Func) : ICollection { var outcome : Queue; outcome = new Queue(); this.forEach( (e) => { outcome.push(action(e)); } ); return outcome; } max(getter : Func) : T { var max : number; var outcome : T; if (this.getSize() === 0) { return null; } outcome = this._top.getContent(); max = getter(outcome); this.forEach( (e) => { var value : number; value = getter(e); if (value > max) { max = value; outcome = e; } } ); return outcome; } min(getter : Func) : T { var min : number; var outcome : T; if (this.getSize() === 0) { return null; } outcome = this._top.getContent(); min = getter(outcome); this.forEach( (e) => { var value : number; value = getter(e); if (value < min) { min = value; outcome = e; } } ); return outcome; } select(selector : Func) : ICollection { var outcome : Queue; outcome = new Queue(); this.forEach( (e) => { if (selector(e)) { outcome.push(e); } } ); return outcome; } sum(getter : Func) : number { var total : number; total = 0; this.forEach(e => total += getter(e)); return total; } toArray() : Array { var outcome : Array; outcome = new Array(); this.forEach(x => outcome.push(x)); return outcome; } toDictionary(keyGetter : Func, valueGetter : Func) : IDictionary { var outcome : IDictionary; outcome = new Dictionary(); this.forEach(x => outcome.add(keyGetter(x), valueGetter(x))); return outcome; } toList() : IList { return new ArrayList(this); } }module SortedListUtils { export class SortedListElement { private _content : T; private _next : SortedListElement; constructor(content? : T) { this._content = content; this._next = null; } getContent() : T { return this._content; } setContent(value : T) : void { this._content = value; } getNext() : SortedListElement { return this._next; } setNext(value : SortedListElement) : void { this._next = value; } hasNext() : boolean { return this._next !== null && this._next !== undefined; } } export class SortedListCursor { private _previous : SortedListElement; private _current : SortedListElement; constructor(previous? : SortedListElement, current? : SortedListElement) { this._previous = previous; this._current = current; } getPrevious() : SortedListElement { return this._previous; } setPrevious(value : SortedListElement) : void { this._previous = value; } hasPrevious() : boolean { return this._previous !== null && this._previous !== undefined; } getCurrent() : SortedListElement { return this._current; } setCurrent(value : SortedListElement) : void { this._current = value; } } } class SortedList implements IListableCollection { private _head : SortedListUtils.SortedListElement; private _getter : Func; private _size : number; private _asc : boolean; constructor(getter : Func, ascending? : boolean) { this._getter = getter; this._size = 0; if (ascending !== null && ascending !== undefined) { this._asc = ascending; } else { this._asc = true; } } private _forEach(func : Func, boolean>) : boolean { var prev : SortedListUtils.SortedListElement, current : SortedListUtils.SortedListElement; if (this.getLength() === 0) { return false; } current = this._head; prev = null; while (current.hasNext()) { if (func(new SortedListUtils.SortedListCursor(prev, current))) { return true; } prev = current; current = current.getNext(); } return func(new SortedListUtils.SortedListCursor(prev, current)); } add(value : A) : void { var e : SortedListUtils.SortedListElement; e = new SortedListUtils.SortedListElement(value); if (this.getLength() === 0) { this._head = e; } else { var success : boolean; var latestCursor : SortedListUtils.SortedListCursor; var comparator : Func2; if (this._asc) { comparator = (a, b) => { return a < b; }; } else { comparator = (a, b) => { return a > b; }; } success = this._forEach( (cursor) => { var current : SortedListUtils.SortedListElement; current = cursor.getCurrent(); latestCursor = cursor; if (comparator(this._getter(value), this._getter(current.getContent()))) { if (cursor.hasPrevious()) { cursor.getPrevious().setNext(e); } else { this._head = e; } e.setNext(current); return true; } else { return false; } } ); if (!success) { latestCursor.getCurrent().setNext(e); } } this._size++; } getAt(index : number) : A { var outcome : A; var i : number; if (index < 0 || index >= this.getLength()) { throw new CollectionException('Unbound index'); } i = 0; this._forEach( (cursor) => { if (i === index) { outcome = cursor.getCurrent().getContent(); return true; } else { i++; return false; } } ); return outcome; } getLength() : number { return this._size; } remove(value : A) : void { var done : boolean; done = this._forEach( (cursor) => { if (cursor.getCurrent().getContent() === value) { if (cursor.hasPrevious()) { cursor.getPrevious().setNext(cursor.getCurrent().getNext()); } else { this._head = cursor.getCurrent().getNext(); } return true; } else { return false; } } ); if (done) { this._size--; } } removeAt(index : number) : void { var i : number; if (index < 0 || index >= this.getLength()) { throw new CollectionException('Unbound index'); } i = 0; this._forEach( (cursor) => { if (i === index) { var e : SortedListUtils.SortedListElement; e = cursor.getCurrent().getNext(); if (cursor.hasPrevious()) { cursor.getPrevious().setNext(e); } else { this._head = e; } return true; } i++; } ); this._size--; } removeIf(func : Func) : void { var prev : SortedListUtils.SortedListElement, current : SortedListUtils.SortedListElement; var size : number; size = this.getLength(); prev = null; current = this._head; for (var i = 0; i < size; i++) { if (func(current.getContent())) { if (prev !== null && prev !== undefined) { prev.setNext(current.getNext()); } else { this._head = current.getNext(); } this._size--; } else { prev = current; } current = current.getNext(); } } orderBy(getter : Func) : ISortableCollection { var outcome : SortedList; outcome = new SortedList(getter); this.forEach(e => outcome.add(e)); return outcome; } orderByDesc(getter : Func) : ISortableCollection { var outcome : SortedList; outcome = new SortedList(getter, false); this.forEach(e => outcome.add(e)); return outcome; } reverse() : ISortableCollection { var outcome : SortedList; outcome = new SortedList(this._getter, !this._asc); this.forEach(e => outcome.add(e)); return outcome; } find(selector : Func) : A { var outcome : A; outcome = null; this._forEach( (cursor) => { var content : A; content = cursor.getCurrent().getContent(); if (selector(content)) { outcome = content; return true; } return false; } ); return outcome; } forEach(action : Action) : void { this._forEach( (cursor) => { action(cursor.getCurrent().getContent()); return false; } ); } map(action : Func) : ICollection { var outcome : SortedList; outcome = new SortedList(this._getter, this._asc); this.forEach( (e) => { outcome.add(action(e)); } ); return outcome; } max(getter : Func) : A { var max : number; var current : A; if (this.getLength() === 0) { return null; } current = this._head.getContent(); max = getter(current); this.forEach( (e) => { var value : number; value = getter(e); if (value > max) { max = value; current = e; } } ); return current; } min(getter : Func) : A { var min : number; var current : A; if (this.getLength() === 0) { return null; } current = this._head.getContent(); min = getter(current); this.forEach( (e) => { var value : number; value = getter(e); if (value < min) { min = value; current = e; } } ); return current; } select(selector : Func) : ICollection { var outcome : SortedList; outcome = new SortedList(this._getter, this._asc); this.forEach( (e) => { if (selector(e)) { outcome.add(e); } } ); return outcome; } sum(getter : Func) : number { var acc : number; acc = 0; this.forEach(e => acc += getter(e)); return acc; } toArray() : Array { var outcome : Array; outcome = new Array(); this.forEach(e => outcome.push(e)); return outcome; } toDictionary(keyGetter : Func, valueGetter : Func) : IDictionary { var outcome : IDictionary; outcome = new Dictionary(); this.forEach(x => outcome.add(keyGetter(x), valueGetter(x))); return outcome; } toList() : IList { return new ArrayList(this); } }module StackUtils { export class StackElement { private _prev : StackElement; private _content : T; constructor(content? : T) { this._content = content; this._prev = null; } getContent() : T { return this._content; } setContent(value : T) : void { this._content = value; } getPrev() : StackElement { return this._prev; } setPrev(value : StackElement) : void { this._prev = value; } hasPrev() : boolean { return this._prev !== null && this._prev !== undefined; } } } class Stack implements ISortableCollection { private _tail : StackUtils.StackElement; private _size : number; constructor(source? : ICollection) { this._size = 0; if (source !== null && source !== undefined) { source.forEach(x => this.push(x)); } } private _forEachInversed(action : Action) : void { var a : Array; var cursor : StackUtils.StackElement; a = new Array(); cursor = this._tail; while (cursor.hasPrev()) { a.push(cursor.getContent()); cursor = cursor.getPrev(); } a.push(cursor.getContent()); for (var i = a.length - 1; i >= 0; i--) { action(a[i]); } } getSize() : number { return this._size; } top() : T { if (this.getSize() === 0) { return null; } else { return this._tail.getContent(); } } pop() : T { if (this.getSize() === 0) { return null; } else { var e : T; e = this._tail.getContent(); this._size--; this._tail = this._tail.getPrev(); return e; } } push(value : T) : void { var e : StackUtils.StackElement; e = new StackUtils.StackElement(value); if (this.getSize() === 0) { this._tail = e; } else { e.setPrev(this._tail); this._tail = e; } this._size++; } orderBy(getter : Func) : ISortableCollection { var outcome : Stack; var a : Array; outcome = new Stack(); if (this.getSize() === 0) { return outcome; } a = new Array(); this.forEach(e => a.push(e)); CollectionUtils.ArrayUtils.sort(a, getter); for (var i = a.length - 1; i >= 0; i--) { outcome.push(a[i]); } return outcome; } orderByDesc(getter : Func) : ISortableCollection { var outcome : Stack; var a : Array; outcome = new Stack(); if (this.getSize() === 0) { return outcome; } a = new Array(); this.forEach(e => a.push(e)); CollectionUtils.ArrayUtils.sort(a, getter); for (var i = 0; i < a.length; i++) { outcome.push(a[i]); } return outcome; } reverse() : ISortableCollection { var outcome : Stack; outcome = new Stack(); this.forEach(e => outcome.push(e)); return outcome; } find(selector : Func) : T { var cursor : StackUtils.StackElement; var e : T; if (this.getSize() === 0) { return null; } cursor = this._tail; while (cursor.hasPrev()) { e = cursor.getContent(); if (selector(e)) { return e; } cursor = cursor.getPrev(); } e = cursor.getContent(); if (selector(e)) { return e; } else { return null; } } forEach(action : Action) : void { var cursor : StackUtils.StackElement; if (this.getSize() === 0) { return; } cursor = this._tail; while (cursor.hasPrev()) { action(cursor.getContent()); cursor = cursor.getPrev(); } action(cursor.getContent()); } map(action : Func) : ICollection { var outcome : Stack; outcome = new Stack(); this._forEachInversed(e => outcome.push(action(e))); return outcome; } max(getter : Func) : T { var max : number; var e : T; if (this.getSize() === 0) { return null; } e = this._tail.getContent(); max = getter(e); this.forEach( (x) => { var value : number; value = getter(x); if (value > max) { max = value; e = x; } } ); return e; } min(getter : Func) : T { var min : number; var e : T; if (this.getSize() === 0) { return null; } e = this._tail.getContent(); min = getter(e); this.forEach( (x) => { var value : number; value = getter(x); if (value < min) { min = value; e = x; } } ); return e; } select(selector : Func) : ICollection { var outcome : Stack; outcome = new Stack(); this._forEachInversed( (e) => { if (selector(e)) { outcome.push(e); } } ); return outcome; } sum(getter : Func) : number { var total : number; total = 0; this.forEach(x => total += getter(x)); return total; } toArray() : Array { var outcome : Array; outcome = new Array(); this.forEach(x => outcome.push(x)); return outcome; } toDictionary(keyGetter : Func, valueGetter : Func) : IDictionary { var outcome : IDictionary; outcome = new Dictionary(); this.forEach(x => outcome.add(keyGetter(x), valueGetter(x))); return outcome; } toList() : IList { return new ArrayList(this); } }interface ICollection { find(selector : Func) : T; forEach(action : Action) : void; map(action : Func) : ICollection; max(getter : Func) : T; min(getter : Func) : T; select(selector : Func) : ICollection; sum(getter : Func) : number; toArray() : Array; toDictionary(keyGetter : Func, valueGetter : Func) : IDictionary; toList() : IList; }interface IDictionary extends ICollection> { add(key : K, value : V) : void; get(key : K) : V; getSize() : number; hasKey(key : K) : boolean; remove(key : K) : void; removeIf(func : Func, boolean>) : void; }interface IList extends IListableCollection { insertAt(index : number, value : T) : void; }interface IListableCollection extends ISortableCollection { add(value : T) : void; getAt(index : number) : T; getLength() : number; remove(value : T) : void; removeAt(index : number) : void; removeIf(func : Func) : void; }interface ISortableCollection extends ICollection { orderBy(getter : Func) : ISortableCollection; orderByDesc(getter : Func) : ISortableCollection; reverse() : ISortableCollection; }module CollectionUtils { export class ArrayUtils { private static _swap(source : Array, i : number, j : number) : void { var tmp : T; tmp = source[i]; source[i] = source[j]; source[j] = tmp; } private static _partition( source : Array, getter : Func, comparator : Func2, first : number, last : number, pivot : number) : number { var j : number; var pivotValue : U; j = pivot; pivotValue = getter(source[pivot]); for (var i = first; i <= last; i++) { var value : U; value = getter(source[i]); if (comparator(value, pivotValue)) { if (j < i) { ArrayUtils._swap(source, j + 1, i); ArrayUtils._swap(source, j, j + 1); j++; } } else { if (i < j) { ArrayUtils._swap(source, i, j); j = i; } } } return j; } private static _sort( source : Array, getter : Func, comparator : Func2, first : number, last : number) : void { if (first < last) { var pivot : number; pivot = Math.round(Math.random() * (last - first)); pivot = ArrayUtils._partition(source, getter, comparator, first, last, pivot); ArrayUtils._sort(source, getter, comparator, first, pivot - 1); ArrayUtils._sort(source, getter, comparator, pivot + 1, last); } } static sort(source : Array, getter : Func, asc : boolean = true) : void { var comparator : Func2; if (source.length === 0) { return; } if (asc) { comparator = (a, b) => { return a <= b; }; } else { comparator = (a, b) => { return a >= b; }; } ArrayUtils._sort(source, getter, comparator, 0, source.length - 1); } } }class CollectionException extends Exception { constructor(msg : string) { super(msg, 'CollectionException'); } } \ No newline at end of file diff --git a/app/models/business/impl/TagBookmarkBusiness.ts b/app/models/business/impl/TagBookmarkBusiness.ts index d1808f6..f2e9a69 100644 --- a/app/models/business/impl/TagBookmarkBusiness.ts +++ b/app/models/business/impl/TagBookmarkBusiness.ts @@ -22,7 +22,7 @@ class TagBookmarkBusiness implements ITagBookmarkBusiness { private _browseDLNode( node : DOMElement, currentTags : IList, - collection : IList>>) + collection : IList>>) : void { var i : number; @@ -38,7 +38,7 @@ class TagBookmarkBusiness implements ITagBookmarkBusiness { b.setURL(a.getAttribute('href')); b.setTitle(a.getText()); - collection.add(new Pair>(b, currentTags)); + collection.add(new KeyValuePair>(b, currentTags)); } ); @@ -61,7 +61,7 @@ class TagBookmarkBusiness implements ITagBookmarkBusiness { (e) => { var l : IList; - l = currentTags.clone(); + l = >currentTags.select(x => true); l.add(collectedTags.getAt(i)); this._browseDLNode(e, l, collection); i++; @@ -71,10 +71,10 @@ class TagBookmarkBusiness implements ITagBookmarkBusiness { private _addRecursiveBookmark( index : number, - coll : IList>>, + coll : IList>>, callback? : Action0, errorHandler? : Action) : void { - var p : Pair>; + var p : KeyValuePair>; callback = ActionHelper.getValueOrDefaultNoArgs(callback); errorHandler = ActionHelper.getValueOrDefault(errorHandler); @@ -90,7 +90,7 @@ class TagBookmarkBusiness implements ITagBookmarkBusiness { ._args .getBookmarkBusiness() .isNotAlreadyExisting( - p.getFirst().getURL(), + p.getKey().getURL(), (success) => { if (!success) { Log.error(new BusinessException('Unable to import bookmark, one has already same URL')); @@ -102,7 +102,7 @@ class TagBookmarkBusiness implements ITagBookmarkBusiness { ._args .getTagBusiness() .merge( - p.getSecond(), + p.getValue(), (outcome) => { var tags : IList = outcome; @@ -110,7 +110,7 @@ class TagBookmarkBusiness implements ITagBookmarkBusiness { ._args .getBookmarkBusiness() .add( - p.getFirst(), + p.getKey(), (outcome) => { this.bindTags( outcome, @@ -512,7 +512,7 @@ class TagBookmarkBusiness implements ITagBookmarkBusiness { reader.onload = (e) => { var dlRoot : DOMElement; - var coll : IList>>; + var coll : IList>>; var tags : IList; var defaultTag : Tag; @@ -525,7 +525,7 @@ class TagBookmarkBusiness implements ITagBookmarkBusiness { DOMElement .fromString('' + reader.result + '') .findSingle('> DL'); - coll = new ArrayList>>(); + coll = new ArrayList>>(); this._browseDLNode(dlRoot, tags, coll); this._addRecursiveBookmark( 0, @@ -600,8 +600,8 @@ class TagBookmarkBusiness implements ITagBookmarkBusiness { (pair) => { var sbk : ScoredBookmark; var currentScore : number; - var bk : Bookmark = pair.getFirst(); - var tagList : IList = pair.getSecond(); + var bk : Bookmark = pair.getKey(); + var tagList : IList = pair.getValue(); sbk = new ScoredBookmark(); bk.hydrate(sbk); diff --git a/app/models/business/impl/TagBusiness.ts b/app/models/business/impl/TagBusiness.ts index 3f4e444..a6306d4 100644 --- a/app/models/business/impl/TagBusiness.ts +++ b/app/models/business/impl/TagBusiness.ts @@ -324,7 +324,7 @@ class TagBusiness implements IInternalTagBusiness { tag.setLabel(StringHelper.trim(tag.getLabel())); // Find a tag with same name - o = outcome.findFirst(e => StringHelper.compare(e.getLabel(), tag.getLabel())); + o = outcome.find(e => StringHelper.compare(e.getLabel(), tag.getLabel())); if (o !== null) { // A tag with same is already existing, nothing to do diff --git a/app/models/dao/ITagBookmarkDAO.ts b/app/models/dao/ITagBookmarkDAO.ts index 4e0c5b3..2de3f19 100644 --- a/app/models/dao/ITagBookmarkDAO.ts +++ b/app/models/dao/ITagBookmarkDAO.ts @@ -17,5 +17,5 @@ interface ITagBookmarkDAO { sortBookmarksByTitleAscForTag(tag : Tag, callback : Action>) : void; - sortBookmarksByTitleAscWithBoundTagsByLabelAsc(callback : Action>>>) : void; + sortBookmarksByTitleAscWithBoundTagsByLabelAsc(callback : Action>>>) : void; } diff --git a/app/models/dao/impl/BookmarkDAO.ts b/app/models/dao/impl/BookmarkDAO.ts index 49ddf8b..3462507 100644 --- a/app/models/dao/impl/BookmarkDAO.ts +++ b/app/models/dao/impl/BookmarkDAO.ts @@ -83,7 +83,7 @@ class BookmarkDAO extends DataAccessObject implements IBookmarkDAO { update(bookmark : Bookmark, callback? : Action) : void { var dict : IDictionary; - var selector : Pair; + var selector : KeyValuePair; callback = ActionHelper.getValueOrDefault(callback); @@ -99,7 +99,7 @@ class BookmarkDAO extends DataAccessObject implements IBookmarkDAO { dict.add('description', bookmark.getDescription()); dict.add('views', bookmark.getViews()); - selector = new Pair('id', bookmark.getId()); + selector = new KeyValuePair('id', bookmark.getId()); this.getARO().update( DAOTables.Bookmarks, @@ -136,7 +136,7 @@ class BookmarkDAO extends DataAccessObject implements IBookmarkDAO { .getARO() .delete( DAOTables.Bookmarks, - new Pair('id', bookmark.getId()), + new KeyValuePair('id', bookmark.getId()), (success2) => { callback(success1 && success2); } @@ -154,7 +154,7 @@ class BookmarkDAO extends DataAccessObject implements IBookmarkDAO { .getARO() .find( DAOTables.Bookmarks, - new Pair('id', id), + new KeyValuePair('id', id), callback, Bookmark.fromObject ); @@ -165,7 +165,7 @@ class BookmarkDAO extends DataAccessObject implements IBookmarkDAO { .getARO() .find( DAOTables.Bookmarks, - new Pair('url', url), + new KeyValuePair('url', url), callback, Bookmark.fromObject ); diff --git a/app/models/dao/impl/TagBookmarkDAO.ts b/app/models/dao/impl/TagBookmarkDAO.ts index e8c0e02..2bf4265 100644 --- a/app/models/dao/impl/TagBookmarkDAO.ts +++ b/app/models/dao/impl/TagBookmarkDAO.ts @@ -125,7 +125,7 @@ class TagBookmarkDAO extends DataAccessObject implements ITagBookmarkDAO { } removeBookmarkRelations(bookmark : Bookmark, callback? : Action) : void { - var selector : Pair; + var selector : KeyValuePair; callback = ActionHelper.getValueOrDefault(callback); @@ -135,7 +135,7 @@ class TagBookmarkDAO extends DataAccessObject implements ITagBookmarkDAO { return; } - selector = new Pair('bookmark_id', bookmark.getId()); + selector = new KeyValuePair('bookmark_id', bookmark.getId()); this .getARO() .delete( @@ -153,7 +153,7 @@ class TagBookmarkDAO extends DataAccessObject implements ITagBookmarkDAO { } removeTagRelations(tag : Tag, callback? : Action) : void { - var selector : Pair; + var selector : KeyValuePair; callback = ActionHelper.getValueOrDefault(callback); @@ -163,7 +163,7 @@ class TagBookmarkDAO extends DataAccessObject implements ITagBookmarkDAO { return; } - selector = new Pair('tag_id', tag.getId()); + selector = new KeyValuePair('tag_id', tag.getId()); this .getARO() .delete( @@ -237,7 +237,7 @@ class TagBookmarkDAO extends DataAccessObject implements ITagBookmarkDAO { ); } - sortBookmarksByTitleAscWithBoundTagsByLabelAsc(callback : Action>>>) : void { + sortBookmarksByTitleAscWithBoundTagsByLabelAsc(callback : Action>>>) : void { var request : StringBuffer; request = new StringBuffer('SELECT bk.id AS id, bk.url as url, bk.title AS title, bk.description AS description, '); @@ -257,13 +257,13 @@ class TagBookmarkDAO extends DataAccessObject implements ITagBookmarkDAO { .executeSQL( request.toString(), (set) => { - var pairList : IList>>; + var pairList : IList>>; var bk : Bookmark = null; var l : IList; var outcome : SQLRowSet; - var p : Pair>; + var p : KeyValuePair>; - pairList = new ArrayList>>(); + pairList = new ArrayList>>(); if (!TSObject.exists(set)) { callback(pairList); @@ -278,7 +278,7 @@ class TagBookmarkDAO extends DataAccessObject implements ITagBookmarkDAO { if (bk === null || bk.getId() !== item.id) { if (bk !== null) { - p = new Pair>(bk, l); + p = new KeyValuePair>(bk, l); pairList.add(p); } @@ -301,7 +301,7 @@ class TagBookmarkDAO extends DataAccessObject implements ITagBookmarkDAO { } if (bk !== null) { - p = new Pair>(bk, l); + p = new KeyValuePair>(bk, l); pairList.add(p); } diff --git a/app/models/dao/impl/TagDAO.ts b/app/models/dao/impl/TagDAO.ts index 0b57319..6fe9899 100644 --- a/app/models/dao/impl/TagDAO.ts +++ b/app/models/dao/impl/TagDAO.ts @@ -77,7 +77,7 @@ class TagDAO extends DataAccessObject implements ITagDAO { update(tag : Tag, callback? : Action) : void { var dict : IDictionary; - var selector : Pair; + var selector : KeyValuePair; callback = ActionHelper.getValueOrDefault(callback); @@ -90,7 +90,7 @@ class TagDAO extends DataAccessObject implements ITagDAO { dict = new Dictionary(); dict.add('label', tag.getLabel()); - selector = new Pair('id', tag.getId()); + selector = new KeyValuePair('id', tag.getId()); this .getARO() @@ -129,7 +129,7 @@ class TagDAO extends DataAccessObject implements ITagDAO { .getARO() .delete( DAOTables.Tags, - new Pair('id', tag.getId()), + new KeyValuePair('id', tag.getId()), (success2) => { callback(success1 && success2); } @@ -147,7 +147,7 @@ class TagDAO extends DataAccessObject implements ITagDAO { .getARO() .find( DAOTables.Tags, - new Pair('id', id), + new KeyValuePair('id', id), callback, Tag.fromObject ); @@ -158,7 +158,7 @@ class TagDAO extends DataAccessObject implements ITagDAO { .getARO() .find( DAOTables.Tags, - new Pair('label', label), + new KeyValuePair('label', label), callback, Tag.fromObject ); diff --git a/app/presenters/IntroPresenter.ts b/app/presenters/IntroPresenter.ts index 22b8c40..fbb3a4c 100644 --- a/app/presenters/IntroPresenter.ts +++ b/app/presenters/IntroPresenter.ts @@ -21,6 +21,14 @@ class IntroPresenter extends YimelloPresenter { //region Private Methods + private _tryExit() : void { + if (this._mustExit) { + this._exit(); + } else { + this._mustExit = true; + } + } + private _exit() : void { if (CacheAPI.get('tour') === 'ok') { NodeWindow.moveTo('main.html'); @@ -33,76 +41,74 @@ class IntroPresenter extends YimelloPresenter { private _testVersion() : void { VersionHelper.isUpToDate( (success) => { - if (!success) { - var body : DOMElement, icon : DOMElement; - var originalWidth : number, originalHeight : number; - var duration : number = 600; - - body = DOMTree.findSingle('.js-body'); - icon = body.findSingle('.js-update-icon'); - originalWidth = 50; - originalHeight = 50; - - icon.on( - DOMElementEvents.Click, - (args) => { - NodeWindow.openExternal('http://yimello.adriencadet.com'); - } - ); + var body : DOMElement, icon : DOMElement; + var originalWidth : number, originalHeight : number; + var duration : number = 600; + + if (success) { + this._tryExit(); + return; + } + + body = DOMTree.findSingle('.js-body'); + icon = body.findSingle('.js-update-icon'); + originalWidth = 50; + originalHeight = 50; + + icon.on( + DOMElementEvents.Click, + (args) => { + NodeWindow.openExternal('http://yimello.adriencadet.com'); + } + ); - icon.setCss({ - width : originalWidth, - height : originalHeight, - top : body.getHeight() - 100, - left : (body.getWidth() - originalWidth) / 2 - }); + icon.setCss({ + width : originalWidth, + height : originalHeight, + top : body.getHeight() - 100, + left : (body.getWidth() - originalWidth) / 2 + }); + + icon.animateEasing( + { + opacity : 1, + width : originalWidth * 2, + height : originalHeight * 2, + top : body.getHeight() - 100 - (originalHeight / 2), + left : (body.getWidth() - originalWidth * 2) / 2 + }, + duration, + 'easeOutBack' + ); - icon.animateEasing( + icon + .findSingle('img') + .animateEasing( { - opacity : 1, - width : originalWidth * 2, - height : originalHeight * 2, - top : body.getHeight() - 100 - (originalHeight / 2), - left : (body.getWidth() - originalWidth * 2) / 2 + marginLeft : (originalWidth * 2 - 50) / 2, + marginTop : (originalHeight * 2 - 50) / 2 }, duration, - 'easeOutBack' - ); - - icon - .findSingle('img') - .animateEasing( - { - marginLeft : (originalWidth * 2 - 50) / 2, - marginTop : (originalHeight * 2 - 50) / 2 - }, - duration, - 'easeOutBack', - (o) => { - icon.addClass('pulse'); - - if (this._mustExit) { - var t : Timer; - - t = new Timer( - (o) => { - this._exit(); - }, - 3000 - ); - } else { - this._mustExit = true; - } + 'easeOutBack', + (o) => { + icon.addClass('pulse'); + + if (this._mustExit) { + var t : Timer; + + t = new Timer( + (o) => { + this._exit(); + }, + 3000 + ); + } else { + this._mustExit = true; } - ); - } else { - if (this._mustExit) { - this._exit(); - } else { - this._mustExit = true; - } - } - } + } + ); + }, + (msg) => this._tryExit() ); } @@ -111,11 +117,11 @@ class IntroPresenter extends YimelloPresenter { //region Public Methods onStart() : void { - var t : Timer; + var t : Timer; super.onStart(); - t = new Timer( + t = new Timer( (o) => { this._testVersion(); }, @@ -126,11 +132,7 @@ class IntroPresenter extends YimelloPresenter { (business) => { business.backup( () => { - if (this._mustExit) { - this._exit(); - } else { - this._mustExit = true; - } + this._tryExit(); } ); } diff --git a/app/presenters/MainPresenter/SearchBar.ts b/app/presenters/MainPresenter/SearchBar.ts index 767d10e..41796dd 100644 --- a/app/presenters/MainPresenter/SearchBar.ts +++ b/app/presenters/MainPresenter/SearchBar.ts @@ -7,7 +7,7 @@ class SearchBar { private _bar : DOMElement; private _input : DOMElement; private _clear : DOMElement; - private _delayer : Timer; + private _delayer : Timer; //endregion Fields @@ -33,7 +33,7 @@ class SearchBar { this._delayer.stop(); } - this._delayer = new Timer( + this._delayer = new Timer( (o) => { if (value.length > 0) { this._listener.onSearchRequest(value); diff --git a/app/presenters/MainPresenter/overlay-menus/BookmarkFormMenu.ts b/app/presenters/MainPresenter/overlay-menus/BookmarkFormMenu.ts index 224242f..063d908 100644 --- a/app/presenters/MainPresenter/overlay-menus/BookmarkFormMenu.ts +++ b/app/presenters/MainPresenter/overlay-menus/BookmarkFormMenu.ts @@ -320,7 +320,7 @@ class BookmarkFormMenu extends OverlayMenu { .forEach( (e) => { if (TSObject.exists( - outcome.findFirst( + outcome.find( (o) => (o.getId() === tags.getAt(i).getId()) ) )) { diff --git a/app/presenters/TourPresenter.ts b/app/presenters/TourPresenter.ts index 683d801..5d9a122 100644 --- a/app/presenters/TourPresenter.ts +++ b/app/presenters/TourPresenter.ts @@ -229,12 +229,12 @@ class TourPresenter extends YimelloPresenter { business.createFromURL( url, (bookmark) => { - var t : Timer; + var t : Timer; this._currentBookmark = bookmark; this._urlInput.addClass('success'); - t = new Timer( + t = new Timer( (o) => { this._swapSlide(TourPresenterSlides.Tags); }, @@ -300,10 +300,10 @@ class TourPresenter extends YimelloPresenter { this._currentBookmark, this._currentTags, () => { - var timer : Timer; + var timer : Timer; this._tagInput.addClass('success'); - timer = new Timer( + timer = new Timer( (o) => { this._swapSlide(TourPresenterSlides.End); }, diff --git a/app/presenters/utils/Notifier.ts b/app/presenters/utils/Notifier.ts index 5bc9304..040c35b 100644 --- a/app/presenters/utils/Notifier.ts +++ b/app/presenters/utils/Notifier.ts @@ -9,7 +9,7 @@ enum NotifierCodes { class Notifier implements INotifier { //region Fields - private _timer : Timer; + private _timer : Timer; private _target : DOMElement; private _content : DOMElement; @@ -60,7 +60,7 @@ class Notifier implements INotifier { }, 750, (o) => { - this._timer = new Timer( + this._timer = new Timer( (o) => { this._hide(); this._timer = null; diff --git a/app/system/Exception.ts b/app/system/Exception.ts deleted file mode 100644 index f2926a0..0000000 --- a/app/system/Exception.ts +++ /dev/null @@ -1,49 +0,0 @@ -/// - -class Exception extends TSObject { - - //region Fields - - private _error : any; - - //endregion Fields - - //region Constructors - - constructor(msg : string, name : string = 'Exception') { - super(); - - this._error = new Error(msg); - this._error.name = name; - } - - //endregion Constructors - - //region Methods - - //region Private Methods - - //endregion Private Methods - - //region Public Methods - - getMessage() : string { - return this._error.message; - } - - getName() : string { - return this._error.name; - } - - getStackTrace() : string { - return this._error.stack; - } - - toString() : string { - return this._error.name + ': ' + this._error.message; - } - - //endregion Public Methods - - //endregion Methods -} diff --git a/app/system/Func.ts b/app/system/Func.ts deleted file mode 100644 index 90565c8..0000000 --- a/app/system/Func.ts +++ /dev/null @@ -1,21 +0,0 @@ -/// - -interface Func0 { - () : U; -} - -interface Func { - (t: T) : U; -} - -interface Func2 { - (t : T, u : U) : V; -} - -interface Func3 { - (t : T, u : U, v : V) : W -} - -interface Func4 { - (t : T, u : U, v : V, w : W) : X -} \ No newline at end of file diff --git a/app/system/Guid.ts b/app/system/Guid.ts deleted file mode 100644 index da15fc8..0000000 --- a/app/system/Guid.ts +++ /dev/null @@ -1,58 +0,0 @@ -/// - -class Guid { - //region Fields - - //endregion Fields - - //region Constructors - - //endregion Constructors - - //region Methods - - //region Private Methods - - static _randomString(length : number) : string { - if (length < 1) { - return null; - } else { - var charSet : string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - var outcome : string = ''; - - for(var i = 0; i < length; i++) { - var index : number; - - index = MathHelper.floor(MathHelper.random() * charSet.length); - outcome += charSet.charAt(index); - } - - return outcome; - } - } - - //endregion Private Methods - - //region Public Methods - - static newGuid() : string { - var outcome : StringBuffer; - - outcome = new StringBuffer(); - outcome.append(Guid._randomString(8)); - outcome.append('-'); - outcome.append(Guid._randomString(4)); - outcome.append('-'); - outcome.append(Guid._randomString(4)); - outcome.append('-'); - outcome.append(Guid._randomString(4)); - outcome.append('-'); - outcome.append(Guid._randomString(12)); - - return outcome.toString(); - } - - //endregion Public Methods - - //endregion Methods -} diff --git a/app/system/Log.ts b/app/system/Log.ts deleted file mode 100644 index f0adb1e..0000000 --- a/app/system/Log.ts +++ /dev/null @@ -1,57 +0,0 @@ -/// - -enum LogLevel { - Debug, - Test, - Production -} - -class Log { - //region Fields - - private static _currentLevel : LogLevel = LogLevel.Debug; - - //endregion Fields - - //region Constructors - - //endregion Constructors - - //region Methods - - //region Private Methods - - //endregion Private Methods - - //region Public Methods - - static setLevel(l : LogLevel) : void { - Log._currentLevel = l; - } - - static debug(msg : string) : void { - if (this._currentLevel <= LogLevel.Debug) { - console.log('DEBUG: ' + msg); - } - } - - static inform(msg : string) : void { - if (this._currentLevel <= LogLevel.Test) { - console.log('%cINFORM: ' + msg, 'color: DeepSkyBlue;'); - } - } - - static warn(msg : string) : void { - if (this._currentLevel <= LogLevel.Production) { - console.log('%cWARN: ' + msg, 'color: orange;'); - } - } - - static error(e : Exception) : void { - console.error('Error: ' + e.toString()); - } - - //endregion Public Methods - - //endregion Methods -} diff --git a/app/system/Pair.ts b/app/system/Pair.ts deleted file mode 100644 index 0320776..0000000 --- a/app/system/Pair.ts +++ /dev/null @@ -1,49 +0,0 @@ -/// - -class Pair extends TSObject { - //region Fields - - private _first : T; - private _second : U; - - //endregion Fields - - //region Constructors - - //endregion Constructors - - constructor(first : T = null, second : U = null) { - super(); - - this._first = first; - this._second = second; - } - - //region Methods - - //region Private Methods - - //endregion Private Methods - - //region Public Methods - - getFirst() : T { - return this._first; - } - - setFirst(first : T) : void { - this._first = first; - } - - getSecond() : U { - return this._second; - } - - setSecond(second : U) : void { - this._second = second; - } - - //endregion Public Methods - - //endregion Methods -} diff --git a/app/system/Timer.ts b/app/system/Timer.ts deleted file mode 100644 index 253014d..0000000 --- a/app/system/Timer.ts +++ /dev/null @@ -1,52 +0,0 @@ -/// - -class Timer extends TSObject { - //region Fields - - private _timer : any; - private _hasIntervals : boolean; - - //endregion Fields - - //region Constructors - - constructor(handler: Action, delay : number, argument : any = null, frequency : number = -1) { - super(); - - if (frequency > 0) { - this._hasIntervals = true; - setTimeout(() => { - this._timer = setInterval(() => { - handler(argument); - }, frequency); - }, delay); - } else { - this._hasIntervals = false; - this._timer = setTimeout(() => { - handler(argument); - }, delay); - } - } - - //endregion Constructors - - //region Methods - - //region Private Methods - - //endregion Private Methods - - //region Public Methods - - stop() : void { - if (this._hasIntervals) { - clearInterval(this._timer); - } else { - clearTimeout(this._timer); - } - } - - //endregion Public Methods - - //endregion Methods -} diff --git a/app/system/collections/IDictionary.ts b/app/system/collections/IDictionary.ts deleted file mode 100644 index 0af665d..0000000 --- a/app/system/collections/IDictionary.ts +++ /dev/null @@ -1,44 +0,0 @@ -/// - -/** - * A dictionary collection - * @type {[type]} - */ -interface IDictionary { - /** - * Adds couple to collection - * @param {T} key [description] - * @param {U} value [description] - */ - add(key : T, value : U) : void; - - /** - * Clones dictionary - * @return {IDictionary} [description] - */ - clone() : IDictionary; - - /** - * Tests if current dictionary contains specified key - * @param {T} key [description] - * @return {boolean} [description] - */ - containsKey(key : T) : boolean; - - /** - * Applies a function to each element - * @param {Action2} f [description] - */ - forEach(f : Action2) : void; - - /** - * Gets value for specified key - * @param {T} key [description] - * @return {U} [description] - */ - get(key : T) : U; - - getLength() : number; - - remove(key : T) : void; -} diff --git a/app/system/collections/IList.ts b/app/system/collections/IList.ts deleted file mode 100644 index 58a62d1..0000000 --- a/app/system/collections/IList.ts +++ /dev/null @@ -1,74 +0,0 @@ -/// - -/** - * A list collection - */ -interface IList { - /** - * Adds a new item to list - * @param {T} t [description] - */ - add(t: T) : void; - - /** - * Clones current list - * @return {IList} [description] - */ - clone() : IList; - - /** - * Finds first matching of provided selector. - * If no element is found, returns null - * @param {Func} f Selector - * @return {T} [description] - */ - findFirst(f : Func) : T; - - /** - * Applies a function to each element of list - * @param {Action} f [description] - */ - forEach(f : Action) : void; - - /** - * Gets an element at specified index - * @param {number} index [description] - * @return {T} [description] - */ - getAt(index: number) : T; - - /** - * Gets length of list - * @return {number} [description] - */ - getLength() : number; - - /** - * Inserts an element at specified index - * @param {number} index [description] - * @param {T} t [description] - */ - insertAt(index : number, t : T) : void; - - /** - * Applies a transformation to each element - * of list - * @param {Func} f [description] - */ - map(f : Func) : void; - - /** - * Removes an element from list - * @param {T} t [description] - */ - remove(t : T) : void; - - removeIf(f : Func) : void; - - /** - * Casts list to an array - * @return {Array} [description] - */ - toArray() : Array; -} - diff --git a/app/system/collections/Queue.ts b/app/system/collections/Queue.ts deleted file mode 100644 index 3c2eab0..0000000 --- a/app/system/collections/Queue.ts +++ /dev/null @@ -1,65 +0,0 @@ -/// - -class Queue extends TSObject { - //region Fields - - private _content : Array; - - //endregion Fields - - //region Constructors - - constructor() { - super(); - - this._content = new Array(); - } - - //endregion Constructors - - //region Methods - - //region Private Methods - - //endregion Private Methods - - //region Public Methods - - getLength() : number { - return this._content.length; - } - - push(t : T) : void { - this._content.push(t); - } - - top() : T { - if (this.getLength() === 0) { - Log.warn('You call top() on an empty queue'); - return null; - } else { - return this._content[0]; - } - } - - pop() : T { - if (this.getLength() === 0) { - Log.warn('You call pop() an empty queue'); - return null; - } else { - var t : T = this._content[0]; - - if (this.getLength() > 1) { - this._content.splice(0, 1); - } else { - this._content = new Array(); - } - - return t; - } - } - - //endregion Public Methods - - //endregion Methods -} diff --git a/app/system/collections/impl/ArrayList.ts b/app/system/collections/impl/ArrayList.ts deleted file mode 100644 index ba37bfa..0000000 --- a/app/system/collections/impl/ArrayList.ts +++ /dev/null @@ -1,140 +0,0 @@ -/// - -/** - * An implementation of list collection. - * Based on an array - */ -class ArrayList extends TSObject implements IList { - //region Fields - - /** - * Used array for storing data - */ - private _content : Array; - - //endregion Fields - - //region Constructors - - constructor() { - super(); - - this._content = new Array(); - } - - //endregion Constructors - - //region Methods - - //region Private Methods - - //endregion Private Methods - - //region Public Methods - - add(t: T) : void { - this._content.push(t); - } - - clone() : IList { - var l : IList = new ArrayList(); - - for (var i = 0; i < this.getLength(); i++) { - l.add(this.getAt(i)); - } - - return l; - } - - findFirst(f : Func) : T { - for (var i = 0; i < this.getLength(); i++) { - var t : T = this.getAt(i); - - if (f(t)) { - return t; - } - } - - return null; - } - - forEach(f : Action) : void { - for(var i = 0; i < this.getLength() ; i++) { - f(this.getAt(i)); - } - } - - getAt(index: number) : T { - if (index < 0) { - throw new CollectionException('Negative index'); - } - - if (index >= this._content.length) { - throw new CollectionException('Unbound index'); - } - - return this._content[index]; - } - - getLength() : number { - return this._content.length; - } - - insertAt(index : number, t : T) : void { - - if (index > this.getLength() || index < 0) { - throw new CollectionException('Unbound index'); - } - - if (index === this.getLength() || this.getLength() === 0) { - this.add(t); - return; - } - - this._content.splice(index, 0, t); - } - - map(f : Func) : void { - var a : Array = new Array(); - - for (var i = 0; i < this.getLength(); i++) { - a.push(f(this.getAt(i))); - } - - this._content = a; - } - - remove(t : T) : void { - var index : number; - - index = this._content.indexOf(t); - - if (index > -1) { - this._content.splice(index, 1); - } else { - throw new CollectionException('Unable to remove: item not found'); - } - } - - removeIf(f : Func) : void { - var a : Array = new Array(); - - this.forEach( - (e) => { - if (!f(e)) { - a.push(e); - } - } - ); - - this._content = a; - } - - toArray() : Array { - return this._content; - } - - //endregion Public Methods - - //endregion Methods -} diff --git a/app/system/collections/impl/Dictionary.ts b/app/system/collections/impl/Dictionary.ts deleted file mode 100644 index 8c7809e..0000000 --- a/app/system/collections/impl/Dictionary.ts +++ /dev/null @@ -1,109 +0,0 @@ -/// - -/** - * An implementation of dictionary collection. - * Uses two arrays in parallel - * @type {[type]} - */ -class Dictionary extends TSObject implements IDictionary { - //region Fields - - /** - * Array of keys - */ - private _keys : Array; - - /** - * Array of values - */ - private _values : Array; - - //endregion Fields - - //region Constructors - - constructor() { - super(); - - this._keys = new Array(); - this._values = new Array(); - } - - //endregion Constructors - - //region Methods - - //region Private Methods - - //endregion Private Methods - - //region Public Methods - - add(key : T, value : U) : void { - if (this.containsKey(key)) { - throw new CollectionException('Unable to add couple: key is already existing'); - } - - this._keys.push(key); - this._values.push(value); - } - - clone() : IDictionary { - var d : IDictionary = new Dictionary(); - - this.forEach((k, v) => { - d.add(k, v); - }); - - return d; - } - - containsKey(key : T) : boolean { - for (var i = 0; i < this._keys.length; i++) { - if (this._keys[i] === key) { - return true; - } - } - - return false; - } - - forEach(f : Action2) : void { - for (var i = 0; i < this._keys.length; i++) { - f(this._keys[i], this._values[i]); - } - } - - get(key : T) : U { - for (var i = 0; i < this._keys.length; i++) { - if (this._keys[i] === key) { - return this._values[i]; - } - } - - throw new CollectionException('Unable to find value for specified key'); - } - - getLength() : number { - return this._keys.length; - } - - // TODO : test - remove(key : T) : void { - var index : number; - - index = this._keys.indexOf(key); - - if (index > -1) { - this._keys.splice(index, 1); - this._values.splice(index, 1); - } else { - throw new CollectionException('Unable to remove: item not found'); - } - } - - //endregion Public Methods - - //endregion Methods -} - diff --git a/app/system/collections/utils/CollectionException.ts b/app/system/collections/utils/CollectionException.ts deleted file mode 100644 index 0e91ca6..0000000 --- a/app/system/collections/utils/CollectionException.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// - -class CollectionException extends Exception {} \ No newline at end of file diff --git a/app/system/storage/ActiveRecord/ActiveRecordObject.ts b/app/system/storage/ActiveRecord/ActiveRecordObject.ts index 9dec7d2..fe38360 100644 --- a/app/system/storage/ActiveRecord/ActiveRecordObject.ts +++ b/app/system/storage/ActiveRecord/ActiveRecordObject.ts @@ -70,7 +70,7 @@ class ActiveRecordObject implements IActiveRecordObject { find( table : string, - selector : Pair, + selector : KeyValuePair, callback : Action, converter? : Func) : void { @@ -79,10 +79,10 @@ class ActiveRecordObject implements IActiveRecordObject { var data : Array; data = new Array(); - data.push(selector.getSecond()); + data.push(selector.getValue()); tx.execute( - 'SELECT * FROM ' + table + ' WHERE LOWER(' + selector.getFirst() + ') = LOWER(?)', + 'SELECT * FROM ' + table + ' WHERE LOWER(' + selector.getKey() + ') = LOWER(?)', data, (tx, outcome) => { var s : SQLRowSet; @@ -161,7 +161,7 @@ class ActiveRecordObject implements IActiveRecordObject { update( table : string, - selector : Pair, + selector : KeyValuePair, data : IDictionary, callback? : Action) : void { @@ -181,22 +181,24 @@ class ActiveRecordObject implements IActiveRecordObject { args = new ArrayList(); - data.forEach((k, v) => { - if (i !== 0) { - marks.append(', '); - } + data.forEach( + (pair) => { + if (i !== 0) { + marks.append(', '); + } - // Keys are used for request - marks.append(k + ' = ?'); - // Values are used as prepared data - args.add(v); - i++; - }); + // Keys are used for request + marks.append(pair.getKey() + ' = ?'); + // Values are used as prepared data + args.add(pair.getValue()); + i++; + } + ); - args.add(selector.getSecond()); + args.add(selector.getValue()); tx.execute( - 'UPDATE ' + table + ' SET ' + marks.toString() + ' WHERE ' + selector.getFirst() + ' = ?', + 'UPDATE ' + table + ' SET ' + marks.toString() + ' WHERE ' + selector.getKey() + ' = ?', args.toArray(), (tx, outcome) => { callback(true); @@ -212,7 +214,7 @@ class ActiveRecordObject implements IActiveRecordObject { ); } - delete(table : string, selector : Pair, callback? : Action) : void { + delete(table : string, selector : KeyValuePair, callback? : Action) : void { callback = ActionHelper.getValueOrDefault(callback); this._database.transaction( @@ -220,12 +222,12 @@ class ActiveRecordObject implements IActiveRecordObject { var request : StringBuffer; request = new StringBuffer('DELETE FROM ' + table); - request.append(' WHERE ' + selector.getFirst()); + request.append(' WHERE ' + selector.getKey()); request.append(' = ?'); tx.execute( request.toString(), - [selector.getSecond()], + [selector.getValue()], (tx, outcome) => { callback(true); }, diff --git a/app/system/storage/ActiveRecord/IActiveRecordObject.ts b/app/system/storage/ActiveRecord/IActiveRecordObject.ts index a0d5fb5..1097441 100644 --- a/app/system/storage/ActiveRecord/IActiveRecordObject.ts +++ b/app/system/storage/ActiveRecord/IActiveRecordObject.ts @@ -28,7 +28,7 @@ interface IActiveRecordObject { */ find( table : string, - selector : Pair, + selector : KeyValuePair, callback : Action, converter? : Func) : void; @@ -49,7 +49,7 @@ interface IActiveRecordObject { */ update( table : string, - selector : Pair, + selector : KeyValuePair, data : IDictionary, callback? : Action) : void; @@ -59,5 +59,5 @@ interface IActiveRecordObject { * @param selector Key/Value to match * @param callback Optional callback to call with a success bool */ - delete(table : string, selector : Pair, callback? : Action) : void; + delete(table : string, selector : KeyValuePair, callback? : Action) : void; } diff --git a/app/system/strings/StringBuffer.ts b/app/system/strings/StringBuffer.ts deleted file mode 100644 index a432ed7..0000000 --- a/app/system/strings/StringBuffer.ts +++ /dev/null @@ -1,27 +0,0 @@ -/// - -class StringBuffer extends TSObject { - constructor(first = '') { - super(); - - this._content = new Array(); - this._content.push(first); - } - - append(s: string) : StringBuffer { - this._content.push(s); - return this; - } - - toString() : string { - var result : string = ''; - - for(var i = 0; i < this._content.length; i++) { - result += this._content[i]; - } - - return result; - } - - private _content : Array; -} \ No newline at end of file From e4cf843bf5aee96b0e5423c056b8350d6dedb131 Mon Sep 17 00:00:00 2001 From: Adrien Cadet Date: Thu, 6 Nov 2014 10:34:09 +0100 Subject: [PATCH 2/2] Fixed compatibility issues with ludivine --- .gitignore | 2 + Gruntfile.js | 4 +- app/helpers/VersionHelper.ts | 2 +- app/ui/assets/scss/_utils.scss | 2 +- testing/src/mocks/DAO.ts | 12 +- .../business/impl/TagBookmarkBusinessTest.ts | 8 +- .../models/business/impl/TagBusinessTest.ts | 6 +- .../src/models/dao/impl/BookmarkDAOTest.ts | 14 +- .../src/models/dao/impl/TagBookmarkDAOTest.ts | 54 ++-- testing/src/models/dao/impl/TagDAOTest.ts | 18 +- testing/src/references.ts | 4 - testing/src/system/GuidTest.ts | 35 --- .../src/system/collections/ArrayListTest.ts | 288 ------------------ .../src/system/collections/DictionaryTest.ts | 164 ---------- testing/src/system/collections/QueueTest.ts | 53 ---- .../ActiveRecord/ActiveRecordObjectTest.ts | 12 +- 16 files changed, 69 insertions(+), 609 deletions(-) delete mode 100644 testing/src/system/GuidTest.ts delete mode 100644 testing/src/system/collections/ArrayListTest.ts delete mode 100644 testing/src/system/collections/DictionaryTest.ts delete mode 100644 testing/src/system/collections/QueueTest.ts diff --git a/.gitignore b/.gitignore index 1d4fdcc..6700ed0 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ app/ui/js/output.js testing/out **/*.css + +*.cfg diff --git a/Gruntfile.js b/Gruntfile.js index da649b2..e5d3c12 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -142,7 +142,7 @@ module.exports = function (grunt) { }, test : { files : ['**/*.ts'], - tasks : ['ts:testing', 'shell:testing', 'clean:build'], + tasks : ['ts:build', 'ts:testing', 'shell:testing', 'clean:build'], options : { interrupt : true, atBegin : true @@ -178,7 +178,7 @@ module.exports = function (grunt) { }); grunt.registerTask('build', ['watch:build']); - grunt.registerTask('testing', ['watch:testing']); + grunt.registerTask('test', ['watch:test']); grunt.registerTask( 'release', [ diff --git a/app/helpers/VersionHelper.ts b/app/helpers/VersionHelper.ts index 9940a0c..71bcbf3 100644 --- a/app/helpers/VersionHelper.ts +++ b/app/helpers/VersionHelper.ts @@ -5,7 +5,7 @@ class VersionHelper { //region Fields private static _target : string = 'http://yimello.adriencadet.com/version'; - private static _version : string = '0.3.1'; + private static _version : string = '0.3.2'; //endregion Fields diff --git a/app/ui/assets/scss/_utils.scss b/app/ui/assets/scss/_utils.scss index 4a2b913..8910f97 100644 --- a/app/ui/assets/scss/_utils.scss +++ b/app/ui/assets/scss/_utils.scss @@ -22,7 +22,7 @@ border-radius: $value; } -@mixin transition($property, $duration, $easing : linear, $delay : 0) { +@mixin transition($property, $duration, $easing : linear, $delay : 0s) { -webkit-transition : $property $duration $easing $delay; -moz-transition : $property $duration $easing $delay; -ms-transition : $property $duration $easing $delay; diff --git a/testing/src/mocks/DAO.ts b/testing/src/mocks/DAO.ts index 8fa6a3d..149becc 100644 --- a/testing/src/mocks/DAO.ts +++ b/testing/src/mocks/DAO.ts @@ -51,7 +51,7 @@ module Mocks { find( table : string, - selector : Pair, + selector : KeyValuePair, callback : Action, converter? : Func) : void { @@ -70,7 +70,7 @@ module Mocks { update( table : string, - selector : Pair, + selector : KeyValuePair, data : IDictionary, callback? : Action) : void { @@ -82,7 +82,7 @@ module Mocks { } } - delete(table : string, selector : Pair, callback? : Action) : void { + delete(table : string, selector : KeyValuePair, callback? : Action) : void { this._deleteTimes++; this._deleteArgs = [table, selector, callback]; if (TSObject.exists(callback)) { @@ -487,7 +487,7 @@ module Mocks { private _removeTagRelationsOutcome : boolean; private _sortTagsByLabelAscForBookmarkOutcome : IList; private _sortBookmarksByTitleAscForTagOutcome : IList; - private _sortBookmarksByTitleAscWithBoundTagsByLabelAscOutcome : IList>>; + private _sortBookmarksByTitleAscWithBoundTagsByLabelAscOutcome : IList>>; private _addMultipleTagRelationsTimes : number; private _updateBookmarkRelationsTimes : number; @@ -565,7 +565,7 @@ module Mocks { callback(this._sortBookmarksByTitleAscForTagOutcome); } - sortBookmarksByTitleAscWithBoundTagsByLabelAsc(callback : Action>>>) : void { + sortBookmarksByTitleAscWithBoundTagsByLabelAsc(callback : Action>>>) : void { this._sortBookmarksByTitleAscWithBoundTagsByLabelAscTimes++; this._sortBookmarksByTitleAscWithBoundTagsByLabelAscArgs = [callback]; callback(this._sortBookmarksByTitleAscWithBoundTagsByLabelAscOutcome); @@ -602,7 +602,7 @@ module Mocks { return this; } - setSortBookmarksByTitleAscWithBoundTagsByLabelAscOutcome(value : IList>>) : Mocks.DAO.TagBookmarkDAO { + setSortBookmarksByTitleAscWithBoundTagsByLabelAscOutcome(value : IList>>) : Mocks.DAO.TagBookmarkDAO { this._sortBookmarksByTitleAscWithBoundTagsByLabelAscOutcome = value; return this; } diff --git a/testing/src/models/business/impl/TagBookmarkBusinessTest.ts b/testing/src/models/business/impl/TagBookmarkBusinessTest.ts index d78f8b4..d5acc3b 100644 --- a/testing/src/models/business/impl/TagBookmarkBusinessTest.ts +++ b/testing/src/models/business/impl/TagBookmarkBusinessTest.ts @@ -161,7 +161,7 @@ class TagBookmarkBusinessTest extends UnitTestClass { TagBookmarkBusinessSearchAsyncTest(obs : IOscarObserver) : void { // Arrange - var list : IList>>; + var list : IList>>; var t1 : Tag, t2 : Tag; var b1 : Bookmark, b2 : Bookmark; var tags1 : IList, tags2 : IList; @@ -171,13 +171,13 @@ class TagBookmarkBusinessTest extends UnitTestClass { t1 = new Tag().setLabel('foobarbar'); t2 = new Tag().setLabel('barbar'); - list = new ArrayList>>(); + list = new ArrayList>>(); tags1 = new ArrayList(); tags1.add(t1); tags2 = new ArrayList(); tags2.add(t2); - list.add(new Pair>(b1, tags1)); - list.add(new Pair>(b2, tags2)); + list.add(new KeyValuePair>(b1, tags1)); + list.add(new KeyValuePair>(b2, tags2)); this._tagBookmarkDAO.setSortBookmarksByTitleAscWithBoundTagsByLabelAscOutcome(list); diff --git a/testing/src/models/business/impl/TagBusinessTest.ts b/testing/src/models/business/impl/TagBusinessTest.ts index d53bb00..bf8864b 100644 --- a/testing/src/models/business/impl/TagBusinessTest.ts +++ b/testing/src/models/business/impl/TagBusinessTest.ts @@ -275,9 +275,9 @@ class TagBusinessTest extends UnitTestClass { Assert.isNotNull(outcome); Assert.areEqual(3, outcome.getLength()); - Assert.isNotNull(outcome.findFirst(e => e.getId() === 'foo')); - Assert.isNotNull(outcome.findFirst(e => e.getId() === 'bar')); - Assert.isNotNull(outcome.findFirst(e => e.getId() === 'foobar')); + Assert.isNotNull(outcome.find(e => e.getId() === 'foo')); + Assert.isNotNull(outcome.find(e => e.getId() === 'bar')); + Assert.isNotNull(outcome.find(e => e.getId() === 'foobar')); obs.success(); } diff --git a/testing/src/models/dao/impl/BookmarkDAOTest.ts b/testing/src/models/dao/impl/BookmarkDAOTest.ts index 7a3dc04..29daac8 100644 --- a/testing/src/models/dao/impl/BookmarkDAOTest.ts +++ b/testing/src/models/dao/impl/BookmarkDAOTest.ts @@ -129,10 +129,10 @@ class BookmarkDAOTest extends UnitTestClass { Assert.areEqual(1, this._aro.updateTimes()); Assert.areEqual(DAOTables.Bookmarks, this._aro.updateArgs()[0]); - Assert.areEqual('id', this._aro.updateArgs()[1].getFirst()); - Assert.areEqual('bar', this._aro.updateArgs()[1].getSecond()); + Assert.areEqual('id', this._aro.updateArgs()[1].getKey()); + Assert.areEqual('bar', this._aro.updateArgs()[1].getValue()); - Assert.areEqual(4, this._aro.updateArgs()[2].getLength()); + Assert.areEqual(4, this._aro.updateArgs()[2].getSize()); Assert.areEqual('google.fr', this._aro.updateArgs()[2].get('url')); Assert.areEqual('foo', this._aro.updateArgs()[2].get('title')); Assert.areEqual('Amazing', this._aro.updateArgs()[2].get('description')); @@ -165,8 +165,8 @@ class BookmarkDAOTest extends UnitTestClass { Assert.areEqual(1, this._aro.deleteTimes()); Assert.areEqual(DAOTables.Bookmarks, this._aro.deleteArgs()[0]); - Assert.areEqual('id', this._aro.deleteArgs()[1].getFirst()); - Assert.areEqual('foo', this._aro.deleteArgs()[1].getSecond()); + Assert.areEqual('id', this._aro.deleteArgs()[1].getKey()); + Assert.areEqual('foo', this._aro.deleteArgs()[1].getValue()); Assert.isTrue(outcome); @@ -213,8 +213,8 @@ class BookmarkDAOTest extends UnitTestClass { // Assert Assert.areEqual(1, this._aro.findTimes()); Assert.areEqual(DAOTables.Bookmarks, this._aro.findArgs()[0]); - Assert.areEqual('id', this._aro.findArgs()[1].getFirst()); - Assert.areEqual('foo', this._aro.findArgs()[1].getSecond()); + Assert.areEqual('id', this._aro.findArgs()[1].getKey()); + Assert.areEqual('foo', this._aro.findArgs()[1].getValue()); Assert.areEqual(Bookmark.fromObject, this._aro.findArgs()[3]); Assert.areEqual(b, outcome); diff --git a/testing/src/models/dao/impl/TagBookmarkDAOTest.ts b/testing/src/models/dao/impl/TagBookmarkDAOTest.ts index 0205c3c..191cc5f 100644 --- a/testing/src/models/dao/impl/TagBookmarkDAOTest.ts +++ b/testing/src/models/dao/impl/TagBookmarkDAOTest.ts @@ -122,8 +122,8 @@ class TagBookmarkDAOTest extends UnitTestClass { // Check delete request Assert.areEqual(1, this._aro.deleteTimes()); Assert.areEqual(DAOTables.TagBookmark, this._aro.deleteArgs()[0]); - Assert.areEqual('bookmark_id', this._aro.deleteArgs()[1].getFirst()); - Assert.areEqual('foo', this._aro.deleteArgs()[1].getSecond()); + Assert.areEqual('bookmark_id', this._aro.deleteArgs()[1].getKey()); + Assert.areEqual('foo', this._aro.deleteArgs()[1].getValue()); // Check insert requests Assert.areEqual(2, this._aro.insertTimes()); @@ -152,8 +152,8 @@ class TagBookmarkDAOTest extends UnitTestClass { // Check delete request Assert.areEqual(1, this._aro.deleteTimes()); Assert.areEqual(DAOTables.TagBookmark, this._aro.deleteArgs()[0]); - Assert.areEqual('bookmark_id', this._aro.deleteArgs()[1].getFirst()); - Assert.areEqual('foo', this._aro.deleteArgs()[1].getSecond()); + Assert.areEqual('bookmark_id', this._aro.deleteArgs()[1].getKey()); + Assert.areEqual('foo', this._aro.deleteArgs()[1].getValue()); obs.success(); } @@ -179,8 +179,8 @@ class TagBookmarkDAOTest extends UnitTestClass { // Check delete request Assert.areEqual(1, this._aro.deleteTimes()); Assert.areEqual(DAOTables.TagBookmark, this._aro.deleteArgs()[0]); - Assert.areEqual('tag_id', this._aro.deleteArgs()[1].getFirst()); - Assert.areEqual('foo', this._aro.deleteArgs()[1].getSecond()); + Assert.areEqual('tag_id', this._aro.deleteArgs()[1].getKey()); + Assert.areEqual('foo', this._aro.deleteArgs()[1].getValue()); obs.success(); } @@ -372,27 +372,27 @@ class TagBookmarkDAOTest extends UnitTestClass { Assert.isNotNull(outcome); Assert.areEqual(2, outcome.getLength()); - Assert.areEqual('1', outcome.getAt(0).getFirst().getId()); - Assert.areEqual('foo', outcome.getAt(0).getFirst().getTitle()); - Assert.areEqual('google.fr', outcome.getAt(0).getFirst().getURL()); - Assert.areEqual('Amazing!', outcome.getAt(0).getFirst().getDescription()); - Assert.areEqual(56, outcome.getAt(0).getFirst().getViews()); - - Assert.areEqual(2, outcome.getAt(0).getSecond().getLength()); - Assert.areEqual('34', outcome.getAt(0).getSecond().getAt(0).getId()); - Assert.areEqual('bar', outcome.getAt(0).getSecond().getAt(0).getLabel()); - Assert.areEqual('45', outcome.getAt(0).getSecond().getAt(1).getId()); - Assert.areEqual('barbar', outcome.getAt(0).getSecond().getAt(1).getLabel()); - - Assert.areEqual('2', outcome.getAt(1).getFirst().getId()); - Assert.areEqual('foobar', outcome.getAt(1).getFirst().getTitle()); - Assert.areEqual('google.uk', outcome.getAt(1).getFirst().getURL()); - Assert.areEqual('Formidable!', outcome.getAt(1).getFirst().getDescription()); - Assert.areEqual(789, outcome.getAt(1).getFirst().getViews()); - - Assert.areEqual(1, outcome.getAt(1).getSecond().getLength()); - Assert.areEqual('35', outcome.getAt(1).getSecond().getAt(0).getId()); - Assert.areEqual('foobarbar', outcome.getAt(1).getSecond().getAt(0).getLabel()); + Assert.areEqual('1', outcome.getAt(0).getKey().getId()); + Assert.areEqual('foo', outcome.getAt(0).getKey().getTitle()); + Assert.areEqual('google.fr', outcome.getAt(0).getKey().getURL()); + Assert.areEqual('Amazing!', outcome.getAt(0).getKey().getDescription()); + Assert.areEqual(56, outcome.getAt(0).getKey().getViews()); + + Assert.areEqual(2, outcome.getAt(0).getValue().getLength()); + Assert.areEqual('34', outcome.getAt(0).getValue().getAt(0).getId()); + Assert.areEqual('bar', outcome.getAt(0).getValue().getAt(0).getLabel()); + Assert.areEqual('45', outcome.getAt(0).getValue().getAt(1).getId()); + Assert.areEqual('barbar', outcome.getAt(0).getValue().getAt(1).getLabel()); + + Assert.areEqual('2', outcome.getAt(1).getKey().getId()); + Assert.areEqual('foobar', outcome.getAt(1).getKey().getTitle()); + Assert.areEqual('google.uk', outcome.getAt(1).getKey().getURL()); + Assert.areEqual('Formidable!', outcome.getAt(1).getKey().getDescription()); + Assert.areEqual(789, outcome.getAt(1).getKey().getViews()); + + Assert.areEqual(1, outcome.getAt(1).getValue().getLength()); + Assert.areEqual('35', outcome.getAt(1).getValue().getAt(0).getId()); + Assert.areEqual('foobarbar', outcome.getAt(1).getValue().getAt(0).getLabel()); obs.success(); } diff --git a/testing/src/models/dao/impl/TagDAOTest.ts b/testing/src/models/dao/impl/TagDAOTest.ts index 1d736e4..97ec3c9 100644 --- a/testing/src/models/dao/impl/TagDAOTest.ts +++ b/testing/src/models/dao/impl/TagDAOTest.ts @@ -108,10 +108,10 @@ class TagDAOTest extends UnitTestClass { Assert.areEqual(1, this._aro.updateTimes()); Assert.areEqual(DAOTables.Tags, this._aro.updateArgs()[0]); - Assert.areEqual('id', this._aro.updateArgs()[1].getFirst()); - Assert.areEqual('foo', this._aro.updateArgs()[1].getSecond()); + Assert.areEqual('id', this._aro.updateArgs()[1].getKey()); + Assert.areEqual('foo', this._aro.updateArgs()[1].getValue()); - Assert.areEqual(1, this._aro.updateArgs()[2].getLength()); + Assert.areEqual(1, this._aro.updateArgs()[2].getSize()); Assert.areEqual('bar', this._aro.updateArgs()[2].get('label')); Assert.isNotNull(outcome); @@ -140,8 +140,8 @@ class TagDAOTest extends UnitTestClass { Assert.areEqual(1, this._aro.deleteTimes()); Assert.areEqual(DAOTables.Tags, this._aro.deleteArgs()[0]); - Assert.areEqual('id', this._aro.deleteArgs()[1].getFirst()); - Assert.areEqual('foo', this._aro.deleteArgs()[1].getSecond()); + Assert.areEqual('id', this._aro.deleteArgs()[1].getKey()); + Assert.areEqual('foo', this._aro.deleteArgs()[1].getValue()); Assert.isTrue(outcome); @@ -187,8 +187,8 @@ class TagDAOTest extends UnitTestClass { // Assert Assert.areEqual(1, this._aro.findTimes()); Assert.areEqual(DAOTables.Tags, this._aro.findArgs()[0]); - Assert.areEqual('id', this._aro.findArgs()[1].getFirst()); - Assert.areEqual('foo', this._aro.findArgs()[1].getSecond()); + Assert.areEqual('id', this._aro.findArgs()[1].getKey()); + Assert.areEqual('foo', this._aro.findArgs()[1].getValue()); Assert.areEqual(Tag.fromObject, this._aro.findArgs()[3]); Assert.areEqual(t, outcome); @@ -211,8 +211,8 @@ class TagDAOTest extends UnitTestClass { // Assert Assert.areEqual(1, this._aro.findTimes()); Assert.areEqual(DAOTables.Tags, this._aro.findArgs()[0]); - Assert.areEqual('label', this._aro.findArgs()[1].getFirst()); - Assert.areEqual('foo', this._aro.findArgs()[1].getSecond()); + Assert.areEqual('label', this._aro.findArgs()[1].getKey()); + Assert.areEqual('foo', this._aro.findArgs()[1].getValue()); Assert.areEqual(Tag.fromObject, this._aro.findArgs()[3]); Assert.areEqual(t, outcome); diff --git a/testing/src/references.ts b/testing/src/references.ts index a26739c..cc98394 100644 --- a/testing/src/references.ts +++ b/testing/src/references.ts @@ -22,10 +22,6 @@ /// /// /// -/// -/// -/// -/// /// /// //grunt-end \ No newline at end of file diff --git a/testing/src/system/GuidTest.ts b/testing/src/system/GuidTest.ts deleted file mode 100644 index 2fccd85..0000000 --- a/testing/src/system/GuidTest.ts +++ /dev/null @@ -1,35 +0,0 @@ -/// - -class GuidTest extends UnitTestClass { - setUp() : void { - - } - - tearDown() : void { - - } - - GuidTestNewGuidTest() : void { - // Arrange - var outcome : string; - var charSet : string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - - // Act - outcome = Guid.newGuid(); - - // Assert - for (var i = 0; i < 32; i++) { - if (i === 8 || i === 13 || i === 18 || i === 23) { - Assert.areEqual('-', outcome.charAt(i)); - } else { - var b : boolean = false; - for (var j = 0; j < charSet.length && !b; j++) { - if (outcome.charAt(i) === charSet.charAt(j)) { - b = true; - } - } - Assert.isTrue(b); - } - } - } -} diff --git a/testing/src/system/collections/ArrayListTest.ts b/testing/src/system/collections/ArrayListTest.ts deleted file mode 100644 index c1db34e..0000000 --- a/testing/src/system/collections/ArrayListTest.ts +++ /dev/null @@ -1,288 +0,0 @@ -/// - -class ArrayListTest extends UnitTestClass { - private _list : ArrayList; - - setUp() : void { - this._list = new ArrayList(); - } - - tearDown() : void { - this._list = null; - } - - ArrayListAddTest() : void { - // Arrange - var i : number = 7; - var a : Array; - - // Act - this._list.add(i); - - // Assert - a = this._list.toArray(); - Assert.isNotNull(a); - Assert.areEqual(1, a.length); - Assert.areEqual(i, a[0]); - } - - ArrayListCloneTest() : void { - // Arrange - var a : Array, b : Array; - var clonedList : IList; - - this._list.add(5); - this._list.add(12); - - // Act - clonedList = this._list.clone(); - - // Assert - a = this._list.toArray(); - b = clonedList.toArray(); - Assert.isNotNull(a); - Assert.isNotNull(b); - Assert.areEqual(2, a.length); - Assert.areEqual(2, b.length); - Assert.areEqual(a[0], b[0]); - Assert.areEqual(a[1], b[1]); - } - - ArrayListFindFirstTest() : void { - // Arrange - var i : number; - - this._list.add(5); - this._list.add(4); - this._list.add(6); - - // Act - i = this._list.findFirst(x => x < 5); - - // Assert - Assert.areEqual(4, i); - } - - ArrayListFindFirstNullTest() : void { - // Arrange - var i : number; - - this._list.add(5); - this._list.add(4); - this._list.add(6); - - // Act - i = this._list.findFirst(x => x < 4); - - // Assert - Assert.isTrue(i == null); - } - - ArrayListForEachTest() : void { - // Arrange - var acc : number = 0; - - this._list.add(3); - this._list.add(4); - this._list.add(5); - - // Act - this._list.forEach( - (x) => { - if (x < 5) { - acc++; - } - } - ); - - // Assert - Assert.areEqual(2, acc); - } - - ArrayListGetAtTest() : void { - // Arrange - var i : number; - - this._list.add(3); - this._list.add(4); - - // Act - i = this._list.getAt(1); - - // Assert - Assert.areEqual(4, i); - } - - ArrayListGetLengthTest() : void { - // Arrange - var l : number; - - this._list.add(3); - this._list.add(4); - - // Act - l = this._list.getLength(); - - // Assert - Assert.areEqual(2, l); - } - - ArrayListGetLengthEmptyListTest() : void { - // Arrange - var l : number; - - // Act - l = this._list.getLength(); - - // Assert - Assert.areEqual(0, l); - } - - ArrayListInsertAtTest() : void { - // Arrange - var a : Array; - - this._list.add(3); - this._list.add(5); - - // Act - this._list.insertAt(1, 4); - - // Assert - a = this._list.toArray(); - Assert.isNotNull(a); - Assert.areEqual(3, a.length); - Assert.areEqual(3, a[0]); - Assert.areEqual(4, a[1]); - Assert.areEqual(5, a[2]); - } - - ArrayListInsertAtAppendTest() : void { - // Arrange - var a : Array; - - this._list.add(3); - this._list.add(4); - - // Act - this._list.insertAt(2, 5); - - // Assert - a = this._list.toArray(); - Assert.isNotNull(a); - Assert.areEqual(3, a.length); - Assert.areEqual(3, a[0]); - Assert.areEqual(4, a[1]); - Assert.areEqual(5, a[2]); - } - - ArrayListInsertAtAppendEmptyListTest() : void { - // Arrange - var a : Array; - - // Act - this._list.insertAt(0, 5); - - // Assert - a = this._list.toArray(); - Assert.isNotNull(a); - Assert.areEqual(1, a.length); - Assert.areEqual(5, a[0]); - } - - ArrayListInsertAtNegativeIndexTest() : void { - // Arrange - - // Act - Assert.throws( - () => { - this._list.insertAt(-5, 2); - } - ); - - // Assert - } - - ArrayListInsertAtBadIndexTest() : void { - // Arrange - - // Act - Assert.throws( - () => { - this._list.insertAt(5, 2); - } - ); - - // Assert - } - - ArrayListMapTest() : void { - // Arrange - var a : Array; - - this._list.add(1); - this._list.add(2); - this._list.add(3); - - // Act - this._list.map(x => x * x); - - // Assert - a = this._list.toArray(); - Assert.isNotNull(a); - Assert.areEqual(3, a.length); - Assert.areEqual(1, a[0]); - Assert.areEqual(4, a[1]); - Assert.areEqual(9, a[2]); - } - - ArrayListRemoveTest() : void { - // Arrange - var a : Array; - - this._list.add(1); - this._list.add(2); - this._list.add(3); - - // Act - this._list.remove(2); - - // Assert - a = this._list.toArray(); - Assert.isNotNull(a); - Assert.areEqual(2, a.length); - Assert.areEqual(1, a[0]); - Assert.areEqual(3, a[1]); - } - - ArrayListRemoveUnvalidValueTest() : void { - // Arrange - var a : Array; - - this._list.add(1); - this._list.add(2); - this._list.add(3); - - // Act - Assert.throws(() => this._list.remove(5)); - } - - ArrayListToArrayTest() : void { - // Arrange - var a : Array; - - this._list.add(1); - this._list.add(2); - this._list.add(3); - - // Act - a = this._list.toArray(); - - // Assert - Assert.isNotNull(a); - Assert.areEqual(3, a.length); - Assert.areEqual(1, a[0]); - Assert.areEqual(2, a[1]); - Assert.areEqual(3, a[2]); - } -} diff --git a/testing/src/system/collections/DictionaryTest.ts b/testing/src/system/collections/DictionaryTest.ts deleted file mode 100644 index cb3c2c6..0000000 --- a/testing/src/system/collections/DictionaryTest.ts +++ /dev/null @@ -1,164 +0,0 @@ -/// - -class DictionaryTest extends UnitTestClass { - private _dict : Dictionary; - - setUp() : void { - this._dict = new Dictionary(); - } - - tearDown() : void { - this._dict = null; - } - - DictionaryAddTest() : void { - // Arrange - var p1 : Mocks.Utils.Person, p2 : Mocks.Utils.Person; - - p1 = new Mocks.Utils.Person('Bruce', 'Willis'); - p2 = new Mocks.Utils.Person('Mickey', 'Rourke'); - - // Act - this._dict.add(p1.lastName, p1); - this._dict.add(p2.lastName, p2); - - // Assert - Assert.areEqual(2, this._dict.getLength()); - Assert.isTrue(p1.equals(this._dict.get(p1.lastName))); - Assert.isTrue(p2.equals(this._dict.get(p2.lastName))); - } - - DictionaryCloneTest() : void { - // Arrange - var p1 : Mocks.Utils.Person, p2 : Mocks.Utils.Person; - var outcome : IDictionary; - - p1 = new Mocks.Utils.Person('Bruce', 'Willis'); - p2 = new Mocks.Utils.Person('Mickey', 'Rourke'); - this._dict.add(p1.lastName, p1); - this._dict.add(p2.lastName, p2); - - // Act - outcome = this._dict.clone(); - - // Assert - Assert.isNotNull(outcome); - Assert.areEqual(this._dict.getLength(), outcome.getLength()); - Assert.areEqual(this._dict.get(p1.lastName), outcome.get(p1.lastName)); - Assert.areEqual(this._dict.get(p2.lastName), outcome.get(p2.lastName)); - } - - DictionaryContainsKeyTest() : void { - // Arrange - var p : Mocks.Utils.Person; - var b : boolean; - - p = new Mocks.Utils.Person('Al', 'Pacino'); - this._dict.add(p.lastName, p); - - // Act - b = this._dict.containsKey('Pacino'); - - // Assert - Assert.isTrue(b); - } - - DictionaryContainsKeyMissingKeyTest() : void { - // Arrange - var p : Mocks.Utils.Person; - var b : boolean; - - p = new Mocks.Utils.Person('Al', 'Pacino'); - this._dict.add(p.lastName, p); - - // Act - b = this._dict.containsKey('foo'); - - // Assert - Assert.isFalse(b); - } - - DictionaryForEachTest() : void { - // Arrange - var acc : StringBuffer; - var p1 : Mocks.Utils.Person, p2 : Mocks.Utils.Person, p3 : Mocks.Utils.Person, p4 : Mocks.Utils.Person; - - p1 = new Mocks.Utils.Person('John', 'Lennon'); - p2 = new Mocks.Utils.Person('Paul', 'McCartney'); - p3 = new Mocks.Utils.Person('Ringo', 'Starr'); - p4 = new Mocks.Utils.Person('George', 'Harrison'); - this._dict.add(p1.lastName, p1); - this._dict.add(p2.lastName, p2); - this._dict.add(p3.lastName, p3); - this._dict.add(p4.lastName, p4); - - acc = new StringBuffer(); - - // Act - this._dict.forEach((k, v) => acc.append(v.firstName)); - - // Assert - Assert.isTrue(StringHelper.compare('JohnPaulRingoGeorge', acc.toString())); - } - - DictionaryGetTest() : void { - // Arrange - var p : Mocks.Utils.Person, outcome : Mocks.Utils.Person; - - p = new Mocks.Utils.Person('Samuel L.', 'Jackson'); - this._dict.add(p.lastName, p); - - // Act - outcome = this._dict.get(p.lastName); - - // Assert - Assert.isTrue(p.equals(outcome)); - } - - DictionaryGetFailTest() : void { - // Arrange - var p : Mocks.Utils.Person, outcome : Mocks.Utils.Person; - - p = new Mocks.Utils.Person('Samuel L.', 'Jackson'); - this._dict.add(p.lastName, p); - - // Act & Assert - Assert.throws( - () => { - outcome = this._dict.get('foo'); - } - ); - } - - DictionaryGetLengthTest() : void { - // Arrange - var p1 : Mocks.Utils.Person, p2 : Mocks.Utils.Person, p3 : Mocks.Utils.Person, p4 : Mocks.Utils.Person; - var n : number; - - p1 = new Mocks.Utils.Person('John', 'Lennon'); - p2 = new Mocks.Utils.Person('Paul', 'McCartney'); - p3 = new Mocks.Utils.Person('Ringo', 'Starr'); - p4 = new Mocks.Utils.Person('George', 'Harrison'); - this._dict.add(p1.lastName, p1); - this._dict.add(p2.lastName, p2); - this._dict.add(p3.lastName, p3); - this._dict.add(p4.lastName, p4); - - // Act - n = this._dict.getLength(); - - // Assert - Assert.areEqual(4, n); - } - - DictionaryGetLengthEmptyListTest() : void { - // Arrange - var n : number; - - // Act - n = this._dict.getLength(); - - // Assert - Assert.areEqual(0, n); - } -} diff --git a/testing/src/system/collections/QueueTest.ts b/testing/src/system/collections/QueueTest.ts deleted file mode 100644 index c785989..0000000 --- a/testing/src/system/collections/QueueTest.ts +++ /dev/null @@ -1,53 +0,0 @@ -/// - -class QueueTest extends UnitTestClass { - private _queue : Queue; - - setUp() : void { - this._queue = new Queue(); - } - - tearDown() : void { - this._queue = null; - } - - QueuePushTest() : void { - // Arrange - - // Act - this._queue.push(10); - this._queue.push(45); - - // Assert - Assert.areEqual(2, this._queue.getLength()); - } - - QueueTopTest() : void { - // Arrange - var i : number; - - this._queue.push(56); - this._queue.push(45); - - // Act - i = this._queue.top(); - - // Assert - Assert.areEqual(56, i); - } - - QueuePopTest() : void { - // Arrange - var i : number; - - this._queue.push(56); - this._queue.push(45); - - // Act - i = this._queue.pop(); - - // Assert - Assert.areEqual(56, i); - Assert.areEqual(1, this._queue.getLength()); - } -} diff --git a/testing/src/system/storage/ActiveRecord/ActiveRecordObjectTest.ts b/testing/src/system/storage/ActiveRecord/ActiveRecordObjectTest.ts index ff608c9..4322f36 100644 --- a/testing/src/system/storage/ActiveRecord/ActiveRecordObjectTest.ts +++ b/testing/src/system/storage/ActiveRecord/ActiveRecordObjectTest.ts @@ -106,7 +106,7 @@ class ActiveRecordObjectTest extends UnitTestClass { // Act this._aro.find( 'foo', - new Pair('id', 15), + new KeyValuePair('id', 15), (outcome) => { // Assert Assert.areEqual('SELECT * FROM foo WHERE LOWER(id) = LOWER(?)', this._transaction.getStatement()); @@ -133,7 +133,7 @@ class ActiveRecordObjectTest extends UnitTestClass { // Act this._aro.find( 'foo', - new Pair('id', 15), + new KeyValuePair('id', 15), (outcome) => { // Assert Assert.areEqual('SELECT * FROM foo WHERE LOWER(id) = LOWER(?)', this._transaction.getStatement()); @@ -163,7 +163,9 @@ class ActiveRecordObjectTest extends UnitTestClass { // Assert Assert.isTrue(success); Assert.areEqual('INSERT INTO bar VALUES (?, ?, ?)', this._transaction.getStatement()); - Assert.areEqual(data.toArray(), this._transaction.getArguments()); + Assert.areEqual(data.getAt(0), this._transaction.getArguments()[0]); + Assert.areEqual(data.getAt(1), this._transaction.getArguments()[1]); + Assert.areEqual(data.getAt(2), this._transaction.getArguments()[2]); obs.success(); } @@ -181,7 +183,7 @@ class ActiveRecordObjectTest extends UnitTestClass { // Act this._aro.update( 'people', - new Pair('id', 15), + new KeyValuePair('id', 15), data, (success) => { // Assert @@ -207,7 +209,7 @@ class ActiveRecordObjectTest extends UnitTestClass { // Act this._aro.delete( 'foobar', - new Pair('id', 15), + new KeyValuePair('id', 15), (success) => { // Assert Assert.isTrue(success);