Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelmay committed Mar 4, 2022
1 parent f1f965a commit 744ec71
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.icegreen.greenmail.configuration;

import java.util.Objects;

/**
* A user to create when servers start
*/
Expand Down Expand Up @@ -58,9 +60,9 @@ public boolean equals(Object o) { // nosonar

UserBean userBean = (UserBean) o;

if (email != null ? !email.equals(userBean.email) : userBean.email != null) return false;
if (login != null ? !login.equals(userBean.login) : userBean.login != null) return false;
return !(password != null ? !password.equals(userBean.password) : userBean.password != null);
if (!Objects.equals(email, userBean.email)) return false;
if (!Objects.equals(login, userBean.login)) return false;
return Objects.equals(password, userBean.password);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Darrell DeBoer <[email protected]>
*/
public final class ImapRequestHandler {
protected final Logger log = LoggerFactory.getLogger(getClass());
private final Logger log = LoggerFactory.getLogger(getClass());
private final ImapCommandFactory imapCommands = new ImapCommandFactory();
private final CommandParser parser = new CommandParser();
private static final String REQUEST_SYNTAX = "Protocol Error: Was expecting <tag SPACE command [arguments]>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ abstract class CommandTemplate
implements ImapCommand, ImapConstants {
protected final Logger log = LoggerFactory.getLogger(getClass());
protected CommandParser parser = new CommandParser();
private String name;
private String argSyntax;
private final String name;
private final String argSyntax;

CommandTemplate(String name, String argSyntax) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void doProcess(ImapRequestLineReader request,
}
}

// Always send COPYUID, even if not UID MOVE
// Always send COPYUID, even if not UID MOVE
response.okResponse(CopyCommand.generateCopyUidResponseCode(toFolder, copiedUidsOld, copiedUidsNew), "");

session.unsolicitedResponses(response); // EXPUNGE responses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ StoreDirective storeDirective(ImapRequestLineReader request) throws ProtocolExce
} else if (next == '-') {
sign = -1;
request.consume();
} else {
sign = 0;
}
} // else default 0

