From fe1009187c3e2b3bd1e3375154a15d6f6cf8777b Mon Sep 17 00:00:00 2001 From: DieGurke Date: Tue, 7 Dec 2021 19:13:51 +0100 Subject: [PATCH 01/12] New change interface and changeManager class --- src/main/java/dev/kske/undoredo/Change.java | 33 ++++++ .../java/dev/kske/undoredo/ChangeManager.java | 100 ++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 src/main/java/dev/kske/undoredo/Change.java create mode 100644 src/main/java/dev/kske/undoredo/ChangeManager.java diff --git a/src/main/java/dev/kske/undoredo/Change.java b/src/main/java/dev/kske/undoredo/Change.java new file mode 100644 index 0000000..6f88984 --- /dev/null +++ b/src/main/java/dev/kske/undoredo/Change.java @@ -0,0 +1,33 @@ +package dev.kske.undoredo; + +/** + * Base interface for changes to be registered in an undo manager. + * + * @author Maximilian Käfer + * @since 0.0.1 + */ +public interface Change { + + /** + * Performs the action implemented by this change. + * + * @since 0.0.1 + */ + void apply(); + + /** + * Inverts this change. + * + * @implSpec This method is not supposed to alter the state of this change, but rather to create + * a new complementary change. + * @return the inverted change + * @since 0.0.1 + */ + Change invert(); + + /** + * @return whether the application of this change would result in an identical state + * @since 0.0.1 + */ + boolean isIdentity(); +} diff --git a/src/main/java/dev/kske/undoredo/ChangeManager.java b/src/main/java/dev/kske/undoredo/ChangeManager.java new file mode 100644 index 0000000..8f2812e --- /dev/null +++ b/src/main/java/dev/kske/undoredo/ChangeManager.java @@ -0,0 +1,100 @@ +package dev.kske.undoredo; + +import java.util.*; + +/** + * @param the change types to store in this change manager + * @author Maximilian Käfer + * @since 0.0.1 + */ +public final class ChangeManager { + + private final List changes = new LinkedList<>(); + + private int index; + private int markedIndex; + + /** + * Adds a change to the changes list. + * + * @param change the change to add + * @since 0.0.1 + */ + public void addChange(C change) { + change.apply(); + changes.add(change); + } + + /** + * Undoes the change at the current index position. + * + * @return whether the operation could be executed due to one being currently available + * @since 0.1.0 + */ + public boolean undo() { + if (isUndoAvailable()) { + changes.get(index).invert().apply(); + --index; + return true; + } + return false; + } + + /** + * Applies the change that was undone before. + * + * @return whether the operation could be executed due to one being currently available + * @since 0.0.1 + */ + public boolean redo() { + if (isRedoAvailable()) { + changes.get(index + 1).apply(); + ++index; + return true; + } + return false; + } + + /** + * Marks the current index. + * + * @since 0.0.1 + */ + public void mark() { + markedIndex = index; + } + + /** + * @return whether the current index was marked + * @since 0.0.1 + */ + public boolean isAtMarkedIndex() { + return markedIndex == index; + } + + /** + * @return whether the undo operation is currently available + * @since 0.0.1 + */ + public boolean isUndoAvailable() { + return index > 0; + } + + /** + * @return whether the redo operation is currently available. + * @since 0.0.1 + */ + public boolean isRedoAvailable() { + return index < changes.size() - 1; + } + + /** + * Provides an unmodifiable view of the changes stored in this change manager. + * + * @return all stored changes + * @since 0.0.1 + */ + public List getChanges() { + return Collections.unmodifiableList(changes); + } +} -- 2.45.2 From acb25c312060a0009d37e46a4e4a65d7bf1200e8 Mon Sep 17 00:00:00 2001 From: kske Date: Wed, 8 Dec 2021 10:35:09 +0100 Subject: [PATCH 02/12] Improve ChangeManager Javadoc --- .../java/dev/kske/undoredo/ChangeManager.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/dev/kske/undoredo/ChangeManager.java b/src/main/java/dev/kske/undoredo/ChangeManager.java index 8f2812e..6d520c2 100644 --- a/src/main/java/dev/kske/undoredo/ChangeManager.java +++ b/src/main/java/dev/kske/undoredo/ChangeManager.java @@ -3,7 +3,11 @@ package dev.kske.undoredo; import java.util.*; /** - * @param the change types to store in this change manager + * A change manager keeps track of subsequent changes and allows un- and redoing them. A specific + * change can be marked using {@link #mark()} to keep track of a saved state in the application that + * uses the manager. + * + * @param the change type to store in this change manager * @author Maximilian Käfer * @since 0.0.1 */ @@ -15,8 +19,8 @@ public final class ChangeManager { private int markedIndex; /** - * Adds a change to the changes list. - * + * Applies the given change and appends it to the change list. + * * @param change the change to add * @since 0.0.1 */ @@ -26,9 +30,9 @@ public final class ChangeManager { } /** - * Undoes the change at the current index position. - * - * @return whether the operation could be executed due to one being currently available + * Undoes the current change. + * + * @return whether an action was performed * @since 0.1.0 */ public boolean undo() { @@ -42,8 +46,8 @@ public final class ChangeManager { /** * Applies the change that was undone before. - * - * @return whether the operation could be executed due to one being currently available + * + * @return whether an action was performed * @since 0.0.1 */ public boolean redo() { @@ -56,8 +60,8 @@ public final class ChangeManager { } /** - * Marks the current index. - * + * Marks the current change. + * * @since 0.0.1 */ public void mark() { @@ -65,7 +69,7 @@ public final class ChangeManager { } /** - * @return whether the current index was marked + * @return whether the current change is marked * @since 0.0.1 */ public boolean isAtMarkedIndex() { @@ -73,7 +77,7 @@ public final class ChangeManager { } /** - * @return whether the undo operation is currently available + * @return whether a change is present that can be undone * @since 0.0.1 */ public boolean isUndoAvailable() { @@ -81,7 +85,7 @@ public final class ChangeManager { } /** - * @return whether the redo operation is currently available. + * @return whether a change is present that can be redone * @since 0.0.1 */ public boolean isRedoAvailable() { @@ -90,7 +94,7 @@ public final class ChangeManager { /** * Provides an unmodifiable view of the changes stored in this change manager. - * + * * @return all stored changes * @since 0.0.1 */ -- 2.45.2 From dc74b78d200539108e93db557dfaf0f972dd7ccb Mon Sep 17 00:00:00 2001 From: kske Date: Wed, 8 Dec 2021 10:42:55 +0100 Subject: [PATCH 03/12] Add Jenkinsfile --- Jenkinsfile | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..61004d1 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,40 @@ +pipeline { + agent any + + options { + ansiColor('xterm') + } + + stages { + stage('Build') { + steps { + sh 'mvn -DskipTests clean package' + } + } + stage('Test') { + steps { + sh 'mvn test' + } + post { + always { + junit 'target/surefire-reports/*.xml' + } + } + } + stage('SonarQube Analysis') { + when { + branch 'develop' + } + steps { + withSonarQubeEnv('KSKE SonarQube') { + sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar' + } + } + } + } + post { + success { + archiveArtifacts artifacts: 'target/undo-redo-*.jar' + } + } +} -- 2.45.2 From bb7c1690b26ff8076296ba1478791eacae96f97e Mon Sep 17 00:00:00 2001 From: kske Date: Fri, 10 Dec 2021 18:39:57 +0100 Subject: [PATCH 04/12] Add change manager unit test skeleton --- pom.xml | 3 + .../dev/kske/undoredo/ChangeManagerTest.java | 76 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/test/java/dev/kske/undoredo/ChangeManagerTest.java diff --git a/pom.xml b/pom.xml index f32663d..8fce4ef 100644 --- a/pom.xml +++ b/pom.xml @@ -165,6 +165,9 @@ org.apache.maven.plugins maven-surefire-plugin 3.0.0-M5 + + --add-opens dev.kske.undoredo/dev.kske.undoredo=ALL-UNNAMED + diff --git a/src/test/java/dev/kske/undoredo/ChangeManagerTest.java b/src/test/java/dev/kske/undoredo/ChangeManagerTest.java new file mode 100644 index 0000000..0d4cbc0 --- /dev/null +++ b/src/test/java/dev/kske/undoredo/ChangeManagerTest.java @@ -0,0 +1,76 @@ +package dev.kske.undoredo; + +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; + +/** + * @author Kai S. K. Engelbart + * @since 0.0.1 + */ +class ChangeManagerTest { + + /** + * Test method for {@link dev.kske.undoredo.ChangeManager#addChange(dev.kske.undoredo.Change)}. + */ + @Test + void testAddChange() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link dev.kske.undoredo.ChangeManager#undo()}. + */ + @Test + void testUndo() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link dev.kske.undoredo.ChangeManager#redo()}. + */ + @Test + void testRedo() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link dev.kske.undoredo.ChangeManager#mark()}. + */ + @Test + void testMark() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link dev.kske.undoredo.ChangeManager#isAtMarkedIndex()}. + */ + @Test + void testIsAtMarkedIndex() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link dev.kske.undoredo.ChangeManager#isUndoAvailable()}. + */ + @Test + void testIsUndoAvailable() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link dev.kske.undoredo.ChangeManager#isRedoAvailable()}. + */ + @Test + void testIsRedoAvailable() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link dev.kske.undoredo.ChangeManager#getChanges()}. + */ + @Test + void testGetChanges() { + fail("Not yet implemented"); + } +} -- 2.45.2 From 2773d360fbed11f38c4245be61ca074daedf7bcf Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 11 Dec 2021 13:51:12 +0100 Subject: [PATCH 05/12] Implement change manager unit tests --- .../dev/kske/undoredo/ChangeManagerTest.java | 138 +++++++++++------- .../java/dev/kske/undoredo/IntChange.java | 31 ++++ .../java/dev/kske/undoredo/IntWrapper.java | 10 ++ 3 files changed, 124 insertions(+), 55 deletions(-) create mode 100644 src/test/java/dev/kske/undoredo/IntChange.java create mode 100644 src/test/java/dev/kske/undoredo/IntWrapper.java diff --git a/src/test/java/dev/kske/undoredo/ChangeManagerTest.java b/src/test/java/dev/kske/undoredo/ChangeManagerTest.java index 0d4cbc0..b3e1b72 100644 --- a/src/test/java/dev/kske/undoredo/ChangeManagerTest.java +++ b/src/test/java/dev/kske/undoredo/ChangeManagerTest.java @@ -1,8 +1,8 @@ package dev.kske.undoredo; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; /** * @author Kai S. K. Engelbart @@ -10,67 +10,95 @@ import org.junit.jupiter.api.Test; */ class ChangeManagerTest { + ChangeManager manager; + IntWrapper wrapper; + IntChange change; + + @BeforeEach + void prepareChangeManager() { + manager = new ChangeManager<>(); + wrapper = new IntWrapper(); + change = new IntChange(wrapper, 1); + } + /** - * Test method for {@link dev.kske.undoredo.ChangeManager#addChange(dev.kske.undoredo.Change)}. + * Tests adding a change. + * + * @since 0.0.1 */ @Test + @Order(1) void testAddChange() { - fail("Not yet implemented"); + assertSame(0, wrapper.value); + manager.addChange(change); + assertSame(1, wrapper.value); } - + /** - * Test method for {@link dev.kske.undoredo.ChangeManager#undo()}. - */ - @Test - void testUndo() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link dev.kske.undoredo.ChangeManager#redo()}. - */ - @Test - void testRedo() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link dev.kske.undoredo.ChangeManager#mark()}. - */ - @Test - void testMark() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link dev.kske.undoredo.ChangeManager#isAtMarkedIndex()}. - */ - @Test - void testIsAtMarkedIndex() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link dev.kske.undoredo.ChangeManager#isUndoAvailable()}. - */ - @Test - void testIsUndoAvailable() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link dev.kske.undoredo.ChangeManager#isRedoAvailable()}. - */ - @Test - void testIsRedoAvailable() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link dev.kske.undoredo.ChangeManager#getChanges()}. + * Tests the consistency of the change list. + * + * @since 0.0.1 */ @Test + @Order(2) void testGetChanges() { - fail("Not yet implemented"); + assertTrue(manager.getChanges().isEmpty()); + manager.addChange(change); + assertSame(1, manager.getChanges().size()); + assertEquals(change, manager.getChanges().get(0)); + } + + /** + * Test undoing a change. + * + * @since 0.0.1 + */ + @Test + @Order(2) + void testUndo() { + assertFalse(manager.isUndoAvailable()); + assertFalse(manager.undo()); + manager.addChange(change); + assertTrue(manager.isUndoAvailable()); + assertTrue(manager.undo()); + assertFalse(manager.isUndoAvailable()); + assertFalse(manager.undo()); + } + + /** + * Tests redoing a change. + * + * @since 0.0.1 + */ + @Test + @Order(4) + void testRedo() { + assertFalse(manager.isRedoAvailable()); + assertFalse(manager.redo()); + manager.addChange(change); + assertFalse(manager.isRedoAvailable()); + assertFalse(manager.redo()); + manager.undo(); + assertTrue(manager.isRedoAvailable()); + assertTrue(manager.redo()); + assertFalse(manager.isRedoAvailable()); + assertFalse(manager.redo()); + } + + /** + * Tests marking a change. + * + * @since 0.0.1 + */ + @Test + @Order(5) + void testMark() { + assertTrue(manager.isAtMarkedIndex()); + manager.addChange(change); + assertFalse(manager.isAtMarkedIndex()); + manager.mark(); + assertTrue(manager.isAtMarkedIndex()); + manager.undo(); + assertFalse(manager.isAtMarkedIndex()); } } diff --git a/src/test/java/dev/kske/undoredo/IntChange.java b/src/test/java/dev/kske/undoredo/IntChange.java new file mode 100644 index 0000000..76299a4 --- /dev/null +++ b/src/test/java/dev/kske/undoredo/IntChange.java @@ -0,0 +1,31 @@ +package dev.kske.undoredo; + +/** + * @author Kai S. K. Engelbart + * @since 0.0.1 + */ +class IntChange implements Change { + + private final IntWrapper wrapper; + private final int value; + + IntChange(IntWrapper wrapper, int value) { + this.wrapper = wrapper; + this.value = value; + } + + @Override + public void apply() { + wrapper.value += value; + } + + @Override + public Change invert() { + return new IntChange(wrapper, -value); + } + + @Override + public boolean isIdentity() { + return value == 0; + } +} diff --git a/src/test/java/dev/kske/undoredo/IntWrapper.java b/src/test/java/dev/kske/undoredo/IntWrapper.java new file mode 100644 index 0000000..bae74ef --- /dev/null +++ b/src/test/java/dev/kske/undoredo/IntWrapper.java @@ -0,0 +1,10 @@ +package dev.kske.undoredo; + +/** + * @author Kai S. K. Engelbart + * @since 0.0.1 + */ +class IntWrapper { + + int value; +} -- 2.45.2 From ee6015b35371f9a6d4dc29aa78aec2ff2c0515ee Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 11 Dec 2021 14:01:31 +0100 Subject: [PATCH 06/12] Fix index handling in change manager --- src/main/java/dev/kske/undoredo/ChangeManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/kske/undoredo/ChangeManager.java b/src/main/java/dev/kske/undoredo/ChangeManager.java index 6d520c2..4d45bd5 100644 --- a/src/main/java/dev/kske/undoredo/ChangeManager.java +++ b/src/main/java/dev/kske/undoredo/ChangeManager.java @@ -15,8 +15,8 @@ public final class ChangeManager { private final List changes = new LinkedList<>(); - private int index; - private int markedIndex; + private int index = -1; + private int markedIndex = -1; /** * Applies the given change and appends it to the change list. @@ -27,6 +27,7 @@ public final class ChangeManager { public void addChange(C change) { change.apply(); changes.add(change); + ++index; } /** @@ -81,7 +82,7 @@ public final class ChangeManager { * @since 0.0.1 */ public boolean isUndoAvailable() { - return index > 0; + return index > -1; } /** -- 2.45.2 From f82df2b979fe0fe4648c9582b19e6e29e4c10d6b Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sat, 11 Dec 2021 17:30:44 +0100 Subject: [PATCH 07/12] Extracted ChangeManager interface from concrete implementation --- .../java/dev/kske/undoredo/ChangeManager.java | 54 +++------------ .../kske/undoredo/UnlimitedChangeManager.java | 69 +++++++++++++++++++ .../dev/kske/undoredo/ChangeManagerTest.java | 2 +- 3 files changed, 81 insertions(+), 44 deletions(-) create mode 100644 src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java diff --git a/src/main/java/dev/kske/undoredo/ChangeManager.java b/src/main/java/dev/kske/undoredo/ChangeManager.java index 4d45bd5..25e73f6 100644 --- a/src/main/java/dev/kske/undoredo/ChangeManager.java +++ b/src/main/java/dev/kske/undoredo/ChangeManager.java @@ -1,6 +1,6 @@ package dev.kske.undoredo; -import java.util.*; +import java.util.List; /** * A change manager keeps track of subsequent changes and allows un- and redoing them. A specific @@ -9,14 +9,10 @@ import java.util.*; * * @param the change type to store in this change manager * @author Maximilian Käfer + * @author Kai S. K. Engelbart * @since 0.0.1 */ -public final class ChangeManager { - - private final List changes = new LinkedList<>(); - - private int index = -1; - private int markedIndex = -1; +public interface ChangeManager { /** * Applies the given change and appends it to the change list. @@ -24,11 +20,7 @@ public final class ChangeManager { * @param change the change to add * @since 0.0.1 */ - public void addChange(C change) { - change.apply(); - changes.add(change); - ++index; - } + void addChange(C change); /** * Undoes the current change. @@ -36,14 +28,7 @@ public final class ChangeManager { * @return whether an action was performed * @since 0.1.0 */ - public boolean undo() { - if (isUndoAvailable()) { - changes.get(index).invert().apply(); - --index; - return true; - } - return false; - } + boolean undo(); /** * Applies the change that was undone before. @@ -51,47 +36,32 @@ public final class ChangeManager { * @return whether an action was performed * @since 0.0.1 */ - public boolean redo() { - if (isRedoAvailable()) { - changes.get(index + 1).apply(); - ++index; - return true; - } - return false; - } + boolean redo(); /** * Marks the current change. * * @since 0.0.1 */ - public void mark() { - markedIndex = index; - } + void mark(); /** * @return whether the current change is marked * @since 0.0.1 */ - public boolean isAtMarkedIndex() { - return markedIndex == index; - } + boolean isAtMarkedIndex(); /** * @return whether a change is present that can be undone * @since 0.0.1 */ - public boolean isUndoAvailable() { - return index > -1; - } + boolean isUndoAvailable(); /** * @return whether a change is present that can be redone * @since 0.0.1 */ - public boolean isRedoAvailable() { - return index < changes.size() - 1; - } + boolean isRedoAvailable(); /** * Provides an unmodifiable view of the changes stored in this change manager. @@ -99,7 +69,5 @@ public final class ChangeManager { * @return all stored changes * @since 0.0.1 */ - public List getChanges() { - return Collections.unmodifiableList(changes); - } + List getChanges(); } diff --git a/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java b/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java new file mode 100644 index 0000000..d927ee7 --- /dev/null +++ b/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java @@ -0,0 +1,69 @@ +package dev.kske.undoredo; + +import java.util.*; + +/** + * @param the change type to store in this change manager + * @author Maximilian Käfer + * @author Kai S. K. Engelbart + * @since 0.0.1 + */ +public final class UnlimitedChangeManager implements ChangeManager { + + private final List changes = new LinkedList<>(); + + private int index = -1; + private int markedIndex = -1; + + @Override + public void addChange(C change) { + change.apply(); + changes.add(change); + ++index; + } + + @Override + public boolean undo() { + if (isUndoAvailable()) { + changes.get(index).invert().apply(); + --index; + return true; + } + return false; + } + + @Override + public boolean redo() { + if (isRedoAvailable()) { + changes.get(index + 1).apply(); + ++index; + return true; + } + return false; + } + + @Override + public void mark() { + markedIndex = index; + } + + @Override + public boolean isAtMarkedIndex() { + return markedIndex == index; + } + + @Override + public boolean isUndoAvailable() { + return index > -1; + } + + @Override + public boolean isRedoAvailable() { + return index < changes.size() - 1; + } + + @Override + public List getChanges() { + return Collections.unmodifiableList(changes); + } +} diff --git a/src/test/java/dev/kske/undoredo/ChangeManagerTest.java b/src/test/java/dev/kske/undoredo/ChangeManagerTest.java index b3e1b72..db18ba5 100644 --- a/src/test/java/dev/kske/undoredo/ChangeManagerTest.java +++ b/src/test/java/dev/kske/undoredo/ChangeManagerTest.java @@ -16,7 +16,7 @@ class ChangeManagerTest { @BeforeEach void prepareChangeManager() { - manager = new ChangeManager<>(); + manager = new UnlimitedChangeManager<>(); wrapper = new IntWrapper(); change = new IntChange(wrapper, 1); } -- 2.45.2 From c411eace810e267892c749fd949d69a301b1db15 Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 11 Dec 2021 17:55:49 +0100 Subject: [PATCH 08/12] Convert to multi-module project --- .gitignore | 7 ++++-- .project | 6 ----- .classpath => core/.classpath | 0 core/.project | 23 +++++++++++++++++++ core/pom.xml | 15 ++++++++++++ .../main/java/dev/kske/undoredo/Change.java | 0 .../java/dev/kske/undoredo/ChangeManager.java | 0 .../kske/undoredo/UnlimitedChangeManager.java | 0 .../java/dev/kske/undoredo/package-info.java | 0 {src => core/src}/main/java/module-info.java | 0 .../dev/kske/undoredo/ChangeManagerTest.java | 0 .../java/dev/kske/undoredo/IntChange.java | 0 .../java/dev/kske/undoredo/IntWrapper.java | 0 pom.xml | 8 ++++++- 14 files changed, 50 insertions(+), 9 deletions(-) rename .classpath => core/.classpath (100%) create mode 100644 core/.project create mode 100644 core/pom.xml rename {src => core/src}/main/java/dev/kske/undoredo/Change.java (100%) rename {src => core/src}/main/java/dev/kske/undoredo/ChangeManager.java (100%) rename {src => core/src}/main/java/dev/kske/undoredo/UnlimitedChangeManager.java (100%) rename {src => core/src}/main/java/dev/kske/undoredo/package-info.java (100%) rename {src => core/src}/main/java/module-info.java (100%) rename {src => core/src}/test/java/dev/kske/undoredo/ChangeManagerTest.java (100%) rename {src => core/src}/test/java/dev/kske/undoredo/IntChange.java (100%) rename {src => core/src}/test/java/dev/kske/undoredo/IntWrapper.java (100%) diff --git a/.gitignore b/.gitignore index 731eb43..6cfda9f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ -/target/ -/.settings/ +# Maven build directories +target/ + +# Eclipse settings directories +.settings/ diff --git a/.project b/.project index 9c30c27..1f09710 100644 --- a/.project +++ b/.project @@ -5,11 +5,6 @@ - - org.eclipse.jdt.core.javabuilder - - - org.eclipse.m2e.core.maven2Builder @@ -17,7 +12,6 @@ - org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature diff --git a/.classpath b/core/.classpath similarity index 100% rename from .classpath rename to core/.classpath diff --git a/core/.project b/core/.project new file mode 100644 index 0000000..49781d8 --- /dev/null +++ b/core/.project @@ -0,0 +1,23 @@ + + + undo-redo-core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/core/pom.xml b/core/pom.xml new file mode 100644 index 0000000..4cfd653 --- /dev/null +++ b/core/pom.xml @@ -0,0 +1,15 @@ + + 4.0.0 + + undo-redo-core + Undo-Redo Core + + + dev.kske + undo-redo + 0.0.1-SNAPSHOT + + + diff --git a/src/main/java/dev/kske/undoredo/Change.java b/core/src/main/java/dev/kske/undoredo/Change.java similarity index 100% rename from src/main/java/dev/kske/undoredo/Change.java rename to core/src/main/java/dev/kske/undoredo/Change.java diff --git a/src/main/java/dev/kske/undoredo/ChangeManager.java b/core/src/main/java/dev/kske/undoredo/ChangeManager.java similarity index 100% rename from src/main/java/dev/kske/undoredo/ChangeManager.java rename to core/src/main/java/dev/kske/undoredo/ChangeManager.java diff --git a/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java b/core/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java similarity index 100% rename from src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java rename to core/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java diff --git a/src/main/java/dev/kske/undoredo/package-info.java b/core/src/main/java/dev/kske/undoredo/package-info.java similarity index 100% rename from src/main/java/dev/kske/undoredo/package-info.java rename to core/src/main/java/dev/kske/undoredo/package-info.java diff --git a/src/main/java/module-info.java b/core/src/main/java/module-info.java similarity index 100% rename from src/main/java/module-info.java rename to core/src/main/java/module-info.java diff --git a/src/test/java/dev/kske/undoredo/ChangeManagerTest.java b/core/src/test/java/dev/kske/undoredo/ChangeManagerTest.java similarity index 100% rename from src/test/java/dev/kske/undoredo/ChangeManagerTest.java rename to core/src/test/java/dev/kske/undoredo/ChangeManagerTest.java diff --git a/src/test/java/dev/kske/undoredo/IntChange.java b/core/src/test/java/dev/kske/undoredo/IntChange.java similarity index 100% rename from src/test/java/dev/kske/undoredo/IntChange.java rename to core/src/test/java/dev/kske/undoredo/IntChange.java diff --git a/src/test/java/dev/kske/undoredo/IntWrapper.java b/core/src/test/java/dev/kske/undoredo/IntWrapper.java similarity index 100% rename from src/test/java/dev/kske/undoredo/IntWrapper.java rename to core/src/test/java/dev/kske/undoredo/IntWrapper.java diff --git a/pom.xml b/pom.xml index 8fce4ef..f04ca06 100644 --- a/pom.xml +++ b/pom.xml @@ -6,10 +6,15 @@ dev.kske undo-redo 0.0.1-SNAPSHOT + pom Undo-Redo A Java library for managing changes in an editor history. https://git.kske.dev/kske/event-bus + + + core + @@ -169,7 +174,8 @@ --add-opens dev.kske.undoredo/dev.kske.undoredo=ALL-UNNAMED - + + -- 2.45.2 From 4ef3c412519654f0a957a6cdce019bcf36d77cbb Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 11 Dec 2021 17:58:09 +0100 Subject: [PATCH 09/12] Adapt Jenkinsfile to multi-module architecture --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 61004d1..ae2c663 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { } post { always { - junit 'target/surefire-reports/*.xml' + junit '*/target/surefire-reports/*.xml' } } } @@ -34,7 +34,7 @@ pipeline { } post { success { - archiveArtifacts artifacts: 'target/undo-redo-*.jar' + archiveArtifacts artifacts: '*/target/undo-redo-*.jar' } } } -- 2.45.2 From 93e177cc35941c5627d8174dae159540a1922327 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sat, 11 Dec 2021 18:09:47 +0100 Subject: [PATCH 10/12] Changed LinkedList to ArrayList --- .../src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java b/core/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java index d927ee7..db958ac 100644 --- a/core/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java +++ b/core/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java @@ -10,7 +10,7 @@ import java.util.*; */ public final class UnlimitedChangeManager implements ChangeManager { - private final List changes = new LinkedList<>(); + private final List changes = new ArrayList<>(); private int index = -1; private int markedIndex = -1; -- 2.45.2 From 23aa60e65e02f97708f40ae8c6fbdd2cd4c6e2ab Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 11 Dec 2021 18:18:39 +0100 Subject: [PATCH 11/12] Move everything into the core package --- .../java/dev/kske/undoredo/{ => core}/Change.java | 2 +- .../kske/undoredo/{ => core}/ChangeManager.java | 2 +- .../{ => core}/UnlimitedChangeManager.java | 2 +- .../dev/kske/undoredo/{ => core}/package-info.java | 2 +- core/src/main/java/module-info.java | 2 +- .../undoredo/{ => core}/ChangeManagerTest.java | 4 ++-- .../dev/kske/undoredo/{ => core}/IntChange.java | 14 +++++++------- .../dev/kske/undoredo/{ => core}/IntWrapper.java | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) rename core/src/main/java/dev/kske/undoredo/{ => core}/Change.java (95%) rename core/src/main/java/dev/kske/undoredo/{ => core}/ChangeManager.java (97%) rename core/src/main/java/dev/kske/undoredo/{ => core}/UnlimitedChangeManager.java (97%) rename core/src/main/java/dev/kske/undoredo/{ => core}/package-info.java (83%) rename core/src/test/java/dev/kske/undoredo/{ => core}/ChangeManagerTest.java (98%) rename core/src/test/java/dev/kske/undoredo/{ => core}/IntChange.java (70%) rename core/src/test/java/dev/kske/undoredo/{ => core}/IntWrapper.java (72%) diff --git a/core/src/main/java/dev/kske/undoredo/Change.java b/core/src/main/java/dev/kske/undoredo/core/Change.java similarity index 95% rename from core/src/main/java/dev/kske/undoredo/Change.java rename to core/src/main/java/dev/kske/undoredo/core/Change.java index 6f88984..4252e03 100644 --- a/core/src/main/java/dev/kske/undoredo/Change.java +++ b/core/src/main/java/dev/kske/undoredo/core/Change.java @@ -1,4 +1,4 @@ -package dev.kske.undoredo; +package dev.kske.undoredo.core; /** * Base interface for changes to be registered in an undo manager. diff --git a/core/src/main/java/dev/kske/undoredo/ChangeManager.java b/core/src/main/java/dev/kske/undoredo/core/ChangeManager.java similarity index 97% rename from core/src/main/java/dev/kske/undoredo/ChangeManager.java rename to core/src/main/java/dev/kske/undoredo/core/ChangeManager.java index 25e73f6..7b887e7 100644 --- a/core/src/main/java/dev/kske/undoredo/ChangeManager.java +++ b/core/src/main/java/dev/kske/undoredo/core/ChangeManager.java @@ -1,4 +1,4 @@ -package dev.kske.undoredo; +package dev.kske.undoredo.core; import java.util.List; diff --git a/core/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java b/core/src/main/java/dev/kske/undoredo/core/UnlimitedChangeManager.java similarity index 97% rename from core/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java rename to core/src/main/java/dev/kske/undoredo/core/UnlimitedChangeManager.java index db958ac..8a0ff35 100644 --- a/core/src/main/java/dev/kske/undoredo/UnlimitedChangeManager.java +++ b/core/src/main/java/dev/kske/undoredo/core/UnlimitedChangeManager.java @@ -1,4 +1,4 @@ -package dev.kske.undoredo; +package dev.kske.undoredo.core; import java.util.*; diff --git a/core/src/main/java/dev/kske/undoredo/package-info.java b/core/src/main/java/dev/kske/undoredo/core/package-info.java similarity index 83% rename from core/src/main/java/dev/kske/undoredo/package-info.java rename to core/src/main/java/dev/kske/undoredo/core/package-info.java index 1cda98b..b4cc131 100644 --- a/core/src/main/java/dev/kske/undoredo/package-info.java +++ b/core/src/main/java/dev/kske/undoredo/core/package-info.java @@ -5,4 +5,4 @@ * @author Kai S. K. Engelbart * @since 0.0.1 */ -package dev.kske.undoredo; +package dev.kske.undoredo.core; diff --git a/core/src/main/java/module-info.java b/core/src/main/java/module-info.java index d8d1033..3ae73e7 100644 --- a/core/src/main/java/module-info.java +++ b/core/src/main/java/module-info.java @@ -7,5 +7,5 @@ */ module dev.kske.undoredo { - exports dev.kske.undoredo; + exports dev.kske.undoredo.core; } diff --git a/core/src/test/java/dev/kske/undoredo/ChangeManagerTest.java b/core/src/test/java/dev/kske/undoredo/core/ChangeManagerTest.java similarity index 98% rename from core/src/test/java/dev/kske/undoredo/ChangeManagerTest.java rename to core/src/test/java/dev/kske/undoredo/core/ChangeManagerTest.java index db18ba5..4643970 100644 --- a/core/src/test/java/dev/kske/undoredo/ChangeManagerTest.java +++ b/core/src/test/java/dev/kske/undoredo/core/ChangeManagerTest.java @@ -1,4 +1,4 @@ -package dev.kske.undoredo; +package dev.kske.undoredo.core; import static org.junit.jupiter.api.Assertions.*; @@ -33,7 +33,7 @@ class ChangeManagerTest { manager.addChange(change); assertSame(1, wrapper.value); } - + /** * Tests the consistency of the change list. * diff --git a/core/src/test/java/dev/kske/undoredo/IntChange.java b/core/src/test/java/dev/kske/undoredo/core/IntChange.java similarity index 70% rename from core/src/test/java/dev/kske/undoredo/IntChange.java rename to core/src/test/java/dev/kske/undoredo/core/IntChange.java index 76299a4..f6e8a32 100644 --- a/core/src/test/java/dev/kske/undoredo/IntChange.java +++ b/core/src/test/java/dev/kske/undoredo/core/IntChange.java @@ -1,17 +1,17 @@ -package dev.kske.undoredo; +package dev.kske.undoredo.core; /** * @author Kai S. K. Engelbart * @since 0.0.1 */ class IntChange implements Change { - - private final IntWrapper wrapper; - private final int value; - + + private final IntWrapper wrapper; + private final int value; + IntChange(IntWrapper wrapper, int value) { - this.wrapper = wrapper; - this.value = value; + this.wrapper = wrapper; + this.value = value; } @Override diff --git a/core/src/test/java/dev/kske/undoredo/IntWrapper.java b/core/src/test/java/dev/kske/undoredo/core/IntWrapper.java similarity index 72% rename from core/src/test/java/dev/kske/undoredo/IntWrapper.java rename to core/src/test/java/dev/kske/undoredo/core/IntWrapper.java index bae74ef..2b6907d 100644 --- a/core/src/test/java/dev/kske/undoredo/IntWrapper.java +++ b/core/src/test/java/dev/kske/undoredo/core/IntWrapper.java @@ -1,10 +1,10 @@ -package dev.kske.undoredo; +package dev.kske.undoredo.core; /** * @author Kai S. K. Engelbart * @since 0.0.1 */ class IntWrapper { - + int value; } -- 2.45.2 From a4695870c4502584ab2bc09a51fc3d7315250c69 Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 11 Dec 2021 18:22:06 +0100 Subject: [PATCH 12/12] Fix core module name --- core/src/main/java/module-info.java | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/module-info.java b/core/src/main/java/module-info.java index 3ae73e7..ccaee99 100644 --- a/core/src/main/java/module-info.java +++ b/core/src/main/java/module-info.java @@ -5,7 +5,7 @@ * @author Kai S. K. Engelbart * @since 0.0.1 */ -module dev.kske.undoredo { +module dev.kske.undoredo.core { exports dev.kske.undoredo.core; } diff --git a/pom.xml b/pom.xml index f04ca06..70f0e57 100644 --- a/pom.xml +++ b/pom.xml @@ -171,7 +171,7 @@ maven-surefire-plugin 3.0.0-M5 - --add-opens dev.kske.undoredo/dev.kske.undoredo=ALL-UNNAMED + --add-opens dev.kske.undoredo.core/dev.kske.undoredo.core=ALL-UNNAMED -- 2.45.2