Use var instead of explicit types

This commit is contained in:
AsamK 2021-02-21 15:01:41 +01:00
parent 03c30519b1
commit de273586b4
77 changed files with 850 additions and 1017 deletions

View file

@ -13,7 +13,7 @@ public class DateUtils {
}
public static String formatTimestamp(long timestamp) {
Date date = new Date(timestamp);
var date = new Date(timestamp);
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); // Quoted "Z" to indicate UTC, no timezone offset
df.setTimeZone(tzUTC);
return timestamp + " (" + df.format(date) + ")";

View file

@ -26,14 +26,14 @@ public class ErrorUtils {
if (timestamp != 0) {
System.out.println(timestamp);
}
List<String> errors = getErrorMessagesFromSendMessageResults(results);
var errors = getErrorMessagesFromSendMessageResults(results);
return handleSendMessageResultErrors(errors);
}
public static List<String> getErrorMessagesFromSendMessageResults(List<SendMessageResult> results) {
List<String> errors = new ArrayList<>();
for (SendMessageResult result : results) {
String error = getErrorMessageFromSendMessageResult(result);
var errors = new ArrayList<String>();
for (var result : results) {
var error = getErrorMessageFromSendMessageResult(result);
if (error != null) {
errors.add(error);
}
@ -58,7 +58,7 @@ public class ErrorUtils {
return 0;
}
System.err.println("Failed to send (some) messages:");
for (String error : errors) {
for (var error : errors) {
System.err.println(error);
}
return 3;

View file

@ -8,8 +8,8 @@ public class Hex {
}
public static String toString(byte[] bytes) {
StringBuffer buf = new StringBuffer();
for (final byte aByte : bytes) {
var buf = new StringBuffer();
for (final var aByte : bytes) {
appendHexChar(buf, aByte);
buf.append(" ");
}
@ -17,8 +17,8 @@ public class Hex {
}
public static String toStringCondensed(byte[] bytes) {
StringBuffer buf = new StringBuffer();
for (final byte aByte : bytes) {
var buf = new StringBuffer();
for (final var aByte : bytes) {
appendHexChar(buf, aByte);
}
return buf.toString();
@ -30,9 +30,9 @@ public class Hex {
}
public static byte[] toByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
var len = s.length();
var data = new byte[len / 2];
for (var i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
}
return data;

View file

@ -12,8 +12,8 @@ public class IOUtils {
}
public static String readAll(InputStream in, Charset charset) throws IOException {
StringWriter output = new StringWriter();
byte[] buffer = new byte[4096];
var output = new StringWriter();
var buffer = new byte[4096];
int n;
while (-1 != (n = in.read(buffer))) {
output.write(new String(buffer, 0, n, charset));
@ -22,7 +22,7 @@ public class IOUtils {
}
public static File getDataHomeDir() {
String dataHome = System.getenv("XDG_DATA_HOME");
var dataHome = System.getenv("XDG_DATA_HOME");
if (dataHome != null) {
return new File(dataHome);
}

View file

@ -6,7 +6,7 @@ import java.security.SecureRandom;
public class RandomUtils {
private static final ThreadLocal<SecureRandom> LOCAL_RANDOM = ThreadLocal.withInitial(() -> {
SecureRandom rand = getSecureRandomUnseeded();
var rand = getSecureRandomUnseeded();
// Let the SecureRandom seed it self initially
rand.nextBoolean();

View file

@ -10,7 +10,7 @@ public class Util {
}
public static String getStringIfNotBlank(Optional<String> value) {
String string = value.orNull();
var string = value.orNull();
if (string == null || string.isBlank()) {
return null;
}
@ -18,10 +18,10 @@ public class Util {
}
public static String formatSafetyNumber(String digits) {
final int partCount = 12;
int partSize = digits.length() / partCount;
StringBuilder f = new StringBuilder(digits.length() + partCount);
for (int i = 0; i < partCount; i++) {
final var partCount = 12;
var partSize = digits.length() / partCount;
var f = new StringBuilder(digits.length() + partCount);
for (var i = 0; i < partCount; i++) {
f.append(digits, i * partSize, (i * partSize) + partSize).append(" ");
}
return f.toString();