String directive = consumeWord(request, new NoopCharValidator());
if ("FLAGS".equalsIgnoreCase(directive)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private String getCc(StoredMessage message) throws MessagingException {
return String.valueOf(addresses[0]);
}

private int doCompare(Comparable c1, Comparable c2) {
private <T extends Comparable<T>> int doCompare(T c1, T c2) {
int multiplier = reverse.getAndSet(false) ? -1 : 1;
if (c1 == c2) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String readLine() throws IOException {
int b = in.read();
if (b < 0) { // End
if (log.isDebugEnabled()) {
log.debug("Unexpected end of stream, read {} bytes: {}", bos.size(), bos.toString());
log.debug("Unexpected end of stream, read {} bytes: {}", bos.size(), bos);
}
if (bos.size() > 0) {
// Best effort?
Expand Down Expand Up @@ -102,7 +102,7 @@ public InputStream dotLimitedInputStream(byte[] initialContent) {
while (true) {
int b = in.read();
if (b < 0) {
throw new IllegalStateException("Unexpected end of stream, read " + bos.size() + " bytes: " + bos.toString());
throw new IllegalStateException("Unexpected end of stream, read " + bos.size() + " bytes: " + bos);
}

if (cbuf == CR_LF_DOT_CR && b == '\n') { // CRLF-DOT-CRLF
Expand All @@ -122,7 +122,7 @@ public InputStream dotLimitedInputStream(byte[] initialContent) {
cbuf = (cbuf << 8) | b;
}
} catch (IOException ex) {
throw new IllegalStateException("Can not read line, read " + bos.size() + " bytes: " + bos.toString(), ex);
throw new IllegalStateException("Can not read line, read " + bos.size() + " bytes: " + bos, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public SmtpManager(ImapHostManager imapHostManager, UserManager userManager) {
this.imapHostManager = imapHostManager;
this.userManager = userManager;
incomingQueue = new Incoming();
notifyList = Collections.synchronizedList(new ArrayList<CountDownLatch>());
notifyList = Collections.synchronizedList(new ArrayList<>());
}


Expand Down Expand Up @@ -94,4 +94,4 @@ private void handle(MovingMessage msg, MailAddress mailAddress) {
public UserManager getUserManager() {
return userManager;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static byte[] getHeaderAsBytes(Part part) {
}

/**
* @return same as {@link #getWholeMessage(javax.mail.Part)} }
* @return same as {@link #getWholeMessage(jakarta.mail.Part)} }
*/
public static String toString(Part msg) {
return getWholeMessage(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public ServerSetup[] build(Properties properties) {
}
}

return serverSetups.toArray(new ServerSetup[serverSetups.size()]);
return serverSetups.toArray(new ServerSetup[0]);
}

protected void addSetup(String hostname, String protocol, Properties properties, List<ServerSetup> serverSetups) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package com.icegreen.greenmail.util;

import java.util.Objects;
import java.util.Properties;

/**
Expand Down Expand Up @@ -290,9 +291,8 @@ public boolean equals(Object o) {
if (connectionTimeout != that.connectionTimeout) return false;
if (writeTimeout != that.writeTimeout) return false;
if (serverStartupTimeout != that.serverStartupTimeout) return false;
if (bindAddress != null ? !bindAddress.equals(that.bindAddress) : that.bindAddress != null) return false;
return !(protocol != null ? !protocol.equals(that.protocol) : that.protocol != null);

if (!Objects.equals(bindAddress, that.bindAddress)) return false;
return Objects.equals(protocol, that.protocol);
}

@Override
Expand Down Expand Up @@ -375,7 +375,7 @@ public static ServerSetup[] verbose(ServerSetup[] serverSetups) {
}

/**
* Creates a copy with dynamic ports (auto detecting available ports) enabled.
* Creates a copy with dynamic ports (auto-detecting available ports) enabled.
*
* @param serverSetups the server setups.
* @return copies of server setups with verbose mode enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public void testSort() throws Exception {
* @param session Session to set on the messages
* @param folder Folder to add to
* @param flags Flags to set on both messages
* @throws Exception
*/
private void storeSortTestMessages(Session session, MailFolder folder, Flags flags) throws Exception {
MimeMessage message1 = new MimeMessage(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private ServerSetup[] createServerSetup() {
if (imapsProtocol) {
setups.add(createTestServerSetup(ServerSetup.IMAPS));
}
return setups.toArray(new ServerSetup[setups.size()]);
return setups.toArray(new ServerSetup[0]);
}

/** Starts the server. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GreenMailBeanDefinitionParser extends AbstractSingleBeanDefinitionP
/** The default hostname ({@value}). */
public static final String DEFAULT_HOSTNAME = "localhost";
/** The default port offset ({@value}). */
private static final Integer DEFAULT_PORT_OFFSET = Integer.valueOf(3000);
private static final Integer DEFAULT_PORT_OFFSET = 3000;
/** The default time to wait for server startup in millis ({@value}). */
public static final long DEFAULT_SERVER_STARTUP_TIMEOUT = 1000L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
import com.icegreen.greenmail.util.PropertiesBasedServerSetupBuilder;
import com.icegreen.greenmail.util.ServerSetup;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

import java.io.PrintStream;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum Protocol {
IMAPS(993);

/** The default port. */
int port;
final int port;

/** Private constructor, including default port */
Protocol(final int pPort) {
Expand All @@ -44,6 +44,6 @@ static Protocol findByPort(int pPort) {

@Override
public String toString() {
return name() + '(' +Integer.toString(port)+')';
return name() + '(' + port +')';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ConfigurationFactoryTest {

@Test
public void testCreate() {
Map<String, String> paramValues = new HashMap<String, String>();
Map<String, String> paramValues = new HashMap<>();
paramValues.put("greenmail.defaultHostname", "127.0.0.1");
paramValues.put("greenmail.portOffset", "20000");
paramValues.put("greenmail.smtp", "");
Expand Down

0 comments on commit 744ec71

Please sign in to comment.