Skip to content

Commit

Permalink
drop lombok dependency
Browse files Browse the repository at this point in the history
replace @EqualsAndHashCode with self-supplied "equals" and "hashcode" implementations according to "Effective Java" best practices. Speeds up the build process and reduces the dependencies on other projects.
  • Loading branch information
mtf90 committed Nov 27, 2018
1 parent 5d31f54 commit b00ecd0
Show file tree
Hide file tree
Showing 21 changed files with 285 additions and 79 deletions.
4 changes: 0 additions & 4 deletions adapters/brics/pom.xml
Expand Up @@ -40,10 +40,6 @@ limitations under the License.
<artifactId>automata-api</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down
Expand Up @@ -16,14 +16,12 @@
package net.automatalib.brics;

import dk.brics.automaton.Transition;
import lombok.EqualsAndHashCode;

/**
* The properties of an edge in a Brics automaton.
*
* @author Malte Isberner
*/
@EqualsAndHashCode
public class BricsTransitionProperty {

private final char min;
Expand Down Expand Up @@ -88,4 +86,24 @@ public static String toString(char min, char max) {
return sb.toString();
}

@Override
public final boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof BricsTransitionProperty)) {
return false;
}

final BricsTransitionProperty that = (BricsTransitionProperty) o;
return min == that.min && max == that.max;
}

@Override
public final int hashCode() {
int result = 1;
result = 31 * result + Character.hashCode(min);
result = 31 * result + Character.hashCode(max);
return result;
}
}
5 changes: 0 additions & 5 deletions api/pom.xml
Expand Up @@ -59,11 +59,6 @@ limitations under the License.
<artifactId>metainf-services</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
Expand Up @@ -15,10 +15,10 @@
*/
package net.automatalib.automata.graphs;

import lombok.EqualsAndHashCode;
import java.util.Objects;

import net.automatalib.ts.UniversalTransitionSystem;

@EqualsAndHashCode
public final class TransitionEdge<I, T> {

private final I input;
Expand All @@ -41,7 +41,27 @@ public <TP> Property<I, TP> property(UniversalTransitionSystem<?, ?, T, ?, TP> u
return new Property<>(input, uts.getTransitionProperty(transition));
}

@EqualsAndHashCode
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof TransitionEdge)) {
return false;
}

final TransitionEdge<?, ?> that = (TransitionEdge<?, ?>) o;
return Objects.equals(input, that.input) && Objects.equals(transition, that.transition);
}

@Override
public int hashCode() {
int result = 1;
result = 31 * result + Objects.hashCode(input);
result = 31 * result + Objects.hashCode(transition);
return result;
}

public static final class Property<I, TP> {

private final I input;
Expand All @@ -59,5 +79,26 @@ public I getInput() {
public TP getProperty() {
return property;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Property)) {
return false;
}

final Property<?, ?> that = (Property<?, ?>) o;
return Objects.equals(input, that.input) && Objects.equals(property, that.property);
}

@Override
public int hashCode() {
int result = 1;
result = 31 * result + Objects.hashCode(input);
result = 31 * result + Objects.hashCode(property);
return result;
}
}
}
Expand Up @@ -15,13 +15,12 @@
*/
package net.automatalib.automata.transducers.probabilistic;

import java.util.Objects;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import lombok.EqualsAndHashCode;

@ParametersAreNonnullByDefault
@EqualsAndHashCode
public final class ProbabilisticOutput<O> {

private final float probability;
Expand All @@ -41,4 +40,25 @@ public float getProbability() {
public O getOutput() {
return output;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ProbabilisticOutput)) {
return false;
}

final ProbabilisticOutput<?> that = (ProbabilisticOutput<?>) o;
return Float.compare(probability, that.probability) == 0 && Objects.equals(output, that.output);
}

@Override
public int hashCode() {
int result = 1;
result = 31 * result + Float.hashCode(probability);
result = 31 * result + Objects.hashCode(output);
return result;
}
}
5 changes: 0 additions & 5 deletions commons/smartcollections/pom.xml
Expand Up @@ -47,11 +47,6 @@ limitations under the License.
<artifactId>jsr305</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
Expand Up @@ -17,12 +17,11 @@

import java.io.Serializable;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Collection;
import java.util.RandomAccess;
import java.util.function.Supplier;

import lombok.EqualsAndHashCode;

