-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15d5493
commit b2ad4bc
Showing
73 changed files
with
3,007 additions
and
232 deletions.
There are no files selected for viewing
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
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); | ||
} | ||
|
||
} |
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
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
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"); | ||
} | ||
|
||
} |
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
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
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
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; | ||
|
||
} |
Oops, something went wrong.