This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Specific class for a RealmList<Bar> field | |
public class BarListParcelConverter extends RealmListParcelConverter<Bar> { | |
@Override | |
public void itemToParcel(Bar input, Parcel parcel) { | |
parcel.writeParcelable(Parcels.wrap(input), 0); | |
} | |
@Override | |
public Bar itemFromParcel(Parcel parcel) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* HttpURLConnection网络请求工具类 | |
*/ | |
public class HttpUtil { | |
/** | |
* Get请求 | |
*/ | |
public static void sendGetRequest( | |
final String urlString, final HttpCallbackListener listener) { | |
// 因为网络请求是耗时操作,所以需要另外开启一个线程来执行该任务。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://stackoverflow.com/questions/40398072/singleton-with-parameter-in-kotlin | |
class TasksLocalDataSource private constructor(context: Context) : TasksDataSource { | |
private val mDbHelper: TasksDbHelper | |
init { | |
// You cannot pass null in kotlin unless you are using `context: Context?` | |
// therefore, checking null is useless | |
// checkNotNull(context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 78: Promise - API overview | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('`Promise` API overview', function() { | |
it('`new Promise()` requires a function as param', () => { | |
const param = () => {}; | |
assert.doesNotThrow(() => { new Promise(param); }); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 77: Promise - chaining | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('chaining multiple promises can enhance readability', () => { | |
describe('prerequisites for understanding', function() { | |
it('reminder: the test passes when a fulfilled promise is returned', function() { | |
return Promise.resolve('I should fulfill.'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 76: Promise - creation | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('a promise can be created in multiple ways', function() { | |
describe('creating a promise fails when', function() { | |
it('using `Promise` as a function', function() { | |
function callPromiseAsFunction() { | |
Promise(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 75: Promise - basics | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('a Promise represents an operation that hasn`t completed yet, but is expected in the future', function() { | |
it('`Promise` is a global function', function() { | |
const expectedType = 'function'; | |
assert.equal(typeof Promise, expectedType); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 74: String - `endsWith()` | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('`str.endsWith(searchString)` determines whether `str` ends with `searchString`.', function() { | |
const s = 'el fin'; | |
describe('1st parameter, the string to search for', function() { | |
it('works with just a character', function() { | |
const doesEndWith = s.endsWith('n'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 73: Generator - `return` inside a generator is special | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('`return` in a generator function is special', function() { | |
describe('the returned value is an IteratorResult (just like any value returned via `yield`)', function() { | |
it('returns an IteratorResult (an object with the properties `value` and `done`)', function() { | |
function* generatorFunction() { return 1; } | |
const returned = generatorFunction().next(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 72: String - `startsWith()` | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('`str.startsWith(searchString)` determines whether `str` begins with `searchString`.', function() { | |
const s = 'the string s'; | |
describe('1st parameter, the string to search for', function() { | |
it('works with just a character', function() { | |
const actual = s.startsWith('t'); |