/**
* A thin wrapper around a simple {@code Object[]} array. Mainly used (and useful) for heavily generic and array-based
* data storage. Extends/Implements some convenient classes/interfaces.
Expand All @@ -32,8 +31,7 @@
*
* @author frohme
*/
@EqualsAndHashCode(callSuper = false)
public class ArrayStorage<T> extends AbstractList<T> implements RandomAccess, Serializable, Cloneable {
public final class ArrayStorage<T> extends AbstractList<T> implements RandomAccess, Serializable, Cloneable {

private final Object[] storage;

Expand Down Expand Up @@ -78,4 +76,22 @@ public int size() {
public ArrayStorage<T> clone() {
return new ArrayStorage<>(storage.clone());
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ArrayStorage)) {
return false;
}

final ArrayStorage<?> that = (ArrayStorage<?>) o;
return Arrays.equals(storage, that.storage);
}

@Override
public int hashCode() {
return Arrays.hashCode(storage);
}
}
4 changes: 0 additions & 4 deletions commons/util/pom.xml
Expand Up @@ -51,10 +51,6 @@ limitations under the License.
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.testng</groupId>
Expand Down
24 changes: 22 additions & 2 deletions commons/util/src/main/java/net/automatalib/commons/util/Pair.java
Expand Up @@ -17,8 +17,8 @@

import java.io.IOException;
import java.io.Serializable;
import java.util.Objects;

import lombok.EqualsAndHashCode;
import net.automatalib.commons.util.strings.AbstractPrintable;
import net.automatalib.commons.util.strings.StringUtil;

Expand All @@ -39,7 +39,6 @@
* @author Malte Isberner
* @author frohme
*/
@EqualsAndHashCode(callSuper = false)
public final class Pair<T1, T2> extends AbstractPrintable implements Serializable {

private static final long serialVersionUID = -1L;
Expand Down Expand Up @@ -76,4 +75,25 @@ public void print(Appendable a) throws IOException {
a.append(", ");
StringUtil.appendObject(a, second);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Pair)) {
return false;
}

final Pair<?, ?> that = (Pair<?, ?>) o;
return Objects.equals(first, that.first) && Objects.equals(second, that.second);
}

@Override
public int hashCode() {
int result = 1;
result = 31 * result + Objects.hashCode(first);
result = 31 * result + Objects.hashCode(second);
return result;
}
}
Expand Up @@ -17,8 +17,8 @@

import java.io.IOException;
import java.io.Serializable;
import java.util.Objects;

import lombok.EqualsAndHashCode;
import net.automatalib.commons.util.strings.AbstractPrintable;
import net.automatalib.commons.util.strings.StringUtil;

Expand All @@ -41,7 +41,6 @@
* @author Malte Isberner
* @author frohme
*/
@EqualsAndHashCode(callSuper = false)
public final class Triple<T1, T2, T3> extends AbstractPrintable implements Serializable {

private static final long serialVersionUID = -1L;
Expand Down Expand Up @@ -87,4 +86,26 @@ public void print(Appendable a) throws IOException {
StringUtil.appendObject(a, third);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Triple)) {
return false;
}

final Triple<?, ?, ?> that = (Triple<?, ?, ?>) o;
return Objects.equals(first, that.first) && Objects.equals(second, that.second) &&
Objects.equals(third, that.third);
}

@Override
public int hashCode() {
int result = 1;
result = 31 * result + Objects.hashCode(first);
result = 31 * result + Objects.hashCode(second);
result = 31 * result + Objects.hashCode(third);
return result;
}
}
4 changes: 0 additions & 4 deletions core/pom.xml
Expand Up @@ -67,10 +67,6 @@ limitations under the License.
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.testng</groupId>
Expand Down
Expand Up @@ -16,11 +16,9 @@
package net.automatalib.automata.transducers.impl.compact;

import java.io.Serializable;
import java.util.Objects;

import lombok.EqualsAndHashCode;

@EqualsAndHashCode
public class CompactMealyTransition<O> implements Serializable {
public final class CompactMealyTransition<O> implements Serializable {

private int memoryIdx;
private final int succId;
Expand Down Expand Up @@ -59,4 +57,26 @@ void setMemoryIdx(int memoryIdx) {
boolean isAutomatonTransition() {
return memoryIdx >= 0;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof CompactMealyTransition)) {
return false;
}

final CompactMealyTransition<?> that = (CompactMealyTransition<?>) o;
return memoryIdx == that.memoryIdx && succId == that.succId && Objects.equals(output, that.output);
}

@Override
public int hashCode() {
int result = 1;
result = 31 * result + Integer.hashCode(memoryIdx);
result = 31 * result + Integer.hashCode(succId);
result = 31 * result + Objects.hashCode(output);
return result;
}
}

0 comments on commit b00ecd0

Please sign in to comment.