Skip to content

Commit

Permalink
Update for B05 homework
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkriehle committed Nov 25, 2024
1 parent 15d5493 commit b2ad4bc
Show file tree
Hide file tree
Showing 73 changed files with 3,007 additions and 232 deletions.
92 changes: 92 additions & 0 deletions src/adap-b01/names-solution/Name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
export const DEFAULT_DELIMITER: string = '.';
export const ESCAPE_CHARACTER = '\\';

/**
* A name is a sequence of string components separated by a delimiter character.
* Special characters within the string may need masking, if they are to appear verbatim.
* There are only two special characters, the delimiter character and the escape character.
* The escape character can't be set, the delimiter character can.
*
* Homogenous name examples
*
* "oss.cs.fau.de" is a name with four name components and the delimiter character '.'.
* "///" is a name with four empty components and the delimiter character '/'.
* "Oh\.\.\." is a name with one component, if the delimiter character is '.'.
*/
export class Name {

private delimiter: string = DEFAULT_DELIMITER;
private components: string[] = [];

/** Expects that all Name components are properly masked */
constructor(other: string[], delimiter?: string) {
if (delimiter != undefined) {
this.delimiter = delimiter;
}

if (other != undefined) {
this.components = [...other];
} else {
this.components = [];
}
}

/**
* Returns a human-readable representation of the Name instance using user-set control characters
* Control characters are not escaped (creating a human-readable string)
* Users can vary the delimiter character to be used
*/
public asString(delimiter: string = this.delimiter): string {
let result = "";
let noComponents = this.getNoComponents();
for (let i:number = 0; i < noComponents; i++) {
result += this.getComponent(i);
if (i < (noComponents - 1)) {
result += delimiter;
}
}
return result;
}

/**
* Returns a machine-readable representation of Name instance using default control characters
* Machine-readable means that from a data string, a Name can be parsed back in
* The control characters in the data string are the default characters
*/
public asDataString(): string {
return this.asString(DEFAULT_DELIMITER);
}

public getDelimiterCharacter(): string {
return this.delimiter;
}

public getComponent(i: number): string {
return this.components[i];
}

/** Expects that new Name component c is properly masked */
public setComponent(i: number, c: string): void {
this.components[i] = c;
}

/** Returns number of components in Name instance */
public getNoComponents(): number {
return this.components.length;
}

/** Expects that new Name component c is properly masked */
public insert(i: number, c: string): void {
this.components.splice(i, 0, c);
}

/** Expects that new Name component c is properly masked */
public append(c: string): void {
this.components.splice(this.components.length, 0, c);
}

public remove(i: number): void {
this.components.splice(i, 1);
}

}
18 changes: 9 additions & 9 deletions src/adap-b01/names/Name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Name {

/** Expects that all Name components are properly masked */
constructor(other: string[], delimiter?: string) {
throw new Error("needs implementation");
throw new Error("needs implementation or deletion");
}

/**
Expand All @@ -29,7 +29,7 @@ export class Name {
* Users can vary the delimiter character to be used
*/
public asString(delimiter: string = this.delimiter): string {
throw new Error("needs implementation");
throw new Error("needs implementation or deletion");
}

/**
Expand All @@ -38,35 +38,35 @@ export class Name {
* The control characters in the data string are the default characters
*/
public asDataString(): string {
throw new Error("needs implementation");
throw new Error("needs implementation or deletion");
}

public getComponent(i: number): string {
throw new Error("needs implementation");
throw new Error("needs implementation or deletion");
}

/** Expects that new Name component c is properly masked */
public setComponent(i: number, c: string): void {
throw new Error("needs implementation");
throw new Error("needs implementation or deletion");
}

/** Returns number of components in Name instance */
public getNoComponents(): number {
throw new Error("needs implementation");
throw new Error("needs implementation or deletion");
}

/** Expects that new Name component c is properly masked */
public insert(i: number, c: string): void {
throw new Error("needs implementation");
throw new Error("needs implementation or deletion");
}

/** Expects that new Name component c is properly masked */
public append(c: string): void {
throw new Error("needs implementation");
throw new Error("needs implementation or deletion");
}

public remove(i: number): void {
throw new Error("needs implementation");
throw new Error("needs implementation or deletion");
}

}
27 changes: 21 additions & 6 deletions src/adap-b02/files1/File.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
export class File {

public isOpen(): boolean {
throw new Error("no implementation");
throw new Error("incomplete example code");
}

public isClosed(): boolean {
throw new Error("no implementation");
throw new Error("incomplete example code");
}

public open(): void {
this.assertIsClosedFile();
throw new Error("incomplete example code");
}

public read(): Object[] {
this.assertIsOpenFile();
throw new Error("no implementation");
throw new Error("incomplete example code");
}

public write(data: Object[]): void {
this.assertIsOpenFile();
throw new Error("incomplete example code");
}

public close(): void {
this.assertIsOpenFile();
throw new Error("incomplete example code");
}

public delete(): void {
this.assertIsClosedFile();
throw new Error("no implementation");
throw new Error("incomplete example code");
}

protected assertIsOpenFile(): void {
throw new Error("no implementation");
throw new Error("incomplete example code");
}

protected assertIsClosedFile(): void {
throw new Error("no implementation");
throw new Error("incomplete example code");
}

}
2 changes: 2 additions & 0 deletions src/adap-b02/files2/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ export interface File {
isOpen(): boolean;
isClosed(): boolean;

open(): void;
read(): any[];
write(data: any[]): void;
close(): void;
delete(): void;

}
24 changes: 17 additions & 7 deletions src/adap-b02/files2/ObjFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,44 @@ export class ObjFile implements File {
}

