Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
This was horrible :(
  • Loading branch information
Mr-Kanister committed Nov 20, 2024
2 parents 5db83e8 + d9138b3 commit fd6bf31
Show file tree
Hide file tree
Showing 41 changed files with 1,015 additions and 146 deletions.
4 changes: 2 additions & 2 deletions src/adap-b01/coordinates/Coordinate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class Coordinate {
public getHashCode(): number {
let hashCode: number = 0;
const s: string = this.asDataString();
for (let i = 0; i < s.length; i++) {
let c = s.charCodeAt(i);
for (let i: number = 0; i < s.length; i++) {
let c: number = s.charCodeAt(i);
hashCode = (hashCode << 5) - hashCode + c;
hashCode |= 0;
}
Expand Down
24 changes: 20 additions & 4 deletions src/adap-b01/names/Name.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
export class Name {
export const DEFAULT_DELIMITER: string = '.';
export const ESCAPE_CHARACTER = '\\';

public readonly DEFAULT_DELIMITER: string = '.';
private readonly 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[] = [];
private delimiter: string = this.DEFAULT_DELIMITER;

/** Expects that all Name components are properly masked */
constructor(other: string[], delimiter?: string) {
this.components = other;
this.delimiter = delimiter ?? this.delimiter;
Expand All @@ -24,6 +37,7 @@ export class Name {
}

/** @methodtype set-method */
/** Expects that new Name component c is properly masked */
public setComponent(i: number, c: string): void {
if (i < 0 || i >= this.getNoComponents()) throw new Error("Index out of bounds");
this.components[i] = c;
Expand All @@ -36,12 +50,14 @@ export class Name {
}

/** @methodtype command-method */
/** Expects that new Name component c is properly masked */
public insert(i: number, c: string): void {
if (i < 0 || i > this.getNoComponents()) throw new Error("Index out of bounds");
this.components = this.components.slice(0, i).concat(c, this.components.slice(i));
}

/** @methodtype command-method */
/** Expects that new Name component c is properly masked */
public append(c: string): void {
this.components.push(c);
}
Expand Down
29 changes: 21 additions & 8 deletions src/adap-b02/common/Printable.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
export const DEFAULT_DELIMITER: string = '.';
export const ESCAPE_CHARACTER = '\\';

export interface Printable {

/**
* Returns human-readable representation of this object
* Expects that delimiter is a single character
/**
* 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
* The delimiter character must be a single character
*/
asString(delChar?: string): string;
asString(delimiter?: string): string;

/**
* Returns machine-readable representation of this object
*/
asDataString(): string;
/**
* 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
* Different fields of the object are separated by the delimiter character
*/
asDataString(): string;

/**
* Returns delimiter char; must be a single character
*/
getDelimiterCharacter(): string;

}
8 changes: 2 additions & 6 deletions src/adap-b02/coordinates/CartesianCoordinate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ export class CartesianCoordinate implements Coordinate {
public getHashCode(): number {
let hashCode: number = 0;
const s: string = this.asDataString();
for (let i = 0; i < s.length; i++) {
let c = s.charCodeAt(i);
for (let i: number = 0; i < s.length; i++) {
let c: number = s.charCodeAt(i);
hashCode = (hashCode << 5) - hashCode + c;
hashCode |= 0;
}
return hashCode;
}

public clone(): Coordinate {
return new CartesianCoordinate(this.doGetX(), this.doGetY());
}

public reset(): void {
this.initialize(0, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/adap-b02/coordinates/Coordinate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Equality } from "../common/Equality";
import { Cloneable } from "../common/Cloneable";

export interface Coordinate extends Equality, Cloneable {
export interface Coordinate extends Equality {

reset(): void;

Expand Down
8 changes: 2 additions & 6 deletions src/adap-b02/coordinates/PolarCoordinate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ export class PolarCoordinate implements Coordinate {
public getHashCode(): number {
let hashCode: number = 0;
const s: string = this.asDataString();
for (let i = 0; i < s.length; i++) {
let c = s.charCodeAt(i);
for (let i: number = 0; i < s.length; i++) {
let c: number = s.charCodeAt(i);
hashCode = (hashCode << 5) - hashCode + c;
hashCode |= 0;
}
return hashCode;
}

public clone(): Coordinate {
return new PolarCoordinate(this.doGetR(), this.doGetPhi());
}

public reset(): void {
this.initialize(0, 0);
}
Expand Down
30 changes: 9 additions & 21 deletions src/adap-b02/names/Name.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Printable } from "../common/Printable";

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.
Expand All @@ -18,35 +15,24 @@ export const ESCAPE_CHARACTER = '\\';
export interface Name extends Printable {

/**
* 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
* Returns true, if number of components == 0; else false
*/
asString(delimiter?: string): string;
isEmpty(): boolean;

/**
* 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
* Returns number of components in Name instance
*/
asDataString(): string;

isEmpty(): boolean;

getDelimiterCharacter(): string;

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

getComponent(i: number): string;

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

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

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

remove(i: number): void;
Expand All @@ -57,4 +43,6 @@ export interface Name extends Printable {
*/
concat(other: Name): void;

}
concat(other: Name): void;

}
3 changes: 2 additions & 1 deletion src/adap-b02/names/StringArrayName.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Name, DEFAULT_DELIMITER, ESCAPE_CHARACTER } from "./Name";
import { DEFAULT_DELIMITER, ESCAPE_CHARACTER } from "../common/Printable";
import { Name } from "./Name";

export class StringArrayName implements Name {

Expand Down
20 changes: 10 additions & 10 deletions src/adap-b02/names/StringName.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Name, DEFAULT_DELIMITER, ESCAPE_CHARACTER } from "./Name";
import { DEFAULT_DELIMITER, ESCAPE_CHARACTER } from "../common/Printable";
import { Name } from "./Name";

export class StringName implements Name {

protected delimiter: string = DEFAULT_DELIMITER;

protected name: string = "";
protected length: number = 0;
protected noComponents: number = 0;

constructor(other: string, delimiter?: string) {
this.name = other;
Expand All @@ -16,7 +16,7 @@ export class StringName implements Name {
// specified.
this.delimiter = delimiter ?? this.delimiter;
const regex = new RegExp(`(?<!\\\\)\\${this.getDelimiterCharacter()}`);
this.length = other.split(regex).length;
this.noComponents = other.split(regex).length;
}

public asString(delimiter: string = this.delimiter): string {
Expand Down Expand Up @@ -46,15 +46,15 @@ export class StringName implements Name {
}

public isEmpty(): boolean {
return this.length ? false : true;
return this.noComponents ? false : true;
}

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

public getNoComponents(): number {
return this.length;
return this.noComponents;
}

public getComponent(i: number): string {
Expand All @@ -81,12 +81,12 @@ export class StringName implements Name {
let array = this.name.split(regex);
array.splice(i, 0, c);
this.name = array.join(this.delimiter);
this.length += 1;
this.noComponents += 1;
}

public append(c: string): void {
this.name += this.delimiter + c;
this.length += 1;
this.noComponents += 1;
}

public remove(i: number): void {
Expand All @@ -97,14 +97,14 @@ export class StringName implements Name {
let array = this.name.split(regex);
array.splice(i, 1);
this.name = array.join(this.delimiter);
this.length -= 1;
this.noComponents -= 1;
}

public concat(other: Name): void {
if (other.getDelimiterCharacter() !== this.getDelimiterCharacter())
throw new Error("The name has the wrong delimiter.");

this.length += other.getNoComponents();
this.noComponents += other.getNoComponents();
this.name += this.delimiter + other.asDataString();
}
}
29 changes: 21 additions & 8 deletions src/adap-b03/common/Printable.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
export const DEFAULT_DELIMITER: string = '.';
export const ESCAPE_CHARACTER = '\\';

export interface Printable {

/**
* Returns human-readable representation of this object
* Expects that delimiter is a single character
/**
* 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
* The delimiter character must be a single character
*/
asString(delChar?: string): string;
asString(delimiter?: string): string;

/**
* Returns machine-readable representation of this object
*/
asDataString(): string;
/**
* 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
* Different fields of the object are separated by the delimiter character
*/
asDataString(): string;

/**
* Returns delimiter char; must be a single character
*/
getDelimiterCharacter(): string;

}
12 changes: 6 additions & 6 deletions src/adap-b03/coordinates/AbstractCoordinate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { Coordinate } from "./Coordinate";

export abstract class AbstractCoordinate implements Coordinate {

public toString(): string {
return this.asDataString();
}

public asDataString(): string {
return this.doGetX() + "#" + this.doGetY();
}
Expand All @@ -13,18 +17,14 @@ export abstract class AbstractCoordinate implements Coordinate {
public getHashCode(): number {
let hashCode: number = 0;
const s: string = this.asDataString();
for (let i = 0; i < s.length; i++) {
let c = s.charCodeAt(i);
for (let i: number = 0; i < s.length; i++) {
let c: number = s.charCodeAt(i);
hashCode = (hashCode << 5) - hashCode + c;
hashCode |= 0;
}
return hashCode;
}

public clone(): Coordinate {
return { ...this };
}

abstract reset(): void;

public getX(): number {
Expand Down
2 changes: 1 addition & 1 deletion src/adap-b03/coordinates/Coordinate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Equality } from "../common/Equality";
import { Cloneable } from "../common/Cloneable";

export interface Coordinate extends Equality, Cloneable {
export interface Coordinate extends Equality {

reset(): void;

Expand Down
3 changes: 2 additions & 1 deletion src/adap-b03/names/AbstractName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Name, DEFAULT_DELIMITER } from "./Name";
import { DEFAULT_DELIMITER } from "../common/Printable";
import { unescape, escape } from "./utils";
import {Name }from "./Name";

export abstract class AbstractName implements Name {

Expand Down
Loading

0 comments on commit fd6bf31

Please sign in to comment.