|
@@ -1,12 +1,14 @@
|
|
-import {Book, Librarian, Logger as DamageLogger} from './interfaces';
|
|
|
|
|
|
+import {Book, Librarian, Logger as DamageLogger, Magazine} from './interfaces';
|
|
import {Category} from './enums';
|
|
import {Category} from './enums';
|
|
-import {Catalog, ReferenceItem, UniversityLibrarian} from './classes';
|
|
|
|
|
|
+import {ReferenceItem, UniversityLibrarian} from './classes';
|
|
import {
|
|
import {
|
|
CalculateLateFees as CalcFee,
|
|
CalculateLateFees as CalcFee,
|
|
- MaxBooksAllowed, Purge
|
|
|
|
|
|
+ MaxBooksAllowed,
|
|
|
|
+ Purge
|
|
} from './lib/utilityfunctions';
|
|
} from './lib/utilityfunctions';
|
|
import refBook from './encyclopedia';
|
|
import refBook from './encyclopedia';
|
|
import {Books, LogAndReturn} from './generics';
|
|
import {Books, LogAndReturn} from './generics';
|
|
|
|
+import Shelf from "./shelf";
|
|
|
|
|
|
export function GetAllBooks(): Book[] {
|
|
export function GetAllBooks(): Book[] {
|
|
const books = [
|
|
const books = [
|
|
@@ -218,8 +220,8 @@ function genericFunctionDemo() {
|
|
console.log('Returned mag', someMag);
|
|
console.log('Returned mag', someMag);
|
|
}
|
|
}
|
|
|
|
|
|
-function purgedemo() {
|
|
|
|
- let inventory: Books = [
|
|
|
|
|
|
+function getBooksInventory(): Books {
|
|
|
|
+ return [
|
|
{
|
|
{
|
|
author: 'K & R',
|
|
author: 'K & R',
|
|
available: true,
|
|
available: true,
|
|
@@ -249,7 +251,27 @@ function purgedemo() {
|
|
title: 'Cool autoexec.bat scripts',
|
|
title: 'Cool autoexec.bat scripts',
|
|
}
|
|
}
|
|
];
|
|
];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function getMagazinesInventory(): Array<Magazine> {
|
|
|
|
+ return [
|
|
|
|
+ {
|
|
|
|
+ title: 'Programming Language Monthly',
|
|
|
|
+ publisher: 'Code Mags',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ publisher: 'College Press',
|
|
|
|
+ title: 'Literary Fiction Quarterly',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ publisher: 'GSU',
|
|
|
|
+ title: 'Give Points',
|
|
|
|
+ }
|
|
|
|
+ ];
|
|
|
|
+}
|
|
|
|
|
|
|
|
+function purgedemo() {
|
|
|
|
+ let inventory: Array<Book> = getBooksInventory();
|
|
// Inventory is accepted because Books is an alias for Array<Book>, so the
|
|
// Inventory is accepted because Books is an alias for Array<Book>, so the
|
|
// signature actually matches.
|
|
// signature actually matches.
|
|
let purgedBooks: Books = Purge(inventory);
|
|
let purgedBooks: Books = Purge(inventory);
|
|
@@ -261,9 +283,19 @@ function purgedemo() {
|
|
}
|
|
}
|
|
|
|
|
|
function genericClassDemo() {
|
|
function genericClassDemo() {
|
|
- let cat = new Catalog<Book>();
|
|
|
|
- let books = GetAllBooks();
|
|
|
|
- cat.addItem(books[0]);
|
|
|
|
|
|
+ let bookShelf: Shelf<Book> = new Shelf<Book>();
|
|
|
|
+ getBooksInventory().forEach(book => bookShelf.add(book));
|
|
|
|
+ let firstBook: Book = bookShelf.getFirst();
|
|
|
|
+ console.log(firstBook);
|
|
|
|
+
|
|
|
|
+ let magazineShelf: Shelf<Magazine> = new Shelf<Magazine>();
|
|
|
|
+ getMagazinesInventory().forEach(mag => magazineShelf.add(mag));
|
|
|
|
+ let firstMagazine: Magazine = magazineShelf.getFirst();
|
|
|
|
+ console.log(firstMagazine);
|
|
|
|
+
|
|
|
|
+ let numberShelf: Shelf<number> = new Shelf<number>();
|
|
|
|
+ [5, 10, 15].forEach(num => numberShelf.add(num));
|
|
|
|
+ console.log(numberShelf);
|
|
}
|
|
}
|
|
|
|
|
|
false && bookDemo();
|
|
false && bookDemo();
|
|
@@ -271,4 +303,4 @@ false && classDemo();
|
|
false && importDemo();
|
|
false && importDemo();
|
|
false && genericFunctionDemo();
|
|
false && genericFunctionDemo();
|
|
false && purgedemo();
|
|
false && purgedemo();
|
|
-false && genericClassDemo();
|
|
|
|
|
|
+genericClassDemo();
|