public isOpen(): boolean {
throw new Error("no implementation");
throw new Error("incomplete example code");
}

public isClosed(): boolean {
throw new Error("no implementation");
throw new Error("incomplete example code");
}

public open(): void {
this.assertIsClosedFile();
throw new Error("incomplete example code");
}

public read(): Object[] {
this.assertIsOpenFile();
throw new Error("no implementation");
throw new Error("incomplete example code");
}

public write(data: Object[]): void {
this.assertIsOpenFile();
throw new Error("no implementation");
throw new Error("incomplete example code");
}

public close(): void {
this.assertIsOpenFile();
throw new Error("incomplete example code");
}

public delete(): void {
this.assertIsClosedFile();
throw new Error("no implementation");
throw new Error("incomplete example code");
}

protected assertIsOpenFile(): void {
throw new Error("no implementation");
throw new Error("incomplete example code");
}

protected assertIsClosedFile(): void {
throw new Error("no implementation");
throw new Error("incomplete example code");
}

}
42 changes: 42 additions & 0 deletions src/adap-b02/names-solution/Name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Printable } from "../common/Printable";

/**
* A name is a sequence of string components separated by a delimiter character.
* Special characters within the string may need masking, if they are to appear verbatim.
* There are only two special characters, the delimiter character and the escape character.
* The escape character can't be set, the delimiter character can.
*
* Homogenous name examples
*
* "oss.cs.fau.de" is a name with four name components and the delimiter character '.'.
* "///" is a name with four empty components and the delimiter character '/'.
* "Oh\.\.\." is a name with one component, if the delimiter character is '.'.
*/
export interface Name extends Printable {

/**
* Returns true, if number of components == 0; else false
*/
isEmpty(): boolean;

/**
* Returns number of components in Name instance
*/
getNoComponents(): number;

getComponent(i: number): string;

/** Expects that new Name component c is properly masked */
setComponent(i: number, c: string): void;

/** Expects that new Name component c is properly masked */
insert(i: number, c: string): void;

/** Expects that new Name component c is properly masked */
append(c: string): void;

remove(i: number): void;

concat(other: Name): void;

}
Loading

0 comments on commit b2ad4bc

Please sign in to comment.