More static imports.

This commit is contained in:
akwizgran
2018-12-20 16:51:10 +00:00
parent ad9191b076
commit 8ecec8bcf5
83 changed files with 313 additions and 288 deletions

View File

@@ -9,7 +9,6 @@ import org.briarproject.bramble.api.account.AccountManager;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.util.IoUtils;
import java.io.File;
import java.util.logging.Logger;
@@ -18,6 +17,7 @@ import javax.annotation.Nullable;
import javax.inject.Inject;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.IoUtils.deleteFileOrDir;
class AndroidAccountManager extends AccountManagerImpl
implements AccountManager {
@@ -99,7 +99,7 @@ class AndroidAccountManager extends AccountManagerImpl
for (File child : children) {
String name = child.getName();
if (!name.equals("lib") && !name.equals("shared_prefs")) {
IoUtils.deleteFileOrDir(child);
deleteFileOrDir(child);
}
}
}

View File

@@ -24,7 +24,6 @@ import java.io.IOException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.BlockingQueue;
@@ -48,6 +47,7 @@ import static android.bluetooth.BluetoothAdapter.STATE_OFF;
import static android.bluetooth.BluetoothAdapter.STATE_ON;
import static android.bluetooth.BluetoothDevice.ACTION_FOUND;
import static android.bluetooth.BluetoothDevice.EXTRA_DEVICE;
import static java.util.Collections.shuffle;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
@@ -260,7 +260,7 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
appContext.unregisterReceiver(receiver);
}
// Shuffle the addresses so we don't always try the same one first
Collections.shuffle(addresses);
shuffle(addresses);
return addresses;
}

View File

@@ -1,7 +1,6 @@
package org.briarproject.bramble.plugin.tor;
import android.content.Context;
import android.os.Build;
import org.briarproject.bramble.api.battery.BatteryManager;
import org.briarproject.bramble.api.event.EventBus;
@@ -26,6 +25,7 @@ import java.util.logging.Logger;
import javax.annotation.concurrent.Immutable;
import javax.net.SocketFactory;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.logging.Logger.getLogger;
@Immutable
@@ -104,7 +104,7 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
return null;
}
// Use position-independent executable for SDK >= 16
if (Build.VERSION.SDK_INT >= 16) architecture += "_pie";
if (SDK_INT >= 16) architecture += "_pie";
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
MAX_POLLING_INTERVAL, BACKOFF_BASE);

View File

