Skip to content

Commit

Permalink
Removed some code smells.
Browse files Browse the repository at this point in the history
Signed-off-by: Juergen Fickel <juergen.fickel@bosch.io>
  • Loading branch information
Juergen Fickel committed Jun 3, 2022
1 parent ea4cae7 commit 5e770ad
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -631,12 +632,33 @@ public String getClientId() {
return clientId;
}

@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
final var that = (JmsConnect) o;
return Objects.equals(clientId, that.clientId);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), clientId);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" + super.toString() +
", clientId=" + clientId +
"]";
}

}

/**
Expand All @@ -647,8 +669,10 @@ static final class JmsRecoverSession extends AbstractWithOrigin implements Recov
private final javax.jms.Connection connection;
@Nullable private final Session session;

JmsRecoverSession(@Nullable final ActorRef origin, @Nullable final javax.jms.Connection connection,
JmsRecoverSession(@Nullable final ActorRef origin,
@Nullable final javax.jms.Connection connection,
@Nullable final Session session) {

super(origin);
this.connection = connection;
this.session = session;
Expand All @@ -662,13 +686,34 @@ Optional<javax.jms.Session> getSession() {
return Optional.ofNullable(session);
}

@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
final var that = (JmsRecoverSession) o;
return Objects.equals(connection, that.connection) && Objects.equals(session, that.session);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), connection, session);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" + super.toString() +
", connection=" + connection +
", session=" + session +
"]";
}

}

/**
Expand All @@ -687,12 +732,33 @@ javax.jms.Session getSession() {
return session;
}

@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
final var that = (JmsCloseSession) o;
return Objects.equals(session, that.session);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), session);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" + super.toString() +
", session=" + session +
"]";
}

}

/**
Expand All @@ -703,8 +769,10 @@ static final class JmsDisconnect extends AbstractWithOrigin implements Disconnec
@Nullable private final javax.jms.Connection connection;
private final boolean shutdownAfterDisconnect;

JmsDisconnect(@Nullable final ActorRef origin, @Nullable final javax.jms.Connection connection,
JmsDisconnect(@Nullable final ActorRef origin,
@Nullable final javax.jms.Connection connection,
final boolean shutdownAfterDisconnect) {

super(origin);
this.connection = connection;
this.shutdownAfterDisconnect = shutdownAfterDisconnect;
Expand All @@ -718,13 +786,35 @@ boolean isShutdownAfterDisconnect() {
return shutdownAfterDisconnect;
}

@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
final var that = (JmsDisconnect) o;
return shutdownAfterDisconnect == that.shutdownAfterDisconnect &&
Objects.equals(connection, that.connection);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), connection, shutdownAfterDisconnect);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" + super.toString() +
", connection=" + connection +
", shutdownAfterDisconnect=" + shutdownAfterDisconnect +
"]";
}

}

/**
Expand All @@ -747,6 +837,28 @@ static final class JmsConnected extends AbstractWithOrigin implements ClientConn
this.consumerList = consumerList;
}

@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
final var that = (JmsConnected) o;
return Objects.equals(connection, that.connection) &&
Objects.equals(session, that.session) &&
Objects.equals(consumerList, that.consumerList);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), connection, session, consumerList);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" + super.toString() +
Expand All @@ -755,6 +867,7 @@ public String toString() {
", consumerList=" + consumerList +
"]";
}

}

/**
Expand Down Expand Up @@ -783,13 +896,34 @@ List<ConsumerData> getConsumerList() {
return consumerList;
}

@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
final var that = (JmsSessionRecovered) o;
return Objects.equals(session, that.session) && Objects.equals(consumerList, that.consumerList);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), session, consumerList);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" + super.toString() +
", session=" + session +
", consumerList=" + consumerList +
"]";
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.eclipse.ditto.connectivity.service.messaging.internal;

import java.util.Objects;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

Expand All @@ -35,10 +37,31 @@ public boolean shutdownAfterDisconnected() {
return shutdownAfterDisconnected;
}

@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
final var that = (ImmutableClientDisconnected) o;
return shutdownAfterDisconnected == that.shutdownAfterDisconnected;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), shutdownAfterDisconnected);
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" + super.toString() +
", shutdownAfterDisconnected=" + shutdownAfterDisconnected +
"]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@

import java.io.Serial;
import java.util.List;
import java.util.Objects;

import javax.annotation.Nullable;

import org.eclipse.ditto.base.model.common.ConditionChecker;
import org.eclipse.ditto.connectivity.service.messaging.mqtt.hivemq.message.subscribe.GenericMqttSubscribe;

/**
* This is exception is thrown to indicate that all subscriptions of an MQTT Subscribe message
* ({@link GenericMqttSubscribe}) failed.
*/
public final class AllSubscriptionsFailedException extends MqttSubscribeException {
public final class AllSubscriptionsFailedException extends SubscriptionsFailedException {

@Serial private static final long serialVersionUID = 4004096047016339725L;

private final transient List<SubscriptionStatus> failedSubscriptionStatuses;

/**
* Constructs a new {@code AllSubscriptionsFailedException} object.
*
Expand All @@ -42,35 +38,7 @@ public final class AllSubscriptionsFailedException extends MqttSubscribeExceptio
public AllSubscriptionsFailedException(final List<SubscriptionStatus> failedSubscriptionStatuses,
@Nullable final Throwable cause) {

super(cause);
ConditionChecker.argumentNotEmpty(failedSubscriptionStatuses, "failedSubscriptionStatuses");
this.failedSubscriptionStatuses = List.copyOf(failedSubscriptionStatuses);
}

/**
* Returns an unmodifiable unsorted List containing the status of each failed subscription.
*
* @return the failed subscription statuses.
*/
public List<SubscriptionStatus> getFailedSubscriptionStatuses() {
return failedSubscriptionStatuses;
}

@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final var that = (AllSubscriptionsFailedException) o;
return Objects.equals(failedSubscriptionStatuses, that.failedSubscriptionStatuses);
}

@Override
public int hashCode() {
return Objects.hash(failedSubscriptionStatuses);
super(failedSubscriptionStatuses, cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
* This exception is thrown to indicate that subscribing a client via one or multiple Subscribe messages
* ({@link GenericMqttSubscribe}) failed for some reason.
*/
public sealed class MqttSubscribeException extends RuntimeException
permits AllSubscriptionsFailedException, SomeSubscriptionsFailedException {
public sealed class MqttSubscribeException extends RuntimeException permits SubscriptionsFailedException {

@Serial private static final long serialVersionUID = 1936431587204652088L;

Expand Down
Loading

0 comments on commit 5e770ad

Please sign in to comment.