Skip to content

Commit

Permalink
#322, #295: Cleaned up a bunch of code with Lombok
Browse files Browse the repository at this point in the history
  • Loading branch information
bbottema committed Jan 2, 2022
1 parent 214b14b commit 846a746
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public interface OperationalConfig {
* Indicates whether the executor service was provided by the user or internally. Used to determine if Simple Java Mail should shut down the executor
* when the connection pool is shut down.
*/
boolean executorServiceIsUserProvided();
boolean isExecutorServiceIsUserProvided();

/**
* @see MailerGenericBuilder#withCustomMailer(CustomMailer)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package org.simplejavamail.api.mailer.config;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.simplejavamail.internal.util.MiscUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Objects;

import static java.lang.String.format;

/**
* Config holder for PKCS12 store+key info used for S/MIME encrypting / decrypting.
*/
// FIXME LOMBOK!!
@EqualsAndHashCode
public final class Pkcs12Config {

@NotNull private final byte[] pkcs12StoreData;
Expand All @@ -31,7 +29,6 @@ private Pkcs12Config(@NotNull byte[] pkcs12StoreData, @NotNull char[] storePassw
this.keyAlias = keyAlias;
this.keyPassword = keyPassword;
}

@NotNull
public static Pkcs12ConfigBuilder builder() {
return new Pkcs12ConfigBuilder();
Expand Down Expand Up @@ -68,29 +65,6 @@ public String toString() {
return sb.toString();
}

@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Pkcs12Config that = (Pkcs12Config) o;
return Arrays.equals(pkcs12StoreData, that.pkcs12StoreData) &&
Arrays.equals(storePassword, that.storePassword) &&
keyAlias.equals(that.keyAlias) &&
Arrays.equals(keyPassword, that.keyPassword);
}

@Override
public int hashCode() {
int result = Objects.hash(Arrays.hashCode(pkcs12StoreData), keyAlias);
result = 31 * result + Arrays.hashCode(storePassword);
result = 31 * result + Arrays.hashCode(keyPassword);
return result;
}

public static class Pkcs12ConfigBuilder {
private byte[] pkcs12StoreData;
private char[] storePassword;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package org.simplejavamail.internal.util;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Comparator;
import java.util.Map;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class NaturalEntryKeyComparator<T extends Comparable<T>> implements Comparator<Map.Entry<T, Object>> {

public static final NaturalEntryKeyComparator INSTANCE = new NaturalEntryKeyComparator();

// TODO Lombok
private NaturalEntryKeyComparator(){
}


@Override
public int compare(Map.Entry<T, Object> o1, Map.Entry<T, Object> o2) {
int keyComparison = o1.getKey().compareTo(o2.getKey());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.simplejavamail.internal.util.concurrent;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.CompletableFuture;
Expand All @@ -14,12 +16,9 @@
* Util that facilitates running a concurrent operation with CompletableFuture support.
*/
@SuppressWarnings("SameParameterValue")
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class AsyncOperationHelper {

// TODO Lombok
private AsyncOperationHelper() {
}

/**
* Executes using a single-execution ExecutorService, which is shutdown immediately after the operation finishes.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.simplejavamail.internal.util.concurrent;

import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

Expand All @@ -9,19 +11,14 @@
/**
* This Runnable is smart in the sense that it can shutdown the
*/
// TODO LOMBOK
@RequiredArgsConstructor
public class NamedRunnable implements Runnable {

private static final Logger LOGGER = getLogger(NamedRunnable.class);

@NotNull private final String processName;
@NotNull private final Runnable operation;

protected NamedRunnable(@NotNull String processName, @NotNull Runnable operation) {
this.processName = processName;
this.operation = operation;
}

@Override
public void run() {
// by the time the code reaches here, the user would have configured the appropriate handlers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.simplejavamail.converter.internal;

import jakarta.mail.internet.MimeMessage;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.simplejavamail.api.email.Email;
import org.simplejavamail.converter.EmailConverter;
Expand All @@ -9,13 +11,11 @@
/**
* @see InternalEmailConverter
*/
// FIXME lombok
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class InternalEmailConverterImpl implements InternalEmailConverter {

public static final InternalEmailConverter INSTANCE = new InternalEmailConverterImpl();

private InternalEmailConverterImpl() {}

@Override
public MimeMessage emailToMimeMessage(@NotNull final Email email) {
return EmailConverter.emailToMimeMessage(email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public boolean validate(@NotNull final Email email)
*/
@Override
public Future<?> shutdownConnectionPool() {
if (!operationalConfig.executorServiceIsUserProvided()) {
if (!operationalConfig.isExecutorServiceIsUserProvided()) {
operationalConfig.getExecutorService().shutdown();
}
return ModuleLoader.loadBatchModule().shutdownConnectionPools(session);
Expand Down
Loading

0 comments on commit 846a746

Please sign in to comment.