Skip to content

Commit 4adb670

Browse files
committed
- Lecture on Thursday, 5th, 2026.
1 parent 3dc66be commit 4adb670

9 files changed

Lines changed: 334 additions & 0 deletions

File tree

2026-02-05-Retro_Copilot/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Retrospective, Evaluation, with a grain of AI
2+
3+
## Retrospective, Evaluation
4+
5+
* [Use Evaluation Link](https://lehreval.psy.uni-osnabrueck.de/evasys/online.php?pswd=PHACT)
6+
* Or scan QR code below:<br><img src="src/main/resources/QRCode_PHACT.png" width="400"/>
7+
8+
## Feedback

2026-02-05-Retro_Copilot/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<version>1.0.0-SNAPSHOT</version>
6+
<groupId>de.hilling.intro-to-coding</groupId>
7+
<artifactId>samples</artifactId>
8+
</parent>
9+
10+
<artifactId>retro-copilot</artifactId>
11+
<name>Retrospective, Evaluation, with a grain of AI</name>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.jspecify</groupId>
16+
<artifactId>jspecify</artifactId>
17+
</dependency>
18+
</dependencies>
19+
20+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package de.hilling.chess;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.regex.Pattern;
6+
7+
import org.jspecify.annotations.NonNull;
8+
9+
/**
10+
* Represents a position on the board.
11+
* Objects of this class are immutable, correct coordinates are checked when the constructor is called.
12+
*/
13+
14+
public class Position extends Object {
15+
private static final char[] X_CHARACTERS = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
16+
private static final Map<String, Position> VALID_POSITIONS = new HashMap<>();
17+
18+
public final int x;
19+
public final int y;
20+
public final String formattedPosition;
21+
22+
static {
23+
for (int x = 0; x < 8; x++) {
24+
for (int y = 0; y < 8; y++) {
25+
Position position = new Position(x, y);
26+
VALID_POSITIONS.put(position.formattedPosition, position);
27+
}
28+
}
29+
}
30+
31+
private Position(int x, int y) {
32+
validatePosition(x, y);
33+
this.x = x;
34+
this.y = y;
35+
formattedPosition = String.format("%c%d", X_CHARACTERS[x], y + 1);
36+
}
37+
38+
private static void validatePosition(int x, int y) {
39+
if (x < 0 || y < 0 || x > 7 || y > 7) {
40+
throw new IllegalArgumentException("x and y need to be between 0 and 7");
41+
}
42+
}
43+
44+
/**
45+
* Access Position object via position string (chess notation).
46+
*
47+
* @param positionString position between "a1 and h8".
48+
* @return Position element
49+
* @throws IllegalArgumentException if positionString is invalid.
50+
*/
51+
public static @NonNull Position of(@NonNull String positionString) {
52+
Position position = VALID_POSITIONS.get(positionString);
53+
if (position == null) {
54+
throw new IllegalArgumentException("Illegal position: " + positionString);
55+
}
56+
return position;
57+
}
58+
59+
/**
60+
* Access Position object via offset.
61+
*
62+
* @param x x-offset, starting at 0.
63+
* @param y y-offset, starting at 0
64+
* @return Position element
65+
* @throws IllegalArgumentException if x or y are not between 0 and 7.
66+
*/
67+
public static @NonNull Position of(int x, int y) {
68+
validatePosition(x, y);
69+
return of(String.format("%c%d", X_CHARACTERS[x], y + 1));
70+
}
71+
72+
@Override
73+
public String toString() {
74+
return formattedPosition;
75+
}
76+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package de.hilling.chess;
2+
3+
import java.util.List;
4+
5+
import org.jspecify.annotations.NonNull;
6+
7+
/**
8+
* Provide the static {@link Sort#sort(List)} function.
9+
*/
10+
public class Sort {
11+
private static boolean debug;
12+
13+
// Never instantiated.
14+
private Sort() {}
15+
16+
public static void setDebug(boolean debug) {
17+
Sort.debug = debug;
18+
}
19+
20+
/**
21+
* Sort the given List inplace.
22+
*
23+
* @param elements comparable non-null Objects.
24+
* @param <T> Type implementing {@link Comparable}.
25+
* @return
26+
*
27+
*/
28+
public static @NonNull <T extends Comparable<T>> List<@NonNull T> sort(@NonNull List<@NonNull T> elements) {
29+
print(elements);
30+
quickSort(elements, 0, elements.size() -1);
31+
return elements;
32+
}
33+
34+
private static <T extends Comparable<T>> void quickSort(@NonNull List<@NonNull T> elements, int left, int right) {
35+
if(unsorted(elements, left, right)) {
36+
print("quicksort: " + (left+1) + ", " + (right+1));
37+
int partitionIndex = partition(elements, left, right);
38+
quickSort(elements, left, partitionIndex - 1);
39+
quickSort(elements, partitionIndex + 1, right);
40+
}
41+
}
42+
43+
private static <T extends Comparable<T>> boolean unsorted(@NonNull List<T> elements, int left, int right) {
44+
if(left >= right) {
45+
return false;
46+
}
47+
for(int index = left; index <= right; index++) {
48+
if(elements.get(index).compareTo(elements.get(right)) > 0) {
49+
return true;
50+
}
51+
}
52+
return false;
53+
}
54+
55+
private static <T extends Comparable<T>> int partition(@NonNull List<@NonNull T> elements, int left, int right) {
56+
T pivot = elements.get(right);
57+
print("piv " + pivot + " " + elements);
58+
int i = (left - 1);
59+
60+
for (int j = left; j < right; j++) {
61+
if(elements.get(j).compareTo(pivot) <= 0) {
62+
i++;
63+
swap(elements, i, j);
64+
}
65+
}
66+
print("move pivot element to " + (i + 1));
67+
swap(elements, i + 1, right);
68+
return i + 1;
69+
}
70+
71+
private static <T extends Comparable<T>> void swap(@NonNull List<T> elements, int i, int j) {
72+
T temp = elements.get(i);
73+
elements.set(i, elements.get(j));
74+
elements.set(j, temp);
75+
print((i+1) + "<->" + (j+1) + " " + elements);
76+
}
77+
78+
private static void print(Object output) {
79+
if(debug) {
80+
System.out.println(output);
81+
}
82+
}
83+
}
826 Bytes
Loading
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package de.hilling.chess;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import java.util.Arrays;
6+
import java.util.Collection;
7+
import java.util.Collections;
8+
import java.util.List;
9+
10+
import org.junit.jupiter.api.BeforeEach;
11+
import org.junit.jupiter.api.Test;
12+
13+
class PositionGenericsTest {
14+
static final Position A1 = Position.of("a1");
15+
static final Position A2 = Position.of("a2");
16+
static final Position B1 = Position.of("b1");
17+
static final Position B2 = Position.of("b2");
18+
19+
List<Position> positionList;
20+
List<Position> randomPositionList;
21+
Collection<Position> randomCollection;
22+
List<Integer> sortedIntegerList;
23+
List<Integer> unsortedIntegerList;
24+
25+
@BeforeEach
26+
void setUp() {
27+
positionList = Arrays.asList(A1, A2, B1, B2);
28+
randomPositionList = Arrays.asList(A2, B1, A1, B2, A1);
29+
randomCollection = Arrays.asList(A1, B1, A2, B2);
30+
sortedIntegerList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
31+
unsortedIntegerList = Arrays.asList(4, 7, 9, 10, 5, 3, 1, 2, 8, 6);
32+
}
33+
34+
@Test
35+
void compareDifferentPositions() {
36+
Collection<Position> positions = randomPositionList;
37+
List bareList = randomPositionList;
38+
List<Object> objectList = bareList;
39+
// List<Object> objectList = randomPositionList;
40+
}
41+
42+
@Test
43+
void sortIntegerList() {
44+
Collections.sort(unsortedIntegerList);
45+
assertEquals(1, unsortedIntegerList.getFirst());
46+
assertEquals(sortedIntegerList, unsortedIntegerList);
47+
}
48+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package de.hilling.chess;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class PositionTest {
8+
9+
@Test
10+
void setUpValidPositions() {
11+
assertEquals("a1", Position.of(0, 0).toString());
12+
assertEquals("e5", Position.of(4, 4).toString());
13+
assertEquals("h8", Position.of(7, 7).toString());
14+
}
15+
16+
@Test
17+
void compareDifferentPositions() {
18+
Position p1 = Position.of(0, 0);
19+
Position p2 = Position.of(1, 0);
20+
assertNotEquals(p1, p2);
21+
}
22+
23+
@Test
24+
void compareEqualPositions() {
25+
Position p1 = Position.of(0, 0);
26+
Position p2 = Position.of(0, 0);
27+
assertEquals(p1, p2);
28+
}
29+
30+
@Test
31+
void compareDifferentPositionHash() {
32+
assertNotEquals(Position.of(0, 1).hashCode(), Position.of(0, 0).hashCode());
33+
}
34+
35+
@Test
36+
void accessPositionObject() {
37+
Position positionA = Position.of("a1");
38+
assertSame(positionA, Position.of("a1"));
39+
}
40+
41+
@Test
42+
void denyNegativePositions() {
43+
try {
44+
Position.of(-1, 0);
45+
fail("IllegalArgumentException expected");
46+
} catch (IllegalArgumentException ile) {
47+
// success
48+
}
49+
}
50+
51+
@Test
52+
void denyOverflowPositions() {
53+
try {
54+
Position.of(0, 8);
55+
fail("IllegalArgumentException expected");
56+
} catch (IllegalArgumentException ile) {
57+
// success
58+
}
59+
}
60+
61+
@Test
62+
void denyIllegalStringPositions() {
63+
try {
64+
Position.of("a9");
65+
fail("IllegalArgumentException expected");
66+
} catch (IllegalArgumentException ile) {
67+
// success
68+
}
69+
}
70+
71+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.hilling.chess;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import java.util.Arrays;
6+
import java.util.List;
7+
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
11+
class SortTest {
12+
13+
List<Integer> sortedIntegerList;
14+
List<Integer> unsortedIntegerList;
15+
16+
@BeforeEach
17+
void setUp() {
18+
Sort.setDebug(true);
19+
sortedIntegerList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
20+
unsortedIntegerList = Arrays.asList(4, 7, 9, 10, 5, 3, 1, 2, 8, 6);
21+
}
22+
23+
@Test
24+
void compareDifferentPositionsSort() {
25+
assertEquals(sortedIntegerList, Sort.sort(unsortedIntegerList));
26+
}
27+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<module>2026-01-16-CommonPropertiesOfAnObject</module>
2222
<module>2026-01-23-Private_Constructors</module>
2323
<module>2026-01-30-Generics_Sorting</module>
24+
<module>2026-02-05-Retro_Copilot</module>
2425
</modules>
2526

2627
<properties>

0 commit comments

Comments
 (0)