@@ -8,7 +8,6 @@ import android.content.ContentResolver;
import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Parcel;
import android.os.StrictMode;
import android.provider.Settings;
@@ -23,6 +22,9 @@ import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static android.content.Context.WIFI_SERVICE;
import static android.os.Build.FINGERPRINT;
import static android.os.Build.SERIAL;
import static android.os.Build.VERSION.SDK_INT;
import static android.provider.Settings.Secure.ANDROID_ID;
@Immutable
@@ -45,8 +47,8 @@ class AndroidSecureRandomProvider extends UnixSecureRandomProvider {
out.writeInt(android.os.Process.myPid());
out.writeInt(android.os.Process.myTid());
out.writeInt(android.os.Process.myUid());
if (Build.FINGERPRINT != null) out.writeUTF(Build.FINGERPRINT);
if (Build.SERIAL != null) out.writeUTF(Build.SERIAL);
if (FINGERPRINT != null) out.writeUTF(FINGERPRINT);
if (SERIAL != null) out.writeUTF(SERIAL);
ContentResolver contentResolver = appContext.getContentResolver();
String id = Settings.Secure.getString(contentResolver, ANDROID_ID);
if (id != null) out.writeUTF(id);
@@ -74,15 +76,13 @@ class AndroidSecureRandomProvider extends UnixSecureRandomProvider {
// Silence strict mode
StrictMode.ThreadPolicy tp = StrictMode.allowThreadDiskWrites();
super.writeSeed();
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT <= 18)
applyOpenSslFix();
if (SDK_INT >= 16 && SDK_INT <= 18) applyOpenSslFix();
StrictMode.setThreadPolicy(tp);
}
// Based on https://android-developers.googleblog.com/2013/08/some-securerandom-thoughts.html
private void applyOpenSslFix() {
byte[] seed = new UnixSecureRandomSpi().engineGenerateSeed(
SEED_LENGTH);
byte[] seed = new UnixSecureRandomSpi().engineGenerateSeed(SEED_LENGTH);
try {
// Seed the OpenSSL PRNG
Class.forName("org.apache.harmony.xnet.provider.jsse.NativeCrypto")

View File

@@ -3,17 +3,19 @@ package org.briarproject.bramble.util;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static android.content.Context.MODE_PRIVATE;
import static android.os.Build.CPU_ABI;
import static android.os.Build.CPU_ABI2;
import static android.os.Build.SUPPORTED_ABIS;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.Arrays.asList;
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
public class AndroidUtils {
@@ -27,10 +29,10 @@ public class AndroidUtils {
public static Collection<String> getSupportedArchitectures() {
List<String> abis = new ArrayList<>();
if (SDK_INT >= 21) {
abis.addAll(Arrays.asList(Build.SUPPORTED_ABIS));
abis.addAll(asList(SUPPORTED_ABIS));
} else {
abis.add(Build.CPU_ABI);
if (Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
abis.add(CPU_ABI);
if (CPU_ABI2 != null) abis.add(CPU_ABI2);
}
return abis;
}

View File

@@ -2,7 +2,6 @@ package org.briarproject.bramble.api;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -10,6 +9,8 @@ import java.util.Set;
import javax.annotation.concurrent.NotThreadSafe;
import static java.util.Collections.unmodifiableSet;
@NotThreadSafe
@NotNullByDefault
public class Multiset<T> {
@@ -96,6 +97,6 @@ public class Multiset<T> {
* is unmodifiable.
*/
public Set<T> keySet() {
return Collections.unmodifiableSet(map.keySet());
return unmodifiableSet(map.keySet());
}
}

View File

@@ -5,10 +5,11 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.MessageId;
import java.util.Collection;
import java.util.Collections;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.emptyList;
@Immutable
@NotNullByDefault
public class BdfMessageContext {
@@ -23,7 +24,7 @@ public class BdfMessageContext {
}
public BdfMessageContext(BdfDictionary dictionary) {
this(dictionary, Collections.emptyList());
this(dictionary, emptyList());
}
public BdfDictionary getDictionary() {

View File

@@ -4,12 +4,12 @@ import org.briarproject.bramble.api.Bytes;
import org.briarproject.bramble.api.FormatException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import static java.util.Arrays.asList;
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
@NotThreadSafe
@@ -22,7 +22,7 @@ public class BdfList extends ArrayList<Object> {
* </pre>
*/
public static BdfList of(Object... items) {
return new BdfList(Arrays.asList(items));
return new BdfList(asList(items));
}
public BdfList() {

View File

@@ -3,11 +3,12 @@ package org.briarproject.bramble.api.db;
import org.briarproject.bramble.api.event.Event;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.concurrent.NotThreadSafe;
import static java.util.Collections.emptyList;
/**
* A wrapper around a database transaction. Transactions are not thread-safe.
*/
@@ -53,7 +54,7 @@ public class Transaction {
* Returns any events attached to the transaction.
*/
public List<Event> getEvents() {
if (events == null) return Collections.emptyList();
if (events == null) return emptyList();
return events;
}

View File

@@ -4,10 +4,11 @@ import org.briarproject.bramble.api.db.Metadata;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.Collection;
import java.util.Collections;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.emptyList;
@Immutable
@NotNullByDefault
public class MessageContext {
@@ -22,7 +23,7 @@ public class MessageContext {
}
public MessageContext(Metadata metadata) {
this(metadata, Collections.emptyList());
this(metadata, emptyList());
}
public Metadata getMetadata() {

View File

@@ -8,6 +8,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.Map.Entry;
import static java.util.Collections.singletonMap;
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -19,15 +20,15 @@ public class BdfDictionaryTest extends BrambleTestCase {
public void testConstructors() {
assertEquals(Collections.<String, Object>emptyMap(),
new BdfDictionary());
assertEquals(Collections.singletonMap("foo", NULL_VALUE),
new BdfDictionary(Collections.singletonMap("foo", NULL_VALUE)));
assertEquals(singletonMap("foo", NULL_VALUE),
new BdfDictionary(singletonMap("foo", NULL_VALUE)));
}
@Test
public void testFactoryMethod() {
assertEquals(Collections.<String, Object>emptyMap(),
BdfDictionary.of());
assertEquals(Collections.singletonMap("foo", NULL_VALUE),
assertEquals(singletonMap("foo", NULL_VALUE),
BdfDictionary.of(new BdfEntry("foo", NULL_VALUE)));
}

View File

@@ -5,9 +5,8 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.test.BrambleTestCase;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -16,15 +15,15 @@ public class BdfListTest extends BrambleTestCase {
@Test
public void testConstructors() {
assertEquals(Collections.emptyList(), new BdfList());
assertEquals(Arrays.asList(1, 2, NULL_VALUE),
new BdfList(Arrays.asList(1, 2, NULL_VALUE)));
assertEquals(emptyList(), new BdfList());
assertEquals(asList(1, 2, NULL_VALUE),
new BdfList(asList(1, 2, NULL_VALUE)));
}
@Test
public void testFactoryMethod() {
assertEquals(Collections.emptyList(), BdfList.of());
assertEquals(Arrays.asList(1, 2, NULL_VALUE),
assertEquals(emptyList(), BdfList.of());
assertEquals(asList(1, 2, NULL_VALUE),
BdfList.of(1, 2, NULL_VALUE));
}

View File

@@ -12,12 +12,10 @@ import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.util.IoUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -25,6 +23,7 @@ import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import static java.util.Arrays.asList;
import static java.util.Collections.sort;
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
@@ -33,6 +32,7 @@ import static org.briarproject.bramble.api.properties.TransportPropertyConstants
import static org.briarproject.bramble.api.sync.ClientId.MAX_CLIENT_ID_LENGTH;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
import static org.briarproject.bramble.util.IoUtils.deleteFileOrDir;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
public class TestUtils {
@@ -48,7 +48,7 @@ public class TestUtils {
}
public static void deleteTestDirectory(File testDir) {
IoUtils.deleteFileOrDir(testDir);
deleteFileOrDir(testDir);
testDir.getParentFile().delete(); // Delete if empty
}
@@ -145,7 +145,7 @@ public class TestUtils {
if (size == 0) throw new IllegalArgumentException();
List<Double> sorted = new ArrayList<>(size);
for (Number n : samples) sorted.add(n.doubleValue());
Collections.sort(sorted);
sort(sorted);
if (size % 2 == 1) return sorted.get(size / 2);
double low = sorted.get(size / 2 - 1), high = sorted.get(size / 2);
return (low + high) / 2;

View File

@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.util.IoUtils;
import java.io.BufferedReader;
import java.io.File;
@@ -23,6 +22,7 @@ import javax.inject.Inject;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.IoUtils.deleteFileOrDir;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.StringUtils.fromHexString;
import static org.briarproject.bramble.util.StringUtils.toHexString;
@@ -182,8 +182,8 @@ class AccountManagerImpl implements AccountManager {
public void deleteAccount() {
synchronized (stateChangeLock) {
LOG.info("Deleting account");
IoUtils.deleteFileOrDir(databaseConfig.getDatabaseKeyDirectory());
IoUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory());
deleteFileOrDir(databaseConfig.getDatabaseKeyDirectory());
deleteFileOrDir(databaseConfig.getDatabaseDirectory());
databaseKey = null;
}
}

View File

@@ -28,6 +28,7 @@ import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.inject.Inject;
import static java.lang.System.arraycopy;
import static java.util.logging.Level.INFO;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.ByteUtils.INT_32_BYTES;
@@ -190,7 +191,7 @@ class CryptoComponentImpl implements CryptoComponent {
PrivateKey ourPriv = ourKeyPair.getPrivate();
byte[][] hashInputs = new byte[inputs.length + 1][];
hashInputs[0] = performRawKeyAgreement(ourPriv, theirPublicKey);
System.arraycopy(inputs, 0, hashInputs, 1, inputs.length);
arraycopy(inputs, 0, hashInputs, 1, inputs.length);
byte[] hash = hash(label, hashInputs);
if (hash.length != SecretKey.LENGTH) throw new IllegalStateException();
return new SecretKey(hash);
@@ -299,13 +300,13 @@ class CryptoComponentImpl implements CryptoComponent {
output[outputOff] = PBKDF_FORMAT_SCRYPT;
outputOff++;
// Salt
System.arraycopy(salt, 0, output, outputOff, salt.length);
arraycopy(salt, 0, output, outputOff, salt.length);
outputOff += salt.length;
// Cost parameter
writeUint32(cost, output, outputOff);
outputOff += INT_32_BYTES;
// IV
System.arraycopy(iv, 0, output, outputOff, iv.length);
arraycopy(iv, 0, output, outputOff, iv.length);
outputOff += iv.length;
// Initialise the cipher and encrypt the plaintext
try {
@@ -335,7 +336,7 @@ class CryptoComponentImpl implements CryptoComponent {
return null; // Unknown format
// Salt
byte[] salt = new byte[PBKDF_SALT_BYTES];
System.arraycopy(input, inputOff, salt, 0, salt.length);
arraycopy(input, inputOff, salt, 0, salt.length);
inputOff += salt.length;
// Cost parameter
long cost = readUint32(input, inputOff);
@@ -344,7 +345,7 @@ class CryptoComponentImpl implements CryptoComponent {
return null; // Invalid cost parameter
// IV
byte[] iv = new byte[STORAGE_IV_BYTES];
System.arraycopy(input, inputOff, iv, 0, iv.length);
arraycopy(input, inputOff, iv, 0, iv.length);
inputOff += iv.length;
// Derive the key from the password
SecretKey key = passwordBasedKdf.deriveKey(password, salt, (int) cost);

View File

@@ -7,6 +7,8 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.security.GeneralSecurityException;
import static java.lang.System.arraycopy;
@NotNullByDefault
class Curve25519KeyParser implements KeyParser {
@@ -26,7 +28,7 @@ class Curve25519KeyParser implements KeyParser {
static byte[] clamp(byte[] b) {
byte[] clamped = new byte[32];
System.arraycopy(b, 0, clamped, 0, 32);
arraycopy(b, 0, clamped, 0, 32);
clamped[0] &= 248;
clamped[31] &= 127;
clamped[31] |= 64;

View File

@@ -8,6 +8,7 @@ import org.briarproject.bramble.api.crypto.SecretKey;
import javax.inject.Inject;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.COMMIT_LENGTH;
class KeyAgreementCryptoImpl implements KeyAgreementCrypto {
@@ -24,7 +25,7 @@ class KeyAgreementCryptoImpl implements KeyAgreementCrypto {
byte[] hash = crypto.hash(COMMIT_LABEL, publicKey.getEncoded());
// The output is the first COMMIT_LENGTH bytes of the hash
byte[] commitment = new byte[COMMIT_LENGTH];
System.arraycopy(hash, 0, commitment, 0, COMMIT_LENGTH);
arraycopy(hash, 0, commitment, 0, COMMIT_LENGTH);
return commitment;
}

View File

@@ -16,6 +16,7 @@ import java.util.logging.Logger;
import javax.annotation.concurrent.Immutable;
import static java.lang.System.arraycopy;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.now;
@@ -56,12 +57,12 @@ class Sec1KeyParser implements KeyParser {
if (encodedKey[0] != 4) throw new GeneralSecurityException();
// The x co-ordinate must be >= 0 and < p
byte[] xBytes = new byte[bytesPerInt];
System.arraycopy(encodedKey, 1, xBytes, 0, bytesPerInt);
arraycopy(encodedKey, 1, xBytes, 0, bytesPerInt);
BigInteger x = new BigInteger(1, xBytes); // Positive signum
if (x.compareTo(modulus) >= 0) throw new GeneralSecurityException();
// The y co-ordinate must be >= 0 and < p
byte[] yBytes = new byte[bytesPerInt];
System.arraycopy(encodedKey, 1 + bytesPerInt, yBytes, 0, bytesPerInt);
arraycopy(encodedKey, 1 + bytesPerInt, yBytes, 0, bytesPerInt);
BigInteger y = new BigInteger(1, yBytes); // Positive signum
if (y.compareTo(modulus) >= 0) throw new GeneralSecurityException();
// Verify that y^2 == x^3 + ax + b (mod p)

View File

@@ -2,6 +2,8 @@ package org.briarproject.bramble.crypto;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import static java.lang.System.arraycopy;
@NotNullByDefault
class Sec1Utils {
@@ -10,10 +12,10 @@ class Sec1Utils {
if (src.length < destLen) {
int padding = destLen - src.length;
for (int i = destOff; i < destOff + padding; i++) dest[i] = 0;
System.arraycopy(src, 0, dest, destOff + padding, src.length);
arraycopy(src, 0, dest, destOff + padding, src.length);
} else {
int srcOff = src.length - destLen;
System.arraycopy(src, srcOff, dest, destOff, destLen);
arraycopy(src, srcOff, dest, destOff, destLen);
}
}
}

View File

@@ -13,6 +13,7 @@ import java.security.GeneralSecurityException;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_PLAINTEXT_LENGTH;
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_NONCE_LENGTH;
@@ -131,7 +132,7 @@ class StreamDecrypterImpl implements StreamDecrypter {
}
// Extract the nonce
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
System.arraycopy(streamHeaderCiphertext, 0, streamHeaderNonce, 0,
arraycopy(streamHeaderCiphertext, 0, streamHeaderNonce, 0,
STREAM_HEADER_NONCE_LENGTH);
// Decrypt and authenticate the stream header
try {
@@ -155,7 +156,7 @@ class StreamDecrypterImpl implements StreamDecrypter {
if (receivedStreamNumber != streamNumber) throw new FormatException();
// Extract the frame key
byte[] frameKeyBytes = new byte[SecretKey.LENGTH];
System.arraycopy(streamHeaderPlaintext, INT_16_BYTES + INT_64_BYTES,
arraycopy(streamHeaderPlaintext, INT_16_BYTES + INT_64_BYTES,
frameKeyBytes, 0, SecretKey.LENGTH);
frameKey = new SecretKey(frameKeyBytes);
}

View File

@@ -11,6 +11,7 @@ import java.security.GeneralSecurityException;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_PLAINTEXT_LENGTH;
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_NONCE_LENGTH;
@@ -89,7 +90,7 @@ class StreamEncrypterImpl implements StreamEncrypter {
throw new RuntimeException(badCipher);
}
// Combine the payload and padding
System.arraycopy(payload, 0, framePlaintext, 0, payloadLength);
arraycopy(payload, 0, framePlaintext, 0, payloadLength);
for (int i = 0; i < paddingLength; i++)
framePlaintext[payloadLength + i] = 0;
// Encrypt and authenticate the payload and padding
@@ -121,10 +122,10 @@ class StreamEncrypterImpl implements StreamEncrypter {
byte[] streamHeaderPlaintext = new byte[STREAM_HEADER_PLAINTEXT_LENGTH];
writeUint16(PROTOCOL_VERSION, streamHeaderPlaintext, 0);
writeUint64(streamNumber, streamHeaderPlaintext, INT_16_BYTES);
System.arraycopy(frameKey.getBytes(), 0, streamHeaderPlaintext,
arraycopy(frameKey.getBytes(), 0, streamHeaderPlaintext,
INT_16_BYTES + INT_64_BYTES, SecretKey.LENGTH);
byte[] streamHeaderCiphertext = new byte[STREAM_HEADER_LENGTH];
System.arraycopy(streamHeaderNonce, 0, streamHeaderCiphertext, 0,
arraycopy(streamHeaderNonce, 0, streamHeaderCiphertext, 0,
STREAM_HEADER_NONCE_LENGTH);
// Encrypt and authenticate the stream header key
try {

View File

@@ -12,6 +12,7 @@ import org.spongycastle.crypto.digests.Blake2bDigest;
import javax.inject.Inject;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.transport.TransportConstants.ALICE_HEADER_LABEL;
import static org.briarproject.bramble.api.transport.TransportConstants.ALICE_TAG_LABEL;
import static org.briarproject.bramble.api.transport.TransportConstants.BOB_HEADER_LABEL;
@@ -134,6 +135,6 @@ class TransportCryptoImpl implements TransportCrypto {
byte[] mac = new byte[macLength];
prf.doFinal(mac, 0);
// The output is the first TAG_LENGTH bytes of the MAC
System.arraycopy(mac, 0, tag, 0, TAG_LENGTH);
arraycopy(mac, 0, tag, 0, TAG_LENGTH);
}
}

View File

@@ -61,7 +61,6 @@ import org.briarproject.bramble.api.transport.TransportKeys;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -72,6 +71,7 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static java.util.Collections.singletonList;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
@@ -899,7 +899,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
if (old == INVISIBLE) db.addGroupVisibility(txn, c, g, v == SHARED);
else if (v == INVISIBLE) db.removeGroupVisibility(txn, c, g);
else db.setGroupVisibility(txn, c, g, v == SHARED);
List<ContactId> affected = Collections.singletonList(c);
List<ContactId> affected = singletonList(c);
transaction.attach(new GroupVisibilityUpdatedEvent(affected));
}

View File

@@ -38,9 +38,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@@ -55,8 +53,12 @@ import java.util.logging.Logger;
import javax.annotation.Nullable;
import static java.lang.System.arraycopy;
import static java.sql.Types.INTEGER;
import static java.sql.Types.VARCHAR;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
@@ -424,7 +426,7 @@ abstract class JdbcDatabase implements Database<Connection> {
// Package access for testing
List<Migration<Connection>> getMigrations() {
return Arrays.asList(
return asList(
new Migration38_39(),
new Migration39_40(),
new Migration40_41(dbTypes)
@@ -1536,7 +1538,7 @@ abstract class JdbcDatabase implements Database<Connection> {
if (raw == null) throw new MessageDeletedException();
if (raw.length <= MESSAGE_HEADER_LENGTH) throw new AssertionError();
byte[] body = new byte[raw.length - MESSAGE_HEADER_LENGTH];
System.arraycopy(raw, MESSAGE_HEADER_LENGTH, body, 0, body.length);
arraycopy(raw, MESSAGE_HEADER_LENGTH, body, 0, body.length);
return new Message(m, g, timestamp, body);
} catch (SQLException e) {
tryToClose(rs, LOG, WARNING);
@@ -1596,7 +1598,7 @@ abstract class JdbcDatabase implements Database<Connection> {
if (intersection == null) intersection = ids;
else intersection.retainAll(ids);
// Return early if there are no matches
if (intersection.isEmpty()) return Collections.emptySet();
if (intersection.isEmpty()) return emptySet();
}
if (intersection == null) throw new AssertionError();
return intersection;
@@ -1645,7 +1647,7 @@ abstract class JdbcDatabase implements Database<Connection> {
GroupId g, Metadata query) throws DbException {
// Retrieve the matching message IDs
Collection<MessageId> matches = getMessageIds(txn, g, query);
if (matches.isEmpty()) return Collections.emptyMap();
if (matches.isEmpty()) return emptyMap();
// Retrieve the metadata for each match
Map<MessageId, Metadata> all = new HashMap<>(matches.size());
for (MessageId m : matches) all.put(m, getMessageMetadata(txn, m));
@@ -2395,7 +2397,7 @@ abstract class JdbcDatabase implements Database<Connection> {
}
ps.close();
}
if (notRemoved.isEmpty()) return Collections.emptyMap();
if (notRemoved.isEmpty()) return emptyMap();
// Update any keys that already exist
String sql = "UPDATE " + tableName + " SET value = ?"
+ " WHERE " + columnName + " = ? AND metaKey = ?";

View File

@@ -13,7 +13,6 @@ import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -24,6 +23,7 @@ import java.util.logging.Logger;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static java.util.Collections.emptyList;
import static java.util.logging.Level.INFO;
import static java.util.logging.Logger.getLogger;
@@ -104,7 +104,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
lock.lock();
try {
Multiset<ContactId> m = connections.get(t);
if (m == null) return Collections.emptyList();
if (m == null) return emptyList();
List<ContactId> ids = new ArrayList<>(m.keySet());
if (LOG.isLoggable(INFO))
LOG.info(ids.size() + " contacts connected: " + t);

View File

@@ -10,11 +10,12 @@ import org.briarproject.bramble.api.properties.TransportProperties;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executor;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.plugin.WanTcpConstants.ID;
@MethodsNotNullByDefault
@@ -80,8 +81,7 @@ class WanTcpPlugin extends TcpPlugin {
protected List<InetSocketAddress> getRemoteSocketAddresses(
TransportProperties p) {
InetSocketAddress parsed = parseSocketAddress(p.get(PROP_IP_PORT));
if (parsed == null) return Collections.emptyList();
return Collections.singletonList(parsed);
return parsed == null ? emptyList() : singletonList(parsed);
}
@Override

View File

@@ -42,9 +42,7 @@ import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -58,6 +56,9 @@ import java.util.zip.ZipInputStream;
import javax.annotation.Nullable;
import javax.net.SocketFactory;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
@@ -252,11 +253,11 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
controlConnection.authenticate(read(cookieFile));
// Tell Tor to exit when the control connection is closed
controlConnection.takeOwnership();
controlConnection.resetConf(Collections.singletonList(OWNER));
controlConnection.resetConf(singletonList(OWNER));
running = true;
// Register to receive events from the Tor process
controlConnection.setEventHandler(this);
controlConnection.setEvents(Arrays.asList(EVENTS));
controlConnection.setEvents(asList(EVENTS));
// Check whether Tor has already bootstrapped
String phase = controlConnection.getInfo("status/bootstrap-phase");
if (phase != null && phase.contains("PROGRESS=100")) {
@@ -411,8 +412,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
if (!running) return;
LOG.info("Creating hidden service");
String privKey = settings.get(HS_PRIVKEY);
Map<Integer, String> portLines =
Collections.singletonMap(80, "127.0.0.1:" + port);
Map<Integer, String> portLines = singletonMap(80, "127.0.0.1:" + port);
Map<String, String> response;
try {
// Use the control connection to set up the hidden service

View File

@@ -8,6 +8,8 @@ import java.io.InputStream;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import static java.lang.System.arraycopy;
@NotThreadSafe
@NotNullByDefault
class ReceiverInputStream extends InputStream {
@@ -44,7 +46,7 @@ class ReceiverInputStream extends InputStream {
while (length == 0) if (!receive()) return -1;
if (data == null) throw new AssertionError();
len = Math.min(len, length);
System.arraycopy(data.getBuffer(), offset, b, off, len);
arraycopy(data.getBuffer(), offset, b, off, len);
offset += len;
length -= len;
return len;

View File

@@ -7,6 +7,8 @@ import java.io.OutputStream;
import javax.annotation.concurrent.NotThreadSafe;
import static java.lang.System.arraycopy;
@NotThreadSafe
@NotNullByDefault
class SenderOutputStream extends OutputStream {
@@ -59,20 +61,20 @@ class SenderOutputStream extends OutputStream {
public void write(byte[] b, int off, int len) throws IOException {
int available = Data.MAX_LENGTH - offset - Data.FOOTER_LENGTH;
while (available <= len) {
System.arraycopy(b, off, buf, offset, available);
arraycopy(b, off, buf, offset, available);
offset += available;
send(false);
off += available;
len -= available;
available = Data.MAX_LENGTH - offset - Data.FOOTER_LENGTH;
}
System.arraycopy(b, off, buf, offset, len);
arraycopy(b, off, buf, offset, len);
offset += len;
}
private void send(boolean lastFrame) throws IOException {
byte[] frame = new byte[offset + Data.FOOTER_LENGTH];
System.arraycopy(buf, 0, frame, 0, frame.length);
arraycopy(buf, 0, frame, 0, frame.length);
Data d = new Data(frame);
d.setLastFrame(lastFrame);
d.setSequenceNumber(sequenceNumber++);

View File

@@ -7,6 +7,8 @@ import java.io.IOException;
import javax.annotation.concurrent.Immutable;
import static java.lang.System.arraycopy;
@Immutable
@NotNullByDefault
class SlipDecoder implements ReadHandler {
@@ -36,7 +38,7 @@ class SlipDecoder implements ReadHandler {
} else {
if (decodedLength > 0) {
byte[] decoded = new byte[decodedLength];
System.arraycopy(buf, 0, decoded, 0, decodedLength);
arraycopy(buf, 0, decoded, 0, decodedLength);
readHandler.handleRead(decoded);
}
reset(false);

View File

@@ -1,7 +1,6 @@
package org.briarproject.bramble.reporting;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.util.IoUtils;
import java.io.Closeable;
import java.io.File;
@@ -17,6 +16,9 @@ import java.util.concurrent.Semaphore;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import static java.io.File.createTempFile;
import static org.briarproject.bramble.util.IoUtils.getInputStream;
@Immutable
@NotNullByDefault
public class DevReportServer {
@@ -131,9 +133,9 @@ public class DevReportServer {
OutputStream out = null;
try {
socket.setSoTimeout(SOCKET_TIMEOUT_MS);
in = IoUtils.getInputStream(socket);
in = getInputStream(socket);
reportDir.mkdirs();
reportFile = File.createTempFile(FILE_PREFIX, FILE_SUFFIX,
reportFile = createTempFile(FILE_PREFIX, FILE_SUFFIX,
reportDir);
out = new FileOutputStream(reportFile);
System.out.println("Saving report to " + reportFile);

View File

@@ -12,6 +12,7 @@ import java.net.SocketAddress;
import java.util.Arrays;
import static org.briarproject.bramble.util.ByteUtils.writeUint16;
import static org.briarproject.bramble.util.IoUtils.read;
class SocksSocket extends Socket {
@@ -89,7 +90,7 @@ class SocksSocket extends Socket {
private void receiveMethodResponse(InputStream in) throws IOException {
byte[] methodResponse = new byte[2];
IoUtils.read(in, methodResponse);
read(in, methodResponse);
byte version = methodResponse[0];
byte method = methodResponse[1];
if (version != 5)
@@ -116,7 +117,7 @@ class SocksSocket extends Socket {
private void receiveConnectResponse(InputStream in) throws IOException {
byte[] connectResponse = new byte[4];
IoUtils.read(in, connectResponse);
read(in, connectResponse);
int version = connectResponse[0] & 0xFF;
int reply = connectResponse[1] & 0xFF;
int addressType = connectResponse[3] & 0xFF;
@@ -127,9 +128,9 @@ class SocksSocket extends Socket {
throw new IOException("Connection failed: " + ERRORS[reply]);
else throw new IOException("Connection failed: " + reply);
}
if (addressType == 1) IoUtils.read(in, new byte[4]); // IPv4
else if (addressType == 4) IoUtils.read(in, new byte[16]); // IPv6
if (addressType == 1) read(in, new byte[4]); // IPv4
else if (addressType == 4) read(in, new byte[16]); // IPv6
else throw new IOException("Unsupported address type: " + addressType);
IoUtils.read(in, new byte[2]); // Port number
read(in, new byte[2]); // Port number
}
}

View File

@@ -11,6 +11,7 @@ import org.briarproject.bramble.api.sync.MessageId;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.sync.Message.FORMAT_VERSION;
import static org.briarproject.bramble.api.sync.MessageId.BLOCK_LABEL;
import static org.briarproject.bramble.api.sync.MessageId.ID_LABEL;
@@ -61,11 +62,11 @@ class MessageFactoryImpl implements MessageFactory {
if (raw.length > MAX_MESSAGE_LENGTH)
throw new IllegalArgumentException();
byte[] groupId = new byte[UniqueId.LENGTH];
System.arraycopy(raw, 0, groupId, 0, UniqueId.LENGTH);
arraycopy(raw, 0, groupId, 0, UniqueId.LENGTH);
GroupId g = new GroupId(groupId);
long timestamp = readUint64(raw, UniqueId.LENGTH);
byte[] body = new byte[raw.length - MESSAGE_HEADER_LENGTH];
System.arraycopy(raw, MESSAGE_HEADER_LENGTH, body, 0, body.length);
arraycopy(raw, MESSAGE_HEADER_LENGTH, body, 0, body.length);
MessageId id = getMessageId(g, timestamp, body);
return new Message(id, g, timestamp, body);
}
@@ -74,9 +75,9 @@ class MessageFactoryImpl implements MessageFactory {
public byte[] getRawMessage(Message m) {
byte[] body = m.getBody();
byte[] raw = new byte[MESSAGE_HEADER_LENGTH + body.length];
System.arraycopy(m.getGroupId().getBytes(), 0, raw, 0, UniqueId.LENGTH);
arraycopy(m.getGroupId().getBytes(), 0, raw, 0, UniqueId.LENGTH);
writeUint64(m.getTimestamp(), raw, UniqueId.LENGTH);
System.arraycopy(body, 0, raw, MESSAGE_HEADER_LENGTH, body.length);
arraycopy(body, 0, raw, MESSAGE_HEADER_LENGTH, body.length);
return raw;
}
}

View File

@@ -21,6 +21,7 @@ import java.util.List;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.sync.RecordTypes.ACK;
import static org.briarproject.bramble.api.sync.RecordTypes.MESSAGE;
import static org.briarproject.bramble.api.sync.RecordTypes.OFFER;
@@ -107,7 +108,7 @@ class SyncRecordReaderImpl implements SyncRecordReader {
List<MessageId> ids = new ArrayList<>(payload.length / UniqueId.LENGTH);
for (int off = 0; off < payload.length; off += UniqueId.LENGTH) {
byte[] id = new byte[UniqueId.LENGTH];
System.arraycopy(payload, off, id, 0, UniqueId.LENGTH);
arraycopy(payload, off, id, 0, UniqueId.LENGTH);
ids.add(new MessageId(id));
}
nextRecord = null;

View File

@@ -3,11 +3,12 @@ package org.briarproject.bramble.transport;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.concurrent.NotThreadSafe;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.util.ByteUtils.MAX_32_BIT_UNSIGNED;
@NotThreadSafe
@@ -64,8 +65,8 @@ class ReorderingWindow {
while (seen[slide]) slide++;
// If the window doesn't need to slide, return
if (slide == 0) {
List<Long> added = Collections.emptyList();
List<Long> removed = Collections.singletonList(index);
List<Long> added = emptyList();
List<Long> removed = singletonList(index);
return new Change(added, removed);
}
// Record the elements that will be added and removed

View File

@@ -8,6 +8,7 @@ import java.io.InputStream;
import javax.annotation.concurrent.NotThreadSafe;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
/**
@@ -51,7 +52,7 @@ class StreamReaderImpl extends InputStream {
readFrame();
}
len = Math.min(len, length);
System.arraycopy(payload, offset, b, off, len);
arraycopy(payload, offset, b, off, len);
offset += len;
length -= len;
return len;

View File

@@ -9,6 +9,7 @@ import java.io.OutputStream;
import javax.annotation.concurrent.NotThreadSafe;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
/**
@@ -70,14 +71,14 @@ class StreamWriterImpl extends OutputStream implements StreamWriter {
public void write(byte[] b, int off, int len) throws IOException {
int available = payload.length - length;
while (available <= len) {
System.arraycopy(b, off, payload, length, available);
arraycopy(b, off, payload, length, available);
length += available;
writeFrame(false);
off += available;
len -= available;
available = payload.length - length;
}
System.arraycopy(b, off, payload, length, len);
arraycopy(b, off, payload, length, len);
length += len;
}

View File

@@ -30,7 +30,6 @@ import org.briarproject.bramble.api.versioning.ClientVersioningManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -45,6 +44,7 @@ import javax.annotation.Nullable;
import javax.inject.Inject;
import static java.util.Collections.emptyList;
import static java.util.Collections.sort;
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
@@ -134,7 +134,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
@Override
public void startService() throws ServiceException {
List<ClientVersion> versions = new ArrayList<>(clients);
Collections.sort(versions);
sort(versions);
try {
db.transaction(false, txn -> {
if (updateClientVersions(txn, versions)) {
@@ -167,7 +167,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
}
// Create and store the first local update
List<ClientVersion> versions = new ArrayList<>(clients);
Collections.sort(versions);
sort(versions);
storeFirstUpdate(txn, g.getId(), versions);
}

View File

@@ -3,13 +3,13 @@ package org.briarproject.bramble;
import org.briarproject.bramble.test.BrambleTestCase;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -119,12 +119,12 @@ public class PoliteExecutorTest extends BrambleTestCase {
private List<Integer> ascendingOrder() {
Integer[] array = new Integer[TASKS];
for (int i = 0; i < TASKS; i++) array[i] = i;
return Arrays.asList(array);
return asList(array);
}
private List<Integer> descendingOrder() {
Integer[] array = new Integer[TASKS];
for (int i = 0; i < TASKS; i++) array[i] = TASKS - 1 - i;
return Arrays.asList(array);
return asList(array);
}
}

View File

@@ -30,11 +30,11 @@ import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static java.util.Collections.singletonMap;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
@@ -166,7 +166,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
context.checking(new DbExpectations() {{
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
oneOf(db).getMessageMetadata(txn, groupId);
will(returnValue(Collections.singletonMap(messageId, metadata)));
will(returnValue(singletonMap(messageId, metadata)));
oneOf(metadataParser).parse(metadata);
will(returnValue(dictionary));
}});
@@ -190,7 +190,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
oneOf(metadataEncoder).encode(query);
will(returnValue(queryMetadata));
oneOf(db).getMessageMetadata(txn, groupId, queryMetadata);
will(returnValue(Collections.singletonMap(messageId, metadata)));
will(returnValue(singletonMap(messageId, metadata)));
oneOf(metadataParser).parse(metadata);
will(returnValue(dictionary));
}});

View File

@@ -22,7 +22,6 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Random;
import static java.util.Collections.emptyList;
@@ -98,7 +97,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test
public void testGetContactByAuthor() throws Exception {
Transaction txn = new Transaction(null, true);
Collection<Contact> contacts = Collections.singleton(contact);
Collection<Contact> contacts = singletonList(contact);
context.checking(new DbExpectations() {{
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
oneOf(db).getContactsByAuthorId(txn, remote.getId());
@@ -123,7 +122,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test(expected = NoSuchContactException.class)
public void testGetContactByUnknownLocalAuthor() throws Exception {
Transaction txn = new Transaction(null, true);
Collection<Contact> contacts = Collections.singleton(contact);
Collection<Contact> contacts = singletonList(contact);
context.checking(new DbExpectations() {{
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
oneOf(db).getContactsByAuthorId(txn, remote.getId());
@@ -135,7 +134,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test
public void testGetActiveContacts() throws Exception {
Collection<Contact> activeContacts = Collections.singletonList(contact);
Collection<Contact> activeContacts = singletonList(contact);
Collection<Contact> contacts = new ArrayList<>(activeContacts);
contacts.add(new Contact(new ContactId(3), remote, local, alias, true,
false));

View File

@@ -33,10 +33,10 @@ import java.security.Provider;
import java.security.SecureRandom;
import java.security.Signature;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static java.util.Arrays.asList;
import static java.util.Collections.sort;
import static net.i2p.crypto.eddsa.EdDSAEngine.SIGNATURE_ALGORITHM;
// Not a JUnit test
@@ -45,9 +45,9 @@ public class EllipticCurvePerformanceTest {
private static final SecureRandom random = new SecureRandom();
private static final int SAMPLES = 50;
private static final int BYTES_TO_SIGN = 1024;
private static final List<String> SEC_NAMES = Arrays.asList(
private static final List<String> SEC_NAMES = asList(
"secp256k1", "secp256r1", "secp384r1", "secp521r1");
private static final List<String> BRAINPOOL_NAMES = Arrays.asList(
private static final List<String> BRAINPOOL_NAMES = asList(
"brainpoolp256r1", "brainpoolp384r1", "brainpoolp512r1");
private static final Provider ED_PROVIDER = new EdDSASecurityProvider();
@@ -184,7 +184,7 @@ public class EllipticCurvePerformanceTest {
private static long median(List<Long> list) {
int size = list.size();
if (size == 0) throw new IllegalArgumentException();
Collections.sort(list);
sort(list);
if (size % 2 == 1) return list.get(size / 2);
return list.get(size / 2 - 1) + list.get(size / 2) / 2;
}

View File

@@ -4,6 +4,8 @@ import java.security.Provider;
import java.security.SecureRandom;
import java.security.SecureRandomSpi;
import static java.lang.System.arraycopy;
class PseudoSecureRandom extends SecureRandom {
private static final Provider PROVIDER = new PseudoSecureRandomProvider();
@@ -28,7 +30,7 @@ class PseudoSecureRandom extends SecureRandom {
@Override
protected void engineNextBytes(byte[] b) {
byte[] random = pseudoRandom.nextBytes(b.length);
System.arraycopy(random, 0, b, 0, b.length);
arraycopy(random, 0, b, 0, b.length);
}
@Override

View File

@@ -8,6 +8,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import static java.lang.System.arraycopy;
import static junit.framework.Assert.assertEquals;
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
import static org.briarproject.bramble.api.transport.TransportConstants.MAC_LENGTH;
@@ -287,7 +288,7 @@ public class StreamDecrypterImplTest extends BrambleTestCase {
private static void assertArrayStartsWith(byte[] expected, byte[] actual,
int len) {
byte[] prefix = new byte[len];
System.arraycopy(actual, 0, prefix, 0, len);
arraycopy(actual, 0, prefix, 0, len);
assertArrayEquals(expected, prefix);
}
}

View File

@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.security.GeneralSecurityException;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.transport.TransportConstants.MAC_LENGTH;
@NotNullByDefault
@@ -22,7 +23,7 @@ class TestAuthenticatedCipher implements AuthenticatedCipher {
public int process(byte[] input, int inputOff, int len, byte[] output,
int outputOff) throws GeneralSecurityException {
if (encrypt) {
System.arraycopy(input, inputOff, output, outputOff, len);
arraycopy(input, inputOff, output, outputOff, len);
for (int i = 0; i < MAC_LENGTH; i++)
output[outputOff + len + i] = 0;
return len + MAC_LENGTH;
@@ -30,8 +31,7 @@ class TestAuthenticatedCipher implements AuthenticatedCipher {
for (int i = 0; i < MAC_LENGTH; i++)
if (input[inputOff + len - MAC_LENGTH + i] != 0)
throw new GeneralSecurityException();
System.arraycopy(input, inputOff, output, outputOff,
len - MAC_LENGTH);
arraycopy(input, inputOff, output, outputOff, len - MAC_LENGTH);
return len - MAC_LENGTH;
}
}

View File

@@ -7,6 +7,7 @@ import org.junit.Test;
import java.security.GeneralSecurityException;
import java.util.Random;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.util.StringUtils.fromHexString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -74,7 +75,7 @@ public class XSalsa20Poly1305AuthenticatedCipherTest extends BrambleTestCase {
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();
cipher.init(false, k, TEST_IV);
byte[] input = new byte[cipher.getMacBytes() - 1];
System.arraycopy(TEST_CIPHERTEXT, 0, input, 0, input.length);
arraycopy(TEST_CIPHERTEXT, 0, input, 0, input.length);
byte[] output = new byte[TEST_PLAINTEXT.length];
cipher.process(input, 0, input.length, output, 0);
}
@@ -85,7 +86,7 @@ public class XSalsa20Poly1305AuthenticatedCipherTest extends BrambleTestCase {
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();
cipher.init(false, k, TEST_IV);
byte[] input = new byte[TEST_CIPHERTEXT.length];
System.arraycopy(TEST_CIPHERTEXT, 0, input, 0, TEST_CIPHERTEXT.length);
arraycopy(TEST_CIPHERTEXT, 0, input, 0, TEST_CIPHERTEXT.length);
input[new Random().nextInt(TEST_CIPHERTEXT.length)] ^= 0xFF;
byte[] output = new byte[TEST_PLAINTEXT.length];
cipher.process(input, 0, input.length, output, 0);

View File

@@ -37,7 +37,6 @@ import org.junit.Test;
import java.io.File;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -47,6 +46,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
@@ -399,10 +399,10 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Both message IDs should be returned
Collection<MessageId> ids = db.getMessagesToAck(txn, contactId, 1234);
assertEquals(Arrays.asList(messageId, messageId1), ids);
assertEquals(asList(messageId, messageId1), ids);
// Remove both message IDs
db.lowerAckFlag(txn, contactId, Arrays.asList(messageId, messageId1));
db.lowerAckFlag(txn, contactId, asList(messageId, messageId1));
// Both message IDs should have been removed
assertEquals(emptyList(), db.getMessagesToAck(txn,
@@ -414,7 +414,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Both message IDs should be returned
ids = db.getMessagesToAck(txn, contactId, 1234);
assertEquals(Arrays.asList(messageId, messageId1), ids);
assertEquals(asList(messageId, messageId1), ids);
db.commitTransaction(txn);
db.close();

View File

@@ -17,8 +17,8 @@ import org.junit.Before;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.junit.Assert.assertEquals;
@@ -34,7 +34,7 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
private final Transaction txn = new Transaction(null, false);
private final LocalAuthor localAuthor = getLocalAuthor();
private final Collection<LocalAuthor> localAuthors =
Collections.singletonList(localAuthor);
singletonList(localAuthor);
private final String authorName = localAuthor.getName();
private final KeyPair keyPair = new KeyPair(publicKey, privateKey);
private final byte[] publicKeyBytes = localAuthor.getPublicKey();

View File

@@ -14,9 +14,10 @@ import org.jmock.Mockery;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import java.util.NoSuchElementException;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.test.TestUtils.getTransportId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -52,38 +53,31 @@ public class ConnectionRegistryImplTest extends BrambleTestCase {
ConnectionRegistry c = new ConnectionRegistryImpl(eventBus);
// The registry should be empty
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId));
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId1));
assertEquals(emptyList(), c.getConnectedContacts(transportId));
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
// Check that a registered connection shows up - this should
// broadcast a ConnectionOpenedEvent and a ContactConnectedEvent
c.registerConnection(contactId, transportId, true);
assertEquals(Collections.singletonList(contactId),
assertEquals(singletonList(contactId),
c.getConnectedContacts(transportId));
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId1));
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
// Register an identical connection - this should broadcast a
// ConnectionOpenedEvent and lookup should be unaffected
c.registerConnection(contactId, transportId, true);
assertEquals(Collections.singletonList(contactId),
assertEquals(singletonList(contactId),
c.getConnectedContacts(transportId));
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId1));
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
// Unregister one of the connections - this should broadcast a
// ConnectionClosedEvent and lookup should be unaffected
c.unregisterConnection(contactId, transportId, true);
assertEquals(Collections.singletonList(contactId),
assertEquals(singletonList(contactId),
c.getConnectedContacts(transportId));
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId1));
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
// Unregister the other connection - this should broadcast a
// ConnectionClosedEvent and a ContactDisconnectedEvent
c.unregisterConnection(contactId, transportId, true);
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId));
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId1));
assertEquals(emptyList(), c.getConnectedContacts(transportId));
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
// Try to unregister the connection again - exception should be thrown
try {
c.unregisterConnection(contactId, transportId, true);
@@ -101,7 +95,7 @@ public class ConnectionRegistryImplTest extends BrambleTestCase {
assertEquals(2, connected.size());
assertTrue(connected.contains(contactId));
assertTrue(connected.contains(contactId1));
assertEquals(Collections.singletonList(contactId1),
assertEquals(singletonList(contactId1),
c.getConnectedContacts(transportId1));
context.assertIsSatisfied();
}

View File

@@ -22,11 +22,11 @@ import org.jmock.lib.concurrent.Synchroniser;
import org.junit.Test;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import static java.util.Arrays.asList;
import static org.briarproject.bramble.test.TestUtils.getTransportId;
public class PluginManagerImplTest extends BrambleTestCase {
@@ -84,8 +84,7 @@ public class PluginManagerImplTest extends BrambleTestCase {
// start()
// First simplex plugin
oneOf(pluginConfig).getSimplexFactories();
will(returnValue(Arrays.asList(simplexFactory,
simplexFailFactory)));
will(returnValue(asList(simplexFactory, simplexFailFactory)));
oneOf(simplexFactory).getId();
will(returnValue(simplexId));
oneOf(simplexFactory).createPlugin(with(any(
@@ -102,7 +101,7 @@ public class PluginManagerImplTest extends BrambleTestCase {
will(throwException(new PluginException()));
// First duplex plugin
oneOf(pluginConfig).getDuplexFactories();
will(returnValue(Arrays.asList(duplexFactory, duplexFailFactory)));
will(returnValue(asList(duplexFactory, duplexFailFactory)));
oneOf(duplexFactory).getId();
will(returnValue(duplexId));
oneOf(duplexFactory).createPlugin(with(any(

View File

@@ -21,13 +21,14 @@ import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Collections;
import java.util.Comparator;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import static java.net.NetworkInterface.getNetworkInterfaces;
import static java.util.Collections.list;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.COMMIT_LENGTH;
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_LAN;
@@ -327,9 +328,8 @@ public class LanTcpPluginTest extends BrambleTestCase {
}
private boolean systemHasLocalIpv4Address() throws Exception {
for (NetworkInterface i : Collections.list(
NetworkInterface.getNetworkInterfaces())) {
for (InetAddress a : Collections.list(i.getInetAddresses())) {
for (NetworkInterface i : list(getNetworkInterfaces())) {
for (InetAddress a : list(i.getInetAddresses())) {
if (a instanceof Inet4Address)
return a.isLinkLocalAddress() || a.isSiteLocalAddress();
}

View File

@@ -25,12 +25,12 @@ import org.briarproject.bramble.test.DbExpectations;
import org.jmock.Expectations;
import org.junit.Test;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
@@ -448,7 +448,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
will(returnValue(contactGroup2));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup2.getId());
will(returnValue(Collections.emptyMap()));
will(returnValue(emptyMap()));
// Third contact: returns an update
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact3);
@@ -514,7 +514,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
// There are no existing properties to merge with
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
localGroup.getId());
will(returnValue(Collections.emptyMap()));
will(returnValue(emptyMap()));
// Store the new properties in the local group, version 1
expectStoreMessage(txn, localGroup.getId(), "foo",
fooPropertiesDict, 1, true, false);
@@ -526,7 +526,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId());
will(returnValue(Collections.emptyMap()));
will(returnValue(emptyMap()));
expectStoreMessage(txn, contactGroup.getId(), "foo",
fooPropertiesDict, 1, true, true);
}});

View File

@@ -7,6 +7,7 @@ import org.junit.Test;
import java.io.ByteArrayOutputStream;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.record.Record.MAX_RECORD_PAYLOAD_BYTES;
import static org.briarproject.bramble.api.record.Record.RECORD_HEADER_BYTES;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
@@ -42,7 +43,7 @@ public class RecordWriterImplTest extends BrambleTestCase {
assertEquals(recordType, written[1]);
assertEquals(payloadLength, readUint16(written, 2));
byte[] writtenPayload = new byte[payloadLength];
System.arraycopy(written, RECORD_HEADER_BYTES, writtenPayload, 0,
arraycopy(written, RECORD_HEADER_BYTES, writtenPayload, 0,
payloadLength);
assertArrayEquals(payload, writtenPayload);
}

View File

@@ -27,11 +27,11 @@ import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import javax.inject.Inject;
import static java.util.Arrays.asList;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION;
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
@@ -90,7 +90,7 @@ public class SyncIntegrationTest extends BrambleTestCase {
byte[] body = "Hello world".getBytes("UTF-8");
message = messageFactory.createMessage(group.getId(), timestamp, body);
message1 = messageFactory.createMessage(group.getId(), timestamp, body);
messageIds = Arrays.asList(message.getId(), message1.getId());
messageIds = asList(message.getId(), message1.getId());
}
@Test

View File

@@ -2,7 +2,6 @@ package org.briarproject.bramble.system;
import org.briarproject.bramble.api.Bytes;
import org.briarproject.bramble.test.BrambleTestCase;
import org.briarproject.bramble.util.IoUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -16,6 +15,7 @@ import java.util.Set;
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
import static org.briarproject.bramble.util.IoUtils.read;
import static org.briarproject.bramble.util.OsUtils.isLinux;
import static org.briarproject.bramble.util.OsUtils.isMac;
import static org.junit.Assert.assertArrayEquals;
@@ -64,7 +64,7 @@ public class UnixSecureRandomSpiTest extends BrambleTestCase {
assertEquals(SEED_BYTES, urandom.length());
byte[] written = new byte[SEED_BYTES];
FileInputStream in = new FileInputStream(urandom);
IoUtils.read(in, written);
read(in, written);
in.close();
assertArrayEquals(seed, written);
}

View File

@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageFactory;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
@NotNullByDefault
@@ -24,7 +25,7 @@ public class TestMessageFactory implements MessageFactory {
public byte[] getRawMessage(Message m) {
byte[] body = m.getBody();
byte[] raw = new byte[MESSAGE_HEADER_LENGTH + body.length];
System.arraycopy(body, 0, raw, MESSAGE_HEADER_LENGTH, body.length);
arraycopy(body, 0, raw, MESSAGE_HEADER_LENGTH, body.length);
return raw;
}
}

View File

@@ -5,11 +5,11 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import static java.util.Collections.sort;
import static org.briarproject.bramble.test.UTest.Result.INCONCLUSIVE;
import static org.briarproject.bramble.test.UTest.Result.LARGER;
import static org.briarproject.bramble.test.UTest.Result.SMALLER;
@@ -80,7 +80,7 @@ public class UTest {
List<Value> sorted = new ArrayList<>(nA + nB);
for (Double d : a) sorted.add(new Value(d, true));
for (Double d : b) sorted.add(new Value(d, false));
Collections.sort(sorted);
sort(sorted);
// Assign ranks to the values
int i = 0, size = sorted.size();

View File

@@ -4,9 +4,9 @@ import org.briarproject.bramble.test.BrambleTestCase;
import org.briarproject.bramble.transport.ReorderingWindow.Change;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.junit.Assert.assertArrayEquals;
@@ -33,9 +33,9 @@ public class ReorderingWindowTest extends BrambleTestCase {
Change change = window.setSeen(0L);
// The window should slide by one element
assertEquals(1L, window.getBase());
assertEquals(Collections.singletonList((long) REORDERING_WINDOW_SIZE),
assertEquals(singletonList((long) REORDERING_WINDOW_SIZE),
change.getAdded());
assertEquals(Collections.singletonList(0L), change.getRemoved());
assertEquals(singletonList(0L), change.getRemoved());
// All elements in the window should be unseen
assertArrayEquals(bitmap, window.getBitmap());
}
@@ -48,8 +48,8 @@ public class ReorderingWindowTest extends BrambleTestCase {
Change change = window.setSeen(1L);
// The window should not slide
assertEquals(0L, window.getBase());
assertEquals(Collections.emptyList(), change.getAdded());
assertEquals(Collections.singletonList(1L), change.getRemoved());
assertEquals(emptyList(), change.getAdded());
assertEquals(singletonList(1L), change.getRemoved());
// The second element in the window should be seen
bitmap[0] = 0x40; // 0100 0000
assertArrayEquals(bitmap, window.getBitmap());
@@ -64,9 +64,9 @@ public class ReorderingWindowTest extends BrambleTestCase {
Change change = window.setSeen(aboveMidpoint);
// The window should slide by one element
assertEquals(1L, window.getBase());
assertEquals(Collections.singletonList((long) REORDERING_WINDOW_SIZE),
assertEquals(singletonList((long) REORDERING_WINDOW_SIZE),
change.getAdded());
assertEquals(Arrays.asList(0L, aboveMidpoint), change.getRemoved());
assertEquals(asList(0L, aboveMidpoint), change.getRemoved());
// The highest element below the midpoint should be seen
bitmap[bitmap.length / 2 - 1] = (byte) 0x01; // 0000 0001
assertArrayEquals(bitmap, window.getBitmap());
@@ -81,9 +81,9 @@ public class ReorderingWindowTest extends BrambleTestCase {
Change change = window.setSeen(0L);
// The window should slide by two elements
assertEquals(2L, window.getBase());
assertEquals(Arrays.asList((long) REORDERING_WINDOW_SIZE,
assertEquals(asList((long) REORDERING_WINDOW_SIZE,
(long) (REORDERING_WINDOW_SIZE + 1)), change.getAdded());
assertEquals(Collections.singletonList(0L), change.getRemoved());
assertEquals(singletonList(0L), change.getRemoved());
// All elements in the window should be unseen
assertArrayEquals(bitmap, window.getBitmap());
}
@@ -98,9 +98,9 @@ public class ReorderingWindowTest extends BrambleTestCase {
Change change = window.setSeen(aboveMidpoint);
// The window should slide by two elements
assertEquals(2L, window.getBase());
assertEquals(Arrays.asList((long) REORDERING_WINDOW_SIZE,
assertEquals(asList((long) REORDERING_WINDOW_SIZE,
(long) (REORDERING_WINDOW_SIZE + 1)), change.getAdded());
assertEquals(Arrays.asList(0L, aboveMidpoint), change.getRemoved());
assertEquals(asList(0L, aboveMidpoint), change.getRemoved());
// The second-highest element below the midpoint should be seen
bitmap[bitmap.length / 2 - 1] = (byte) 0x02; // 0000 0010
assertArrayEquals(bitmap, window.getBitmap());

View File

@@ -7,6 +7,7 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import static java.lang.System.arraycopy;
import static org.briarproject.bramble.api.transport.TransportConstants.FRAME_HEADER_LENGTH;
import static org.briarproject.bramble.api.transport.TransportConstants.MAC_LENGTH;
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_FRAME_LENGTH;
@@ -47,7 +48,7 @@ class TestStreamDecrypter implements StreamDecrypter {
if (read == -1) throw new EOFException();
offset += read;
}
System.arraycopy(frame, FRAME_HEADER_LENGTH, payload, 0, payloadLength);
arraycopy(frame, FRAME_HEADER_LENGTH, payload, 0, payloadLength);
return payloadLength;
}

View File

@@ -16,7 +16,6 @@ import com.sun.jna.win32.W32APITypeMapper;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -26,6 +25,7 @@ import javax.annotation.concurrent.ThreadSafe;
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
import static com.sun.jna.Library.OPTION_TYPE_MAPPER;
import static java.util.Collections.unmodifiableMap;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logException;
@@ -51,7 +51,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
Map<String, Object> m = new HashMap<>();
m.put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
m.put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
options = Collections.unmodifiableMap(m);
options = unmodifiableMap(m);
}
@Override

View File

@@ -26,6 +26,7 @@ import javax.annotation.Nullable;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import static java.lang.System.arraycopy;
import static java.nio.charset.CodingErrorAction.IGNORE;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.INFO;
@@ -375,7 +376,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
int off = i + 1;
if (off < b.length) {
byte[] data = new byte[b.length - off];
System.arraycopy(b, off, data, 0, data.length);
arraycopy(b, off, data, 0, data.length);
handleData(data);
}
return;

View File

@@ -25,7 +25,6 @@ import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -46,6 +45,9 @@ import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED;
import static android.content.pm.PackageManager.GET_PERMISSIONS;
import static android.content.pm.PackageManager.GET_SIGNATURES;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.Collections.emptySet;
import static java.util.Collections.sort;
import static java.util.Collections.unmodifiableList;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logException;
@@ -105,8 +107,7 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
@UiThread
public Collection<AppDetails> getApps() {
if (cachedApps != null) return cachedApps;
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED,
Collections.emptySet());
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED, emptySet());
List<AppDetails> apps = new ArrayList<>();
List<PackageInfo> packageInfos =
pm.getInstalledPackages(GET_PERMISSIONS);
@@ -117,8 +118,8 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
apps.add(new AppDetails(name, packageInfo.packageName));
}
}
Collections.sort(apps, (a, b) -> a.name.compareTo(b.name));
apps = Collections.unmodifiableList(apps);
sort(apps, (a, b) -> a.name.compareTo(b.name));
apps = unmodifiableList(apps);
cachedApps = apps;
return apps;
}
@@ -127,8 +128,7 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
@UiThread
public void allowApps(Collection<String> packageNames) {
cachedApps = null;
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED,
Collections.emptySet());
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED, emptySet());
Set<String> merged = new HashSet<>(allowed);
merged.addAll(packageNames);
prefs.edit().putStringSet(PREF_KEY_ALLOWED, merged).apply();

View File

@@ -4,10 +4,11 @@ import org.briarproject.briar.api.blog.BlogCommentHeader;
import org.briarproject.briar.api.blog.BlogPostHeader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static java.util.Collections.sort;
// This class is not thread-safe
class BlogCommentItem extends BlogPostItem {
@@ -20,7 +21,7 @@ class BlogCommentItem extends BlogPostItem {
BlogCommentItem(BlogCommentHeader header) {
super(header, null);
postHeader = collectComments(header);
Collections.sort(comments, COMPARATOR);
sort(comments, COMPARATOR);
}
private BlogPostHeader collectComments(BlogPostHeader header) {

View File

@@ -7,7 +7,6 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
@@ -23,7 +22,6 @@ import org.briarproject.briar.android.logging.BriefLogFormatter;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.Callable;
@@ -41,6 +39,8 @@ import static android.content.Context.WIFI_SERVICE;
import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.Collections.unmodifiableMap;
import static org.briarproject.bramble.util.PrivacyUtils.scrubInetAddress;
import static org.briarproject.bramble.util.PrivacyUtils.scrubMacAddress;
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
@@ -90,7 +90,7 @@ public class BriarReportPrimer implements ReportPrimer {
ActivityManager.MemoryInfo mem = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mem);
String systemMemory;
if (Build.VERSION.SDK_INT >= 16) {
if (SDK_INT >= 16) {
systemMemory = (mem.totalMem / 1024 / 1024) + " MiB total, "
+ (mem.availMem / 1024 / 1204) + " MiB free, "
+ (mem.threshold / 1024 / 1024) + " MiB threshold";
@@ -213,7 +213,7 @@ public class BriarReportPrimer implements ReportPrimer {
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE;
// Is Bluetooth LE scanning and advertising supported?
boolean btLeApi = false, btLeScan = false, btLeAdvertise = false;
if (bt != null && Build.VERSION.SDK_INT >= 21) {
if (bt != null && SDK_INT >= 21) {
btLeApi = true;
btLeScan = bt.getBluetoothLeScanner() != null;
btLeAdvertise = bt.getBluetoothLeAdvertiser() != null;
@@ -255,7 +255,7 @@ public class BriarReportPrimer implements ReportPrimer {
// Git commit ID
customData.put("Commit ID", BuildConfig.GitHash);
return Collections.unmodifiableMap(customData);
return unmodifiableMap(customData);
}
}

View File

@@ -42,7 +42,6 @@ import org.briarproject.briar.android.Localizer;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;
@@ -67,6 +66,7 @@ import static android.provider.Settings.EXTRA_CHANNEL_ID;
import static android.provider.Settings.System.DEFAULT_NOTIFICATION_URI;
import static android.support.v4.view.ViewCompat.LAYOUT_DIRECTION_LTR;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.Arrays.asList;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
@@ -222,7 +222,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
if (SDK_INT < 27) {
// remove System Default Theme option
List<CharSequence> entries =
new ArrayList<>(Arrays.asList(theme.getEntries()));
new ArrayList<>(asList(theme.getEntries()));
entries.remove(getString(R.string.pref_theme_system));
theme.setEntries(entries.toArray(new CharSequence[0]));
}

View File

@@ -1,7 +1,6 @@
package org.briarproject.briar.android.splash;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.preference.PreferenceManager;
@@ -21,6 +20,7 @@ import java.util.logging.Logger;
import javax.inject.Inject;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
@@ -40,7 +40,7 @@ public class SplashScreenActivity extends BaseActivity {
public void onCreate(Bundle state) {
super.onCreate(state);
if (Build.VERSION.SDK_INT >= 21) {
if (SDK_INT >= 21) {
getWindow().setExitTransition(new Fade());
}

View File

@@ -28,12 +28,12 @@ import org.briarproject.briar.api.client.PostHeader;
import org.briarproject.briar.api.client.ThreadedMessage;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import static java.util.Collections.singletonList;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
@@ -186,7 +186,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
@Override
public void markItemRead(I item) {
markItemsRead(Collections.singletonList(item));
markItemsRead(singletonList(item));
}
@Override

View File

@@ -8,7 +8,6 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.UiThread;
import android.util.AttributeSet;
@@ -26,6 +25,7 @@ import java.util.logging.Logger;
import javax.annotation.Nullable;
import static android.content.Context.WINDOW_SERVICE;
import static android.os.Build.VERSION.SDK_INT;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
import static java.util.Objects.requireNonNull;
@@ -106,7 +106,7 @@ public class KeyboardAwareLinearLayout extends LinearLayout {
return;
}
if (viewInset == 0 && Build.VERSION.SDK_INT >= 21)
if (viewInset == 0 && SDK_INT >= 21)
viewInset = getViewInset();
int availableHeight =
getRootView().getHeight() - statusBarHeight - viewInset;

View File

@@ -21,8 +21,7 @@ import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.Arrays;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNKNOWN;
@@ -91,7 +90,7 @@ public class ForumActivityTest {
forumItems[i].setLevel(LEVELS[i]);
}
ThreadItemList<ForumItem> list = new ThreadItemListImpl<>();
list.addAll(Arrays.asList(forumItems));
list.addAll(asList(forumItems));
return list;
}

View File

@@ -38,7 +38,6 @@ import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -50,6 +49,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.Nullable;
import javax.inject.Inject;
import static java.util.Collections.emptyMap;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
@@ -560,8 +560,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
GroupId groupId, MessageId id, BdfDictionary meta)
throws DbException, FormatException {
return getPostHeaderFromMetadata(txn, groupId, id, meta,
Collections.emptyMap());
return getPostHeaderFromMetadata(txn, groupId, id, meta, emptyMap());
}
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,

View File

@@ -6,7 +6,6 @@ import org.briarproject.briar.api.client.MessageTree;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@@ -14,6 +13,9 @@ import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;
import static java.util.Collections.singletonList;
import static java.util.Collections.sort;
@ThreadSafe
@NotNullByDefault
public class MessageTreeImpl<T extends MessageTree.MessageNode>
@@ -47,7 +49,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
@Override
public synchronized void add(T node) {
add(Collections.singletonList(node));
add(singletonList(node));
}
private void markAsUnsorted(List<T> list) {
@@ -69,7 +71,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
private void sortUnsorted() {
for (List<T> list : unsortedLists) {
Collections.sort(list, comparator);
sort(list, comparator);
}
unsortedLists.clear();
}
@@ -87,9 +89,9 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
public synchronized void setComparator(Comparator<T> comparator) {
this.comparator = comparator;
// Sort all lists with the new comparator
Collections.sort(roots, comparator);
sort(roots, comparator);
for (Map.Entry<MessageId, List<T>> entry : nodeMap.entrySet()) {
Collections.sort(entry.getValue(), comparator);
sort(entry.getValue(), comparator);
}
}

View File

@@ -2,13 +2,14 @@ package org.briarproject.briar.feed;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import okhttp3.Dns;
import static java.util.Collections.singletonList;
class NoDns implements Dns {
private static final byte[] UNSPECIFIED_ADDRESS = new byte[4];
@@ -22,7 +23,7 @@ class NoDns implements Dns {
throws UnknownHostException {
InetAddress unspecified =
InetAddress.getByAddress(hostname, UNSPECIFIED_ADDRESS);
return Collections.singletonList(unspecified);
return singletonList(unspecified);
}
}

View File

@@ -32,7 +32,6 @@ import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -45,6 +44,7 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static java.util.Collections.emptyMap;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_LOCAL;
@@ -249,7 +249,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
BdfDictionary meta) throws DbException, FormatException {
return getForumPostHeader(txn, id, meta, Collections.emptyMap());
return getForumPostHeader(txn, id, meta, emptyMap());
}
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,

View File

@@ -15,10 +15,9 @@ import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.briar.api.client.SessionId;
import java.util.Collections;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAC_BYTES;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_BYTES;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
@@ -84,8 +83,7 @@ class IntroductionValidator extends BdfMessageValidator {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}
@@ -118,8 +116,7 @@ class IntroductionValidator extends BdfMessageValidator {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}
@@ -144,8 +141,7 @@ class IntroductionValidator extends BdfMessageValidator {
.encodeMetadata(AUTH, sessionId, m.getTimestamp(), false, false,
false);
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
private BdfMessageContext validateActivateMessage(Message m, BdfList body)
@@ -169,8 +165,7 @@ class IntroductionValidator extends BdfMessageValidator {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}
@@ -192,8 +187,7 @@ class IntroductionValidator extends BdfMessageValidator {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}

View File

@@ -42,7 +42,6 @@ import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -54,6 +53,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static java.util.Collections.emptyMap;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNVERIFIED;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
@@ -574,7 +574,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
BdfDictionary meta, boolean local)
throws DbException, FormatException {
GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(),
m.getId(), meta, Collections.emptyMap());
m.getId(), meta, emptyMap());
String text = getMessageText(clientHelper.toList(m));
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, text,
local));
@@ -584,7 +584,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
BdfDictionary meta, boolean local, Visibility v)
throws DbException, FormatException {
JoinMessageHeader header = getJoinMessageHeader(txn, m.getGroupId(),
m.getId(), meta, Collections.emptyMap(), v);
m.getId(), meta, emptyMap(), v);
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, "",
local));
}

View File

@@ -19,10 +19,10 @@ import org.briarproject.briar.api.privategroup.PrivateGroup;
import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
import java.security.GeneralSecurityException;
import java.util.Collections;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
@@ -120,8 +120,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}
@@ -139,8 +138,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}

View File

@@ -15,10 +15,9 @@ import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.api.system.Clock;
import java.util.Collections;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
@@ -70,8 +69,7 @@ abstract class SharingValidator extends BdfMessageValidator {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}
@@ -93,8 +91,7 @@ abstract class SharingValidator extends BdfMessageValidator {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}

View File

@@ -5,11 +5,11 @@ import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.MessageTree;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import javax.annotation.Nullable;
import static java.util.Arrays.asList;
import static java.util.Arrays.copyOf;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.junit.Assert.assertEquals;
@@ -48,8 +48,8 @@ public class MessageTreeImplTest {
nodes[3].setTimestamp(timestamp - 2);
nodes[2].setTimestamp(timestamp - 1);
// add all nodes except the last one
tree.add(Arrays.asList(Arrays.copyOf(nodes, nodes.length - 1)));
tree.add(Collections.singletonList(nodes[nodes.length - 1]));
tree.add(asList(copyOf(nodes, nodes.length - 1)));
tree.add(singletonList(nodes[nodes.length - 1]));
TestNode[] sortedNodes =
tree.depthFirstOrder().toArray(new TestNode[5]);
assertEquals(nodes[4], sortedNodes[0]);

View File

@@ -16,10 +16,11 @@ import org.jmock.Expectations;
import org.junit.Test;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
@@ -178,7 +179,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);
assertExpectedMessageContext(messageContext, JOIN, creatorList,
Collections.emptyList());
emptyList());
assertTrue(messageContext.getDictionary()
.getBoolean(KEY_INITIAL_JOIN_MSG));
}
@@ -363,7 +364,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);
assertExpectedMessageContext(messageContext, JOIN, memberList,
Collections.emptyList());
emptyList());
assertFalse(messageContext.getDictionary()
.getBoolean(KEY_INITIAL_JOIN_MSG));
}
@@ -606,7 +607,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);
assertExpectedMessageContext(messageContext, POST, memberList,
Arrays.asList(parentId, previousMsgId));
asList(parentId, previousMsgId));
assertArrayEquals(previousMsgId.getBytes(),
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
assertArrayEquals(parentId.getBytes(),
@@ -621,7 +622,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);
assertExpectedMessageContext(messageContext, POST, memberList,
Collections.singletonList(previousMsgId));
singletonList(previousMsgId));
assertArrayEquals(previousMsgId.getBytes(),
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
assertFalse(

View File

@@ -35,14 +35,16 @@ import org.jmock.Expectations;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static junit.framework.TestCase.fail;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
@@ -112,9 +114,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
private final BdfDictionary bdfSession =
BdfDictionary.of(new BdfEntry("f", "o"));
private final Map<MessageId, BdfDictionary> oneResult =
Collections.singletonMap(storageMessage.getId(), bdfSession);
private final Map<MessageId, BdfDictionary> noResults =
Collections.emptyMap();
singletonMap(storageMessage.getId(), bdfSession);
private final Map<MessageId, BdfDictionary> noResults = emptyMap();
public GroupInvitationManagerImplTest() {
@@ -156,7 +157,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
will(returnValue(false));
oneOf(db).addGroup(txn, localGroup);
oneOf(db).getContacts(txn);
will(returnValue(Collections.singletonList(contact)));
will(returnValue(singletonList(contact)));
}});
expectAddingContact(contact);
groupInvitationManager.createLocalState(txn);
@@ -192,7 +193,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
.mergeGroupMetadata(txn, contactGroup.getId(), meta);
oneOf(db).getGroups(txn, PrivateGroupManager.CLIENT_ID,
PrivateGroupManager.MAJOR_VERSION);
will(returnValue(Collections.singletonList(privateGroup)));
will(returnValue(singletonList(privateGroup)));
oneOf(privateGroupManager).isMember(txn, privateGroup.getId(),
c.getAuthor());
will(returnValue(true));
@@ -743,7 +744,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true);
will(returnValue(txn));
oneOf(db).getContacts(txn);
will(returnValue(Collections.singletonList(contact)));
will(returnValue(singletonList(contact)));
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact);
will(returnValue(contactGroup));
@@ -836,7 +837,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
expectAddingMember(privateGroup.getId(), contact);
context.checking(new Expectations() {{
oneOf(db).getContactsByAuthorId(txn, author.getId());
will(returnValue(Collections.singletonList(contact)));
will(returnValue(singletonList(contact)));
}});
groupInvitationManager.addingMember(txn, privateGroup.getId(), author);
}
@@ -847,8 +848,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
author.getId(), getRandomString(5), true, true);
Contact contact3 = new Contact(new ContactId(3), author,
author.getId(), getRandomString(5), true, true);
Collection<Contact> contacts =
Arrays.asList(contact, contact2, contact3);
Collection<Contact> contacts = asList(contact, contact2, contact3);
Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION);
Group contactGroup3 = getGroup(CLIENT_ID, MAJOR_VERSION);
@@ -861,9 +861,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
BdfDictionary.of(new BdfEntry("f3", "o"));
expectGetSession(oneResult, sessionId, contactGroup.getId());
expectGetSession(Collections.singletonMap(storageId2, bdfSession2),
expectGetSession(singletonMap(storageId2, bdfSession2),
sessionId, contactGroup2.getId());
expectGetSession(Collections.singletonMap(storageId3, bdfSession3),
expectGetSession(singletonMap(storageId3, bdfSession3),
sessionId, contactGroup3.getId());
context.checking(new Expectations() {{

View File

@@ -11,9 +11,9 @@ import org.briarproject.briar.api.privategroup.GroupMessage;
import org.jmock.Expectations;
import org.junit.Test;
import java.util.Collections;
import java.util.Map;
import static java.util.Collections.singletonMap;
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
@@ -753,7 +753,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
BdfDictionary query = BdfDictionary.of(new BdfEntry("query", ""));
BdfDictionary meta = BdfDictionary.of(new BdfEntry("meta", ""));
Map<MessageId, BdfDictionary> invites =
Collections.singletonMap(lastRemoteMessageId, meta);
singletonMap(lastRemoteMessageId, meta);
context.checking(new Expectations() {{
oneOf(messageParser)
.getInvitesAvailableToAnswerQuery(privateGroupId);

View File

@@ -28,10 +28,11 @@ import org.jmock.Expectations;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getGroup;
@@ -66,8 +67,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
private final Contact contact =
new Contact(contactId, author, localAuthor.getId(),
getRandomString(5), true, true);
private final Collection<Contact> contacts =
Collections.singletonList(contact);
private final Collection<Contact> contacts = singletonList(contact);
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final Group blogGroup =
@@ -120,7 +120,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
private void expectAddingContact(Transaction txn) throws Exception {
BdfDictionary meta = BdfDictionary.of(
new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
Map<MessageId, BdfDictionary> sessions = Collections.emptyMap();
Map<MessageId, BdfDictionary> sessions = emptyMap();
context.checking(new Expectations() {{
// Create the contact group and share it with the contact

View File

@@ -16,6 +16,7 @@ import org.briarproject.briar.headless.contact.ContactController
import org.briarproject.briar.headless.event.WebSocketController
import org.briarproject.briar.headless.forums.ForumController
import org.briarproject.briar.headless.messaging.MessagingController
import java.lang.Integer.parseInt
import java.lang.Runtime.getRuntime
import java.lang.System.exit
import java.util.concurrent.atomic.AtomicBoolean
@@ -128,7 +129,7 @@ constructor(
fun Context.getContactIdFromPathParam(): ContactId {
val contactString = pathParam("contactId")
val contactInt = try {
Integer.parseInt(contactString)
parseInt(contactString)
} catch (e: NumberFormatException) {
throw NotFoundResponse()
}