Skip to content

Commit

Permalink
hapifhir#42: move to Java 8 remove a LOT of warnings and update some …
Browse files Browse the repository at this point in the history
…dependencies
  • Loading branch information
ohr committed May 27, 2020
1 parent 1b8c0eb commit d09c11c
Show file tree
Hide file tree
Showing 473 changed files with 3,208 additions and 3,820 deletions.
4 changes: 2 additions & 2 deletions hapi-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<!-- make sure our code doesn't have 1.5+ dependencies except where we know it -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.13</version>
<version>1.16</version>
<executions>
<execution>
<id>check-java-version</id>
Expand All @@ -108,7 +108,7 @@
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java16</artifactId>
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
<ignores>
Expand Down
11 changes: 2 additions & 9 deletions hapi-base/src/main/java/ca/uhn/hl7v2/DefaultHapiContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public DefaultHapiContext(HapiContext context) {
.getModelClassFactory());
}

public void close() throws IOException {
public void close() {
getConnectionHub().discardAll();
if (DefaultExecutorService.isDefaultService(executorService)) {
executorService.shutdownNow();
Expand All @@ -151,14 +151,7 @@ public void close() throws IOException {
public synchronized ExecutorService getExecutorService() {
if (executorService == null) {
executorService = DefaultExecutorService.getDefaultService();
Runtime.getRuntime().addShutdownHook(new Thread() {

@Override
public void run() {
executorService.shutdownNow();
}

});
Runtime.getRuntime().addShutdownHook(new Thread(() -> executorService.shutdownNow()));
}
return executorService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static HapiContext unmodifiableContext(HapiContext context) {

private static class UnmodifiableHapiContext implements HapiContext {

private HapiContext context;
private final HapiContext context;

public UnmodifiableHapiContext(HapiContext context) {
this.context = context;
Expand Down
15 changes: 7 additions & 8 deletions hapi-base/src/main/java/ca/uhn/hl7v2/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ GNU General Public License (the "GPL"), in which case the provisions of the GPL
*/
public class Location {

private Stack<GroupLocation> groups = new Stack<GroupLocation>();
private Stack<GroupLocation> groups = new Stack<>();
private String segmentName = null;
private int segmentRepetition = 0;
private int field = -1;
Expand All @@ -52,14 +52,15 @@ public Location() {
}

public Location(Location l) {
this.groups = new Stack<GroupLocation>();
this.groups = new Stack<>();
groups.addAll(l.groups);
this.segmentName = l.segmentName;
this.segmentRepetition = l.segmentRepetition;
this.field = l.field;
this.fieldRepetition = l.fieldRepetition;
this.component = l.component;
this.subcomponent = l.subcomponent;
this.componentLevel = l.componentLevel;
}

public Collection<GroupLocation> getGroups() {
Expand Down Expand Up @@ -240,14 +241,12 @@ public boolean equals(Object obj) {
return false;
if (segmentRepetition != other.segmentRepetition)
return false;
if (subcomponent != other.subcomponent)
return false;
return true;
}
return subcomponent == other.subcomponent;
}

public static class GroupLocation {
String groupName;
int repetition;
final String groupName;
final int repetition;

private GroupLocation(String groupName, int repetition) {
this.groupName = groupName;
Expand Down
2 changes: 1 addition & 1 deletion hapi-base/src/main/java/ca/uhn/hl7v2/Severity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public enum Severity {
private final String code;
private final String message;

private Severity(String code, String message) {
Severity(String code, String message) {
this.code = code;
this.message = message;
}
Expand Down
39 changes: 17 additions & 22 deletions hapi-base/src/main/java/ca/uhn/hl7v2/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ GNU General Public License (the "GPL"), in which case the provisions of the GPL
*/
package ca.uhn.hl7v2;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

Expand All @@ -47,9 +48,9 @@ public enum Version {
V28("2.8"), // -
V281("2.8.1"); // -

private String version;
private final String version;
private static ArrayList<Version> ourVersionsOnClasspath;
private static final Map<Version, Boolean> ourIsOnClasspath = new HashMap<Version, Boolean>();
private static final Map<Version, Boolean> ourIsOnClasspath = new HashMap<>();

Version(String version) {
this.version = version;
Expand Down Expand Up @@ -115,29 +116,29 @@ public static Version latestVersion() {
}

public static Version[] asOf(Version v) {
List<Version> versions = new ArrayList<Version>();
List<Version> versions = new ArrayList<>();
for (Version version : Version.values()) {
if (version.compareTo(v) >= 0)
versions.add(version);
}
return versions.toArray(new Version[versions.size()]);
return versions.toArray(new Version[0]);
}

public static Version[] except(Version... v) {
Set<Version> versions = new HashSet<Version>(Arrays.asList(Version.values()));
Set<Version> versions = new HashSet<>(Arrays.asList(Version.values()));
for (Version version : v) {
versions.remove(version);
}
return versions.toArray(new Version[versions.size()]);
return versions.toArray(new Version[0]);
}

public static Version[] before(Version v) {
List<Version> versions = new ArrayList<Version>();
List<Version> versions = new ArrayList<>();
for (Version version : Version.values()) {
if (version.compareTo(v) < 0)
versions.add(version);
}
return versions.toArray(new Version[versions.size()]);
return versions.toArray(new Version[0]);
}

public String modelPackageName() {
Expand All @@ -156,19 +157,13 @@ public synchronized boolean available() {
Boolean retVal = ourIsOnClasspath.get(this);
if (retVal == null) {
String resource = "ca/uhn/hl7v2/parser/eventmap/" + getVersion() + ".properties";
InputStream in = Parser.class.getClassLoader().getResourceAsStream(resource);
try {
retVal = in != null;
ourIsOnClasspath.put(this, retVal);
} finally {
if (in != null) {
try {
in.close();
} catch (Exception e) {
// Ignore
}
}
}
try (InputStream in = Parser.class.getClassLoader().getResourceAsStream(resource)) {
retVal = in != null;
ourIsOnClasspath.put(this, retVal);
} catch (IOException e) {
throw new RuntimeException(e);
}
// Ignore
}
return retVal;
}
Expand All @@ -179,7 +174,7 @@ public synchronized boolean available() {
*/
public static synchronized List<Version> availableVersions() {
if (ourVersionsOnClasspath == null) {
ourVersionsOnClasspath = new ArrayList<Version>();
ourVersionsOnClasspath = new ArrayList<>();
for (Version next : values()) {
if (next.available()) {
ourVersionsOnClasspath.add(next);
Expand Down
31 changes: 11 additions & 20 deletions hapi-base/src/main/java/ca/uhn/hl7v2/VersionLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,17 @@ private static void checkStructureLibraries() {
}

private static void printHapiVersion() {
InputStream is = null;
try {
is = VersionLogger.class
.getResourceAsStream("/ca/uhn/hl7v2/hapi-version.properties");
Properties p = new Properties();
p.load(is);
ourVersion = p.getProperty("version");
LOG.info("HAPI version is: " + ourVersion);
} catch (IOException e) {
LOG.warn("Unable to determine HAPI version information", e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// ignore
}
}
}
}
try (InputStream is = VersionLogger.class
.getResourceAsStream("/ca/uhn/hl7v2/hapi-version.properties")) {
Properties p = new Properties();
p.load(is);
ourVersion = p.getProperty("version");
LOG.info("HAPI version is: " + ourVersion);
} catch (IOException e) {
LOG.warn("Unable to determine HAPI version information", e);
}
// ignore
}

/**
* @return Returns the current version of HAPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public AcceptApplication() {
* supplies the desired values (this is just here to override inclusion of the
* default error message).
*/
public void fillDetails(Message ack) throws ApplicationException {
public void fillDetails(Message ack) {
//do nothing -- no more information needed
}

Expand Down
14 changes: 5 additions & 9 deletions hapi-base/src/main/java/ca/uhn/hl7v2/app/AcceptorThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ GNU General Public License (the "GPL"), in which case the provisions of the GPL
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
Expand All @@ -56,28 +55,25 @@ class AcceptorThread extends Service {

private static final Logger log = LoggerFactory
.getLogger(AcceptorThread.class);
private int port;
private boolean tls = false;
private final int port;
private final boolean tls;
private ServerSocket ss;
private final BlockingQueue<AcceptedSocket> queue;
private final SocketFactory socketFactory;

public AcceptorThread(ServerSocket serverSocket, int port, ExecutorService service,
BlockingQueue<AcceptedSocket> queue) throws IOException,
SocketException {
BlockingQueue<AcceptedSocket> queue) throws IOException {
this(port, false, service, queue);
this.ss = serverSocket;
}

public AcceptorThread(int port, ExecutorService service,
BlockingQueue<AcceptedSocket> queue) throws IOException,
SocketException {
BlockingQueue<AcceptedSocket> queue) throws IOException {
this(port, false, service, queue);
}

public AcceptorThread(int port, boolean tls, ExecutorService service,
BlockingQueue<AcceptedSocket> queue) throws IOException,
SocketException {
BlockingQueue<AcceptedSocket> queue) {
this(port, tls, service, queue, null);
}

Expand Down
15 changes: 7 additions & 8 deletions hapi-base/src/main/java/ca/uhn/hl7v2/app/ActiveConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public class ActiveConnection implements Connection {

private static final Logger log = LoggerFactory.getLogger(ActiveConnection.class);

private Initiator initiator;
private final Initiator initiator;
private Responder responder;
private List<Socket> sockets;
private HL7Writer ackWriter;
private HL7Writer sendWriter;
private final HL7Writer ackWriter;
private final HL7Writer sendWriter;
private Parser parser;
private BlockingMap<String, String> responses;
private List<Receiver> receivers;
Expand Down Expand Up @@ -132,13 +132,12 @@ public ActiveConnection(Parser parser, LowerLayerProtocol llp, Socket inbound,
}

/** Common initialization tasks */
private void init(Parser parser, ExecutorService executorService, Socket inboundSocket)
throws LLPException {
private void init(Parser parser, ExecutorService executorService, Socket inboundSocket) {
this.parser = parser;
this.executorService = executorService;
sockets = new ArrayList<Socket>();
responses = new BlockingHashMap<String, String>(executorService);
receivers = new ArrayList<Receiver>(2);
sockets = new ArrayList<>();
responses = new BlockingHashMap<>(executorService);
receivers = new ArrayList<>(2);
responder = new Responder(inboundSocket);
}

Expand Down
Loading

0 comments on commit d09c11c

Please sign in to comment.