Skip to content

Commit

Permalink
resolve conflicts after update the project
Browse files Browse the repository at this point in the history
  • Loading branch information
Miro committed Dec 8, 2024
1 parent d7cc7a6 commit 8bd8804
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 59 deletions.
1 change: 0 additions & 1 deletion src/adap-b03/coordinates/Coordinate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Equality } from "../common/Equality";
import { Cloneable } from "../common/Cloneable";

export interface Coordinate extends Equality {

Expand Down
20 changes: 10 additions & 10 deletions src/adap-b04/names/AbstractName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export abstract class AbstractName implements Name {

private setDelimiter(delimiter: string): void {
// Contract: Delimiter must be non-empty string
IllegalArgumentException.assertCondition(
IllegalArgumentException.assert(
!(!delimiter || delimiter.length <= 0),
"Delimiter must be a non-empty string."
);
Expand All @@ -24,7 +24,7 @@ export abstract class AbstractName implements Name {

// Contract: Must return a non-empty string
public asString(delimiter: string = this.delimiter): string {
IllegalArgumentException.assertCondition(
IllegalArgumentException.assert(
!(!delimiter || delimiter.length <= 0),
"Delimiter must be a non-empty string."
);
Expand All @@ -36,7 +36,7 @@ export abstract class AbstractName implements Name {

const result = unescapedComponents.join(delimiter);
// Contract: The result string must include the delimiter
MethodFailedException.assertCondition(
MethodFailedException.assert(
result.includes(delimiter),
"The result string must include the provided delimiter."
);
Expand All @@ -58,7 +58,7 @@ export abstract class AbstractName implements Name {
public isEmpty(): boolean {
const result = this.getNoComponents() === 0;
// Contract: isEmpty must return true if there are no components
MethodFailedException.assertCondition(
MethodFailedException.assert(
result === (this.getNoComponents() === 0),
"isEmpty must return true if there are no components."
);
Expand All @@ -79,7 +79,7 @@ export abstract class AbstractName implements Name {
public clone(): Name {
const copy = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
// Contract: The clone must be equal to the original object
MethodFailedException.assertCondition(
MethodFailedException.assert(
copy.isEqual(this),
"The clone must be equal to the original object."
);
Expand All @@ -103,7 +103,7 @@ export abstract class AbstractName implements Name {
}

// Contract: Concatenation must increase component count by the number of components in the other object
MethodFailedException.assertCondition(
MethodFailedException.assert(
this.getNoComponents() === initialComponentCount + other.getNoComponents(),
"Concatenation must increase component count by the number of components in the other object."
);
Expand All @@ -119,7 +119,7 @@ export abstract class AbstractName implements Name {

protected checkIndexBounds(index: number, componentCount: number): void {
// Contract: Index must be within valid bounds
IllegalArgumentException.assertCondition(
IllegalArgumentException.assert(
index >= 0 && index < componentCount,
`Index ${index} is out of bounds. Valid indices are from 0 to ${componentCount - 1}.`
);
Expand All @@ -130,11 +130,11 @@ export abstract class AbstractName implements Name {
}

checkClassInvariants(): void {
InvalidStateException.assertIsNotNullOrUndefined(
this.delimiter,
InvalidStateException.assert(
this.delimiter != null && this.delimiter != undefined,
"Class invariant violated: delimiter must be a non-empty string."
);
InvalidStateException.assertCondition(
InvalidStateException.assert(
this.delimiter.length > 0,
"Class invariant violated: delimiter must have a length greater than zero."
);
Expand Down
16 changes: 8 additions & 8 deletions src/adap-b04/names/StringArrayName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export class StringArrayName extends AbstractName {
constructor(other: string[], delimiter?: string) {
super(delimiter); // Validates delimiter
// Contract: The input must be an array of strings
IllegalArgumentException.assertCondition(
IllegalArgumentException.assert(
Array.isArray(other),
"The input must be an array of strings."
);
for (const item of other) {
// Contract: All components must be strings
IllegalArgumentException.assertCondition(
IllegalArgumentException.assert(
typeof item === "string",
"All components must be strings."
);
Expand All @@ -36,7 +36,7 @@ export class StringArrayName extends AbstractName {
public setComponent(i: number, c: string): void {
this.checkIndexBounds(i, this.components.length); // Precondition: valid index
// Contract: Component must be a string
IllegalArgumentException.assertCondition(
IllegalArgumentException.assert(
typeof c === "string",
"Component must be a string."
);
Expand All @@ -46,12 +46,12 @@ export class StringArrayName extends AbstractName {

public insert(i: number, c: string): void {
// Contract: Component must be a string
IllegalArgumentException.assertCondition(
IllegalArgumentException.assert(
typeof c === "string",
"Component must be a string."
); // Precondition: valid string
// Contract: Index must be within valid bounds for insertion
IllegalArgumentException.assertCondition(
IllegalArgumentException.assert(
i >= 0 && i <= this.components.length,
"Index ${i} is out of bounds for insert."
); // Precondition: valid index
Expand All @@ -61,7 +61,7 @@ export class StringArrayName extends AbstractName {

public append(c: string): void {
// Contract: Component must be a string
IllegalArgumentException.assertCondition(
IllegalArgumentException.assert(
typeof c === "string",
"Component must be a string."
); // Precondition: valid string
Expand All @@ -77,12 +77,12 @@ export class StringArrayName extends AbstractName {

public checkClassInvariants(): void {
// Contract: Components must be an array of strings
InvalidStateException.assertCondition(
InvalidStateException.assert(
Array.isArray(this.components),
"Components must be an array."
);
// Contract: Ensure all components are strings
InvalidStateException.assertCondition(
InvalidStateException.assert(
this.components.every((comp) => typeof comp === "string"),
"All components must be strings."
);
Expand Down
2 changes: 1 addition & 1 deletion src/adap-b04/names/StringName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class StringName extends AbstractName {
constructor(name: string, delimiter?: string) {
super(delimiter); // Validates delimiter
// Contract: Name must be a non-empty string
IllegalArgumentException.assertCondition(
IllegalArgumentException.assert(
typeof name === "string" && name.length > 0,
"Name must be a non-empty string."
);
Expand Down
13 changes: 6 additions & 7 deletions src/adap-b05/names/AbstractName.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {DEFAULT_DELIMITER, ESCAPE_CHARACTER} from "../common/Printable";
import {Name} from "./Name";
import {IllegalArgumentException} from "../common/IllegalArgumentException";
import {AssertionDispatcher, ExceptionType} from "../common/AssertionDispatcher";
import {MethodFailedException} from "../common/MethodFailedException";
import {InvalidStateException} from "../common/InvalidStateException";

Expand All @@ -11,12 +10,12 @@ export abstract class AbstractName implements Name {

constructor(delimiter: string = DEFAULT_DELIMITER) {
// precondition
IllegalArgumentException.assertCondition(delimiter != null && delimiter.length == 1, "The delimiter must consist of only one character.");
IllegalArgumentException.assert(delimiter != null && delimiter.length == 1, "The delimiter must consist of only one character.");

this.delimiter = delimiter ?? this.delimiter;

// postcondition
AssertionDispatcher.dispatch(ExceptionType.POSTCONDITION,
InvalidStateException.assert(
this instanceof AbstractName,
"The instance does not meet the prototype requirements of AbstractName.",
);
Expand Down Expand Up @@ -143,7 +142,7 @@ export abstract class AbstractName implements Name {
public isEmpty(): boolean {
const result = this.getNoComponents() === 0;
// Contract: isEmpty must return true if there are no components
MethodFailedException.assertCondition(
MethodFailedException.assert(
result === (this.getNoComponents() === 0),
"isEmpty must return true if there are no components."
);
Expand All @@ -152,13 +151,13 @@ export abstract class AbstractName implements Name {

public getDelimiterCharacter(): string {
// CLASS INV
InvalidStateException.assertIsNotNullOrUndefined(this.delimiter, "Delimiter must not be null!");
InvalidStateException.assertCondition(this.delimiter.length === 1, "Delimiter must be a single character!");
InvalidStateException.assert( this.delimiter != null && this.delimiter != undefined, "Delimiter must not be null!");
InvalidStateException.assert(this.delimiter.length === 1, "Delimiter must be a single character!");

let str: string = this.delimiter;

// postcondition
MethodFailedException.assertIsNotNullOrUndefined(str, "Could not execute getDelimiterCharacter()!");
MethodFailedException.assert(str != null && str != undefined, "Could not execute getDelimiterCharacter()!");

return str;
}
Expand Down
26 changes: 13 additions & 13 deletions src/adap-b05/names/StringArrayName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractName } from "./AbstractName";
import { AssertionDispatcher, ExceptionType } from "../common/AssertionDispatcher";
import { IllegalArgumentException } from "../common/IllegalArgumentException";
import {MethodFailedException} from "../common/MethodFailedException";

export class StringArrayName extends AbstractName {
protected components: string[] = [];
Expand All @@ -12,39 +12,39 @@ export class StringArrayName extends AbstractName {
this.validatePreconditions(other, delimiter);
this.components = other.map(c => this.unescape(c, this.delimiter));
// Postcondition: Ensure valid string array
AssertionDispatcher.dispatch(ExceptionType.POSTCONDITION, Array.isArray(this.components) && this.components.every(() => true), "Components should be a valid string array.");
MethodFailedException.assert( Array.isArray(this.components) && this.components.every(() => true), "Components should be a valid string array.");
}

private validatePreconditions(other: string[], delimiter?: string): void {
AssertionDispatcher.dispatch(ExceptionType.PRECONDITION, other !== undefined && other !== null, "Should be defined");
AssertionDispatcher.dispatch(ExceptionType.PRECONDITION, other.length !== 0, "At least one component is required.");
MethodFailedException.assert( other !== undefined && other !== null, "Should be defined");
MethodFailedException.assert( other.length !== 0, "At least one component is required.");

if (delimiter && delimiter.length !== 1) {
throw new IllegalArgumentException("Delimiter must be a single character.");
}

other.forEach(c => {
AssertionDispatcher.dispatch(ExceptionType.PRECONDITION, this.isEscaped(c, this.getDelimiterCharacter()), "Components must be escaped.");
MethodFailedException.assert( this.isEscaped(c, this.getDelimiterCharacter()), "Components must be escaped.");
});
}

private ensureValidInstance(): void {
AssertionDispatcher.dispatch(ExceptionType.PRECONDITION, this instanceof StringArrayName, "Instance is not of type StringArrayName.");
MethodFailedException.assert(this instanceof StringArrayName, "Instance is not of type StringArrayName.");
}

private ensureValidIndex(i: number): void {
AssertionDispatcher.dispatch(ExceptionType.PRECONDITION, i >= 0 && i < this.getNoComponents(), "Index out of bounds.");
MethodFailedException.assert( i >= 0 && i < this.getNoComponents(), "Index out of bounds.");
}

private ensureValidComponent(c: string): void {
AssertionDispatcher.dispatch(ExceptionType.PRECONDITION, c !== undefined && c !== null, "Should be defined");
AssertionDispatcher.dispatch(ExceptionType.PRECONDITION, this.isEscaped(c, this.getDelimiterCharacter()), "Component must be escaped.");
MethodFailedException.assert( c !== undefined && c !== null, "Should be defined");
MethodFailedException.assert( this.isEscaped(c, this.getDelimiterCharacter()), "Component must be escaped.");
}

public getNoComponents(): number {
this.ensureValidInstance();
const count = this.components.length;
AssertionDispatcher.dispatch(ExceptionType.POSTCONDITION, count >= 0, "Must return non-negative value.");
MethodFailedException.assert( count >= 0, "Must return non-negative value.");
return count;
}

Expand All @@ -53,8 +53,8 @@ export class StringArrayName extends AbstractName {
this.ensureValidIndex(i);
const component = this.escape(this.components[i], this.delimiter);
// Postcondition: Ensure component is defined and escaped
AssertionDispatcher.dispatch(ExceptionType.POSTCONDITION, component !== undefined && component !== null, "Component should be defined");
AssertionDispatcher.dispatch(ExceptionType.POSTCONDITION, this.isEscaped(component, this.getDelimiterCharacter()), "Component must be escaped.");
MethodFailedException.assert( component !== undefined && component !== null, "Component should be defined");
MethodFailedException.assert( this.isEscaped(component, this.getDelimiterCharacter()), "Component must be escaped.");

return component;
}
Expand All @@ -74,7 +74,7 @@ export class StringArrayName extends AbstractName {
public insert(i: number, c: string): void {
this.ensureValidInstance();
this.ensureValidComponent(c);
AssertionDispatcher.dispatch(ExceptionType.PRECONDITION, i >= 0 && i <= this.getNoComponents(), "Index out of bounds.");
MethodFailedException.assert( i >= 0 && i <= this.getNoComponents(), "Index out of bounds.");

try {
this.components.splice(i, 0, this.unescape(c, this.delimiter));
Expand Down
Loading

0 comments on commit 8bd8804

Please sign in to comment.