Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
as reported by IntelliJ's analysis
  • Loading branch information
mtf90 committed Dec 22, 2024
1 parent 9e03f42 commit 3c378a0
Show file tree
Hide file tree
Showing 33 changed files with 96 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ default S addInitialState(@Nullable Boolean property) {

@Override
default void setStateProperty(S state, Boolean property) {
setAccepting(state, property.booleanValue());
setAccepting(state, property);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public boolean getEdgeProperties(S src, TransitionEdge<I, T> edge, S tgt, Map<St
public boolean getNodeProperties(S node, Map<String, String> properties) {
super.getNodeProperties(node, properties);

final String oldLabel = properties.get(NodeAttrs.LABEL);
properties.put(NodeAttrs.LABEL, oldLabel + " / " + automaton.getStateProperty(node));
properties.compute(NodeAttrs.LABEL, (k, oldLabel) -> oldLabel + " / " + automaton.getStateProperty(node));

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,4 @@
* (original) state type
*/
public interface AcceptorPowersetViewTS<S, I, OS>
extends PowersetViewTS<S, I, S, OS, OS>, DeterministicAcceptorTS<S, I> {

@Override
default AcceptorPowersetViewTS<?, I, S> powersetView() {
return DeterministicAcceptorTS.super.powersetView();
}
}
extends PowersetViewTS<S, I, S, OS, OS>, DeterministicAcceptorTS<S, I> {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package net.automatalib.ts.modal;

import java.util.Collection;
import java.util.Iterator;

import net.automatalib.automaton.UniversalAutomaton;
import net.automatalib.automaton.UniversalFiniteAlphabetAutomaton;
Expand Down Expand Up @@ -47,16 +46,6 @@
public interface ModalTransitionSystem<S, I, T, TP extends ModalEdgeProperty>
extends UniversalFiniteAlphabetAutomaton<S, I, T, Void, TP> {

@Override
default Iterator<S> iterator() {
return UniversalFiniteAlphabetAutomaton.super.iterator();
}

@Override
default int size() {
return UniversalFiniteAlphabetAutomaton.super.size();
}

@Override
default UniversalGraph<S, TransitionEdge<I, T>, Void, Property<I, TP>> transitionGraphView(Collection<? extends I> inputs) {
return new MTSGraphView<>(this, inputs);
Expand Down
3 changes: 0 additions & 3 deletions api/src/main/java/net/automatalib/word/Word.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@ public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
if (!(other instanceof Word)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/test/java/net/automatalib/word/EmptyWordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class EmptyWordTest extends AbstractWordTest {

@Test
public void testLength() {
Assert.assertEquals(0, testWord.length());
Assert.assertEquals(testWord.length(), 0);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion api/src/test/java/net/automatalib/word/SharedWordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SharedWordTest extends AbstractNonemptyWordTest {

@Test
public void testLength() {
Assert.assertEquals(LENGTH, testWord.length());
Assert.assertEquals(testWord.length(), LENGTH);
}

@Override
Expand Down
72 changes: 36 additions & 36 deletions api/src/test/java/net/automatalib/word/WordBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,40 @@ public void constructorTest() {
WordBuilder<Character> wb;

wb = new WordBuilder<>();
Assert.assertEquals(0, wb.size());
Assert.assertEquals(Word.epsilon(), wb.toWord());
Assert.assertEquals(wb.size(), 0);
Assert.assertEquals(wb.toWord(), Word.epsilon());

wb = new WordBuilder<>(-1);
Assert.assertEquals(0, wb.size());
Assert.assertEquals(Word.epsilon(), wb.toWord());
Assert.assertEquals(wb.size(), 0);
Assert.assertEquals(wb.toWord(), Word.epsilon());

final Word<Character> aaaaa = Word.fromString("aaaaa");

wb = new WordBuilder<>('a', 5);
Assert.assertEquals(5, wb.size());
Assert.assertEquals(aaaaa, wb.toWord());
Assert.assertEquals(wb.size(), 5);
Assert.assertEquals(wb.toWord(), aaaaa);

wb = new WordBuilder<>(null, 5);
Assert.assertEquals(5, wb.size());
Assert.assertEquals(Word.fromSymbols(null, null, null, null, null), wb.toWord());
Assert.assertEquals(wb.size(), 5);
Assert.assertEquals(wb.toWord(), Word.fromSymbols(null, null, null, null, null));

wb = new WordBuilder<>(10, 'a', 5);
Assert.assertEquals(5, wb.size());
Assert.assertEquals(aaaaa, wb.toWord());
Assert.assertEquals(wb.size(), 5);
Assert.assertEquals(wb.toWord(), aaaaa);

wb = new WordBuilder<>(-1, 'a', 5);
Assert.assertEquals(5, wb.size());
Assert.assertEquals(aaaaa, wb.toWord());
Assert.assertEquals(wb.size(), 5);
Assert.assertEquals(wb.toWord(), aaaaa);

final Word<Character> abc = Word.fromString("abc");

wb = new WordBuilder<>(abc);
Assert.assertEquals(3, wb.size());
Assert.assertEquals(abc, wb.toWord());
Assert.assertEquals(wb.size(), 3);
Assert.assertEquals(wb.toWord(), abc);

wb = new WordBuilder<>(-1, abc);
Assert.assertEquals(3, wb.size());
Assert.assertEquals(abc, wb.toWord());
Assert.assertEquals(wb.size(), 3);
Assert.assertEquals(wb.toWord(), abc);
}

@Test
Expand All @@ -71,50 +71,50 @@ public void appendTest() {
final Word<Character> abcabcabc = abc.concat(abc, abc);

wb.append('a');
Assert.assertEquals(1, wb.size());
Assert.assertEquals(Word.fromSymbols('a'), wb.toWord());
Assert.assertEquals(wb.size(), 1);
Assert.assertEquals(wb.toWord(), Word.fromSymbols('a'));

wb.clear();
wb.append('a', 'b', 'c');
Assert.assertEquals(3, wb.size());
Assert.assertEquals(abc, wb.toWord());
Assert.assertEquals(wb.size(), 3);
Assert.assertEquals(wb.toWord(), abc);

wb.clear();
wb.append(abc);
Assert.assertEquals(3, wb.size());
Assert.assertEquals(abc, wb.toWord());
Assert.assertEquals(wb.size(), 3);
Assert.assertEquals(wb.toWord(), abc);

wb.clear();
wb.append(Arrays.asList('a', 'b', 'c'));
Assert.assertEquals(3, wb.size());
Assert.assertEquals(abc, wb.toWord());
Assert.assertEquals(wb.size(), 3);
Assert.assertEquals(wb.toWord(), abc);

wb.clear();
wb.append(abc, abc, abc);
Assert.assertEquals(9, wb.size());
Assert.assertEquals(abcabcabc, wb.toWord());
Assert.assertEquals(wb.size(), 9);
Assert.assertEquals(wb.toWord(), abcabcabc);

wb.clear();
wb.repeatAppend(3, 'a');
Assert.assertEquals(3, wb.size());
Assert.assertEquals(aaa, wb.toWord());
Assert.assertEquals(wb.size(), 3);
Assert.assertEquals(wb.toWord(), aaa);

wb.clear();
wb.repeatAppend(3, abc);
Assert.assertEquals(9, wb.size());
Assert.assertEquals(abcabcabc, wb.toWord());
Assert.assertEquals(wb.size(), 9);
Assert.assertEquals(wb.toWord(), abcabcabc);


final int bigChunkSize = 27;
wb.clear();
wb.repeatAppend(bigChunkSize, abc);
Assert.assertEquals(bigChunkSize * 3, wb.size());
Assert.assertEquals(wb.size(), bigChunkSize * 3);

Word<Character> buffer = Word.epsilon();
for (int i = 0; i < bigChunkSize; i++) {
buffer = buffer.concat(abc);
}
Assert.assertEquals(buffer, wb.toWord());
Assert.assertEquals(wb.toWord(), buffer);
}

@Test
Expand All @@ -124,7 +124,7 @@ public void reverseTest() {
final Word<Character> cba = Word.fromString("cba");

wb.append(abc).reverse();
Assert.assertEquals(cba, wb.toWord());
Assert.assertEquals(wb.toWord(), cba);
}

@Test
Expand All @@ -133,7 +133,7 @@ public void toWordTest() {
final Word<Character> abc = Word.fromString("abc");

wb.repeatAppend(3, abc);
Assert.assertEquals(abc, wb.toWord(3, 6));
Assert.assertEquals(wb.toWord(3, 6), abc);

Assert.assertThrows(IndexOutOfBoundsException.class, () -> wb.toWord(-1, wb.size()));
Assert.assertThrows(IndexOutOfBoundsException.class, () -> wb.toWord(0, wb.size() + 1));
Expand All @@ -147,11 +147,11 @@ public void truncateTest() {
final Word<Character> abcabcabc = abcabc.concat(abc);

wb.repeatAppend(3, abc).truncate(12);
Assert.assertEquals(abcabcabc, wb.toWord());
Assert.assertEquals(wb.toWord(), abcabcabc);

wb.clear();
wb.repeatAppend(3, abc).truncate(6);
Assert.assertEquals(abcabc, wb.toWord());
Assert.assertEquals(wb.toWord(), abcabc);
}

}
30 changes: 15 additions & 15 deletions api/src/test/java/net/automatalib/word/WordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public void fromTest() {
Assert.assertEquals(Word.fromArray(referenceAsArray, 0, 0), Word.epsilon());

final Word<Character> wordFromArray = Word.fromArray(referenceAsArray, 1, 2);
Assert.assertEquals(wordFromArray, reference.subWord(1));
Assert.assertEquals(reference.subWord(1), wordFromArray);

// check that mutating the source does not alter the word
referenceAsArray[1] = 'x';
Assert.assertEquals(wordFromArray, reference.subWord(1));
Assert.assertEquals(reference.subWord(1), wordFromArray);
}

@Test
Expand All @@ -64,24 +64,24 @@ public void toArrayTest() {

referenceAsArray = new Character[3];
reference.writeToArray(0, referenceAsArray, 0, 3);
Assert.assertEquals('a', referenceAsArray[0].charValue());
Assert.assertEquals('b', referenceAsArray[1].charValue());
Assert.assertEquals('c', referenceAsArray[2].charValue());
Assert.assertEquals(referenceAsArray[0].charValue(), 'a');
Assert.assertEquals(referenceAsArray[1].charValue(), 'b');
Assert.assertEquals(referenceAsArray[2].charValue(), 'c');

referenceAsArray = new Character[1];
reference.writeToArray(2, referenceAsArray, 0, 1);
Assert.assertEquals('c', referenceAsArray[0].charValue());
Assert.assertEquals(referenceAsArray[0].charValue(), 'c');

referenceAsArray = new Character[3];
reference.writeToArray(1, referenceAsArray, 2, 1);
Assert.assertNull(referenceAsArray[0]);
Assert.assertNull(referenceAsArray[1]);
Assert.assertEquals('b', referenceAsArray[2].charValue());
Assert.assertEquals(referenceAsArray[2].charValue(), 'b');

final int[] wordAsInt = reference.toIntArray(x -> x - 'a');
Assert.assertEquals(0, wordAsInt[0]);
Assert.assertEquals(1, wordAsInt[1]);
Assert.assertEquals(2, wordAsInt[2]);
Assert.assertEquals(wordAsInt[0], 0);
Assert.assertEquals(wordAsInt[1], 1);
Assert.assertEquals(wordAsInt[2], 2);
}

@Test
Expand All @@ -91,7 +91,7 @@ public void transformTest() {

final Word<String> transform = source.transform(c -> new String(new char[] {c, c}));

Assert.assertEquals(target, transform);
Assert.assertEquals(transform, target);
}

@Test
Expand All @@ -101,10 +101,10 @@ public void subwordTest() {
final Word<Character> bc = Word.fromSymbols('b', 'c');
final Word<Character> abc = Word.fromString("abc");

Assert.assertEquals(c, abc.subWord(2));
Assert.assertEquals(bc, abc.subWord(1));
Assert.assertEquals(abc, abc.subWord(0));
Assert.assertEquals(b, abc.subWord(1, 2));
Assert.assertEquals(abc.subWord(2), c);
Assert.assertEquals(abc.subWord(1), bc);
Assert.assertEquals(abc.subWord(0), abc);
Assert.assertEquals(abc.subWord(1, 2), b);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public abstract class AbstractLinkedList<E, T extends LinkedListEntry<E, T>> ext
* @param other
* the list to append,
*/
@SuppressWarnings("unchecked")
public void concat(AbstractLinkedList<? extends E, ? extends T> other) {
if (other.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public void testUnknownSystemLibrary() {

private void checkGreeter() {
final NativeGreeter nativeGreeter = new NativeGreeter();
Assert.assertEquals("Hello John", nativeGreeter.greet("John"));
Assert.assertEquals(nativeGreeter.greet("John"), "Hello John");
}
}
1 change: 0 additions & 1 deletion core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
open module net.automatalib.core {

requires net.automatalib.api;
requires net.automatalib.common.smartcollection;
requires net.automatalib.common.util;

// make non-static once https://github.com/typetools/checker-framework/issues/4559 is implemented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public int getIntInitialState() {

@Override
public void setTransition(Integer state, I input, @Nullable T transition) {
setTransition(state.intValue(), getSymbolIndex(input), transition);
setTransition(state, getSymbolIndex(input), transition);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public int getSuccessor(int state, int input) {
@Override
// Overridden for performance reasons (to prevent autoboxing of default implementation)
public @Nullable Integer getSuccessor(Integer state, Iterable<? extends I> input) {
return toState(getIntSuccessor(state.intValue(), input));
return toState(getIntSuccessor(state, input));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testConfluenceBug() {

@Test(dependsOnMethods = "testConfluenceBug")
public void testLookup() {
Assert.assertEquals(Acceptance.DONT_KNOW, incDfa.lookup(W_1));
Assert.assertEquals(incDfa.lookup(W_1), Acceptance.DONT_KNOW);
Assert.assertEquals(incDfa.lookup(W_2), Acceptance.DONT_KNOW);
Assert.assertEquals(incDfa.lookup(W_3), Acceptance.DONT_KNOW);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ public void testAges() {
for (Pair<Word<Character>, Word<Character>> word : words) {
adaptiveMealy.insert(word.getFirst(), word.getSecond());
}
Assert.assertEquals(W_1, adaptiveMealy.getOldestInput());
Assert.assertEquals(adaptiveMealy.getOldestInput(), W_1);
adaptiveMealy.insert(W_1, W_1_O);
Assert.assertEquals(W_2, adaptiveMealy.getOldestInput());
Assert.assertEquals(adaptiveMealy.getOldestInput(), W_2);
adaptiveMealy.insert(W_2, W_2_O);
Assert.assertEquals(W_3, adaptiveMealy.getOldestInput());
Assert.assertEquals(adaptiveMealy.getOldestInput(), W_3);
adaptiveMealy.insert(W_3, W_3_O);
Assert.assertEquals(W_1, adaptiveMealy.getOldestInput());
Assert.assertEquals(adaptiveMealy.getOldestInput(), W_1);
}

@Test(dependsOnMethods = "testLookup")
Expand Down
Loading

0 comments on commit 3c378a0

Please sign in to comment.