Verified Commit d7383a33 authored by akwizgran's avatar akwizgran Committed by Torsten Grote

Effectively final.

parent a5b321a9
......@@ -45,7 +45,7 @@ public class AndroidPluginModule {
backoffFactory);
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
backoffFactory, appContext);
final Collection<DuplexPluginFactory> duplex =
Collection<DuplexPluginFactory> duplex =
Arrays.asList(bluetooth, tor, lan);
@NotNullByDefault
PluginConfig pluginConfig = new PluginConfig() {
......
......@@ -285,11 +285,11 @@ class DroidtoothPlugin implements DuplexPlugin, EventListener {
Map<ContactId, TransportProperties> remote =
callback.getRemoteProperties();
for (Entry<ContactId, TransportProperties> e : remote.entrySet()) {
final ContactId c = e.getKey();
ContactId c = e.getKey();
if (connected.contains(c)) continue;
final String address = e.getValue().get(PROP_ADDRESS);
String address = e.getValue().get(PROP_ADDRESS);
if (StringUtils.isNullOrEmpty(address)) continue;
final String uuid = e.getValue().get(PROP_UUID);
String uuid = e.getValue().get(PROP_UUID);
if (StringUtils.isNullOrEmpty(uuid)) continue;
ioExecutor.execute(() -> {
if (!running) return;
......
......@@ -400,7 +400,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
}
socket = ss;
// Store the port number
final String localPort = String.valueOf(ss.getLocalPort());
String localPort = String.valueOf(ss.getLocalPort());
Settings s = new Settings();
s.put(PREF_TOR_PORT, localPort);
callback.mergeSettings(s);
......@@ -536,8 +536,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
}
}
private void connectAndCallBack(final ContactId c,
final TransportProperties p) {
private void connectAndCallBack(ContactId c, TransportProperties p) {
ioExecutor.execute(() -> {
if (!isRunning()) return;
DuplexTransportConnection d = createConnection(p);
......
......@@ -48,8 +48,8 @@ public class PoliteExecutor implements Executor {
}
@Override
public void execute(final Runnable r) {
final long submitted = System.currentTimeMillis();
public void execute(Runnable r) {
long submitted = System.currentTimeMillis();
Runnable wrapped = () -> {
if (log.isLoggable(LOG_LEVEL)) {
long queued = System.currentTimeMillis() - submitted;
......
......@@ -28,9 +28,9 @@ public class TimeLoggingExecutor extends ThreadPoolExecutor {
}
@Override
public void execute(final Runnable r) {
public void execute(Runnable r) {
if (log.isLoggable(LOG_LEVEL)) {
final long submitted = System.currentTimeMillis();
long submitted = System.currentTimeMillis();
super.execute(() -> {
long started = System.currentTimeMillis();
long queued = started - submitted;
......
......@@ -88,7 +88,7 @@ class LifecycleManagerImpl implements LifecycleManager {
executors.add(e);
}
private LocalAuthor createLocalAuthor(final String nickname) {
private LocalAuthor createLocalAuthor(String nickname) {
long now = System.currentTimeMillis();
KeyPair keyPair = crypto.generateSignatureKeyPair();
byte[] publicKey = keyPair.getPublic().getEncoded();
......
......@@ -111,7 +111,7 @@ class Poller implements EventListener {
connectToContact(c, (DuplexPlugin) p);
}
private void connectToContact(final ContactId c, final SimplexPlugin p) {
private void connectToContact(ContactId c, SimplexPlugin p) {
ioExecutor.execute(() -> {
TransportId t = p.getId();
if (!connectionRegistry.isConnected(c, t)) {
......@@ -122,7 +122,7 @@ class Poller implements EventListener {
});
}
private void connectToContact(final ContactId c, final DuplexPlugin p) {
private void connectToContact(ContactId c, DuplexPlugin p) {
ioExecutor.execute(() -> {
TransportId t = p.getId();
if (!connectionRegistry.isConnected(c, t)) {
......@@ -153,7 +153,7 @@ class Poller implements EventListener {
try {
PollTask scheduled = tasks.get(t);
if (scheduled == null || due < scheduled.due) {
final PollTask task = new PollTask(p, due, randomiseNext);
PollTask task = new PollTask(p, due, randomiseNext);
tasks.put(t, task);
scheduler.schedule(
() -> ioExecutor.execute(task), delay, MILLISECONDS);
......@@ -164,7 +164,7 @@ class Poller implements EventListener {
}
@IoExecutor
private void poll(final Plugin p) {
private void poll(Plugin p) {
TransportId t = p.getId();
if (LOG.isLoggable(INFO)) LOG.info("Polling plugin " + t);
p.poll(connectionRegistry.getConnectedContacts(t));
......
......@@ -108,7 +108,7 @@ abstract class FilePlugin implements SimplexPlugin {
}
}
protected void createReaderFromFile(final File f) {
protected void createReaderFromFile(File f) {
if (!running) return;
ioExecutor.execute(new ReaderCreator(f));
}
......
......@@ -37,7 +37,7 @@ class PortMapperImpl implements PortMapper {
}
@Override
public MappingResult map(final int port) {
public MappingResult map(int port) {
if (!started.getAndSet(true)) start();
if (gateway == null) return null;
InetAddress internal = gateway.getLocalAddress();
......
......@@ -214,8 +214,7 @@ abstract class TcpPlugin implements DuplexPlugin {
}
}
private void connectAndCallBack(final ContactId c,
final TransportProperties p) {
private void connectAndCallBack(ContactId c, TransportProperties p) {
ioExecutor.execute(() -> {
if (!isRunning()) return;
DuplexTransportConnection d = createConnection(p);
......
......@@ -48,7 +48,7 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
@Override
public void start() {
SlipEncoder encoder = new SlipEncoder(this);
final Sender sender = new Sender(clock, encoder);
Sender sender = new Sender(clock, encoder);
receiver = new Receiver(clock, sender);
decoder = new SlipDecoder(receiver, Data.MAX_LENGTH);
inputStream = new ReceiverInputStream(receiver);
......
......@@ -93,7 +93,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
hooks.put(c, hook);
}
private void validateOutstandingMessagesAsync(final ClientId c) {
private void validateOutstandingMessagesAsync(ClientId c) {
dbExecutor.execute(() -> validateOutstandingMessages(c));
}
......@@ -114,7 +114,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
}
}
private void validateNextMessageAsync(final Queue<MessageId> unvalidated) {
private void validateNextMessageAsync(Queue<MessageId> unvalidated) {
if (unvalidated.isEmpty()) return;
dbExecutor.execute(() -> validateNextMessage(unvalidated));
}
......@@ -148,7 +148,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
}
}
private void deliverOutstandingMessagesAsync(final ClientId c) {
private void deliverOutstandingMessagesAsync(ClientId c) {
dbExecutor.execute(() -> deliverOutstandingMessages(c));
}
......@@ -169,8 +169,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
}
}
private void deliverNextPendingMessageAsync(
final Queue<MessageId> pending) {
private void deliverNextPendingMessageAsync(Queue<MessageId> pending) {
if (pending.isEmpty()) return;
dbExecutor.execute(() -> deliverNextPendingMessage(pending));
}
......@@ -234,7 +233,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
}
}
private void validateMessageAsync(final Message m, final Group g) {
private void validateMessageAsync(Message m, Group g) {
validationExecutor.execute(() -> validateMessage(m, g));
}
......@@ -258,8 +257,8 @@ class ValidationManagerImpl implements ValidationManager, Service,
}
}
private void storeMessageContextAsync(final Message m, final ClientId c,
final MessageContext result) {
private void storeMessageContextAsync(Message m, ClientId c,
MessageContext result) {
dbExecutor.execute(() -> storeMessageContext(m, c, result));
}
......@@ -354,7 +353,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
return pending;
}
private void shareOutstandingMessagesAsync(final ClientId c) {
private void shareOutstandingMessagesAsync(ClientId c) {
dbExecutor.execute(() -> shareOutstandingMessages(c));
}
......@@ -381,7 +380,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
* This method should only be called for messages that have all their
* dependencies delivered and have been delivered themselves.
*/
private void shareNextMessageAsync(final Queue<MessageId> toShare) {
private void shareNextMessageAsync(Queue<MessageId> toShare) {
if (toShare.isEmpty()) return;
dbExecutor.execute(() -> shareNextMessage(toShare));
}
......@@ -410,7 +409,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
}
}
private void invalidateNextMessageAsync(final Queue<MessageId> invalidate) {
private void invalidateNextMessageAsync(Queue<MessageId> invalidate) {
if (invalidate.isEmpty()) return;
dbExecutor.execute(() -> invalidateNextMessage(invalidate));
}
......@@ -467,12 +466,12 @@ class ValidationManagerImpl implements ValidationManager, Service,
}
}
private void loadGroupAndValidateAsync(final Message m) {
private void loadGroupAndValidateAsync(Message m) {
dbExecutor.execute(() -> loadGroupAndValidate(m));
}
@DatabaseExecutor
private void loadGroupAndValidate(final Message m) {
private void loadGroupAndValidate(Message m) {
try {
Group g;
Transaction txn = db.startTransaction(true);
......
......@@ -155,7 +155,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
}
}
private void removeContact(final ContactId c) {
private void removeContact(ContactId c) {
activeContacts.remove(c);
dbExecutor.execute(() -> {
for (TransportKeyManager m : managers.values()) m.removeContact(c);
......
......@@ -24,10 +24,10 @@ public class PoliteExecutorTest extends BrambleTestCase {
Executor delegate = Executors.newSingleThreadExecutor();
// Allow all the tasks to be delegated straight away
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, TASKS * 2);
final List<Integer> list = new Vector<>();
final CountDownLatch latch = new CountDownLatch(TASKS);
List<Integer> list = new Vector<>();
CountDownLatch latch = new CountDownLatch(TASKS);
for (int i = 0; i < TASKS; i++) {
final int result = i;
int result = i;
polite.execute(() -> {
list.add(result);
latch.countDown();
......@@ -46,10 +46,10 @@ public class PoliteExecutorTest extends BrambleTestCase {
Executor delegate = Executors.newSingleThreadExecutor();
// Allow two tasks to be delegated at a time
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, 2);
final List<Integer> list = new Vector<>();
final CountDownLatch latch = new CountDownLatch(TASKS);
List<Integer> list = new Vector<>();
CountDownLatch latch = new CountDownLatch(TASKS);
for (int i = 0; i < TASKS; i++) {
final int result = i;
int result = i;
polite.execute(() -> {
list.add(result);
latch.countDown();
......@@ -67,11 +67,11 @@ public class PoliteExecutorTest extends BrambleTestCase {
Executor delegate = Executors.newCachedThreadPool();
// Allow all the tasks to be delegated straight away
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, TASKS * 2);
final List<Integer> list = new Vector<>();
final CountDownLatch[] latches = new CountDownLatch[TASKS];
List<Integer> list = new Vector<>();
CountDownLatch[] latches = new CountDownLatch[TASKS];
for (int i = 0; i < TASKS; i++) latches[i] = new CountDownLatch(1);
for (int i = 0; i < TASKS; i++) {
final int result = i;
int result = i;
polite.execute(() -> {
try {
// Each task waits for the next task, if any, to finish
......@@ -95,10 +95,10 @@ public class PoliteExecutorTest extends BrambleTestCase {
Executor delegate = Executors.newCachedThreadPool();
// Allow one task to be delegated at a time
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, 1);
final List<Integer> list = new Vector<>();
final CountDownLatch latch = new CountDownLatch(TASKS);
List<Integer> list = new Vector<>();
CountDownLatch latch = new CountDownLatch(TASKS);
for (int i = 0; i < TASKS; i++) {
final int result = i;
int result = i;
polite.execute(() -> {
try {
// Each task runs faster than the previous task
......
......@@ -83,9 +83,9 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
@Test(expected = InvalidMessageException.class)
public void testRejectsTooShortMessage() throws Exception {
final byte[] invalidRaw = new byte[MESSAGE_HEADER_LENGTH];
byte[] invalidRaw = new byte[MESSAGE_HEADER_LENGTH];
// Use a mock message so the length of the raw message can be invalid
final Message invalidMessage = context.mock(Message.class);
Message invalidMessage = context.mock(Message.class);
context.checking(new Expectations() {{
oneOf(invalidMessage).getTimestamp();
......@@ -101,8 +101,8 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
@Test
public void testAcceptsMinLengthMessage() throws Exception {
final byte[] shortRaw = new byte[MESSAGE_HEADER_LENGTH + 1];
final Message shortMessage =
byte[] shortRaw = new byte[MESSAGE_HEADER_LENGTH + 1];
Message shortMessage =
new Message(messageId, groupId, timestamp, shortRaw);
context.checking(new Expectations() {{
......
......@@ -76,8 +76,8 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testAddLocalMessage() throws Exception {
final boolean shared = true;
final Transaction txn = new Transaction(null, false);
boolean shared = true;
Transaction txn = new Transaction(null, false);
context.checking(new Expectations() {{
oneOf(db).startTransaction(false);
......@@ -95,7 +95,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testCreateMessage() throws Exception {
final byte[] bytes = expectToByteArray(list);
byte[] bytes = expectToByteArray(list);
context.checking(new Expectations() {{
oneOf(messageFactory).createMessage(groupId, timestamp, bytes);
......@@ -107,7 +107,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testGetMessageAsList() throws Exception {
final Transaction txn = new Transaction(null, true);
Transaction txn = new Transaction(null, true);
expectToList(true);
context.checking(new Expectations() {{
......@@ -125,7 +125,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testGetGroupMetadataAsDictionary() throws Exception {
final Transaction txn = new Transaction(null, true);
Transaction txn = new Transaction(null, true);
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
......@@ -145,7 +145,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testGetMessageMetadataAsDictionary() throws Exception {
final Transaction txn = new Transaction(null, true);
Transaction txn = new Transaction(null, true);
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
......@@ -165,9 +165,9 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testGetMessageMetadataAsDictionaryMap() throws Exception {
final Map<MessageId, BdfDictionary> map = new HashMap<>();
Map<MessageId, BdfDictionary> map = new HashMap<>();
map.put(messageId, dictionary);
final Transaction txn = new Transaction(null, true);
Transaction txn = new Transaction(null, true);
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
......@@ -187,13 +187,13 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testGetMessageMetadataAsDictionaryQuery() throws Exception {
final Map<MessageId, BdfDictionary> map = new HashMap<>();
Map<MessageId, BdfDictionary> map = new HashMap<>();
map.put(messageId, dictionary);
final BdfDictionary query =
BdfDictionary query =
BdfDictionary.of(new BdfEntry("query", "me"));
final Metadata queryMetadata = new Metadata();
Metadata queryMetadata = new Metadata();
queryMetadata.put("query", getRandomBytes(42));
final Transaction txn = new Transaction(null, true);
Transaction txn = new Transaction(null, true);
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
......@@ -215,7 +215,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testMergeGroupMetadata() throws Exception {
final Transaction txn = new Transaction(null, false);
Transaction txn = new Transaction(null, false);
context.checking(new Expectations() {{
oneOf(db).startTransaction(false);
......@@ -233,7 +233,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testMergeMessageMetadata() throws Exception {
final Transaction txn = new Transaction(null, false);
Transaction txn = new Transaction(null, false);
context.checking(new Expectations() {{
oneOf(db).startTransaction(false);
......@@ -280,10 +280,10 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testSign() throws Exception {
final byte[] privateKey = getRandomBytes(42);
final byte[] signed = getRandomBytes(42);
byte[] privateKey = getRandomBytes(42);
byte[] signed = getRandomBytes(42);
final byte[] bytes = expectToByteArray(list);
byte[] bytes = expectToByteArray(list);
context.checking(new Expectations() {{
oneOf(cryptoComponent).sign(label, bytes, privateKey);
will(returnValue(signed));
......@@ -295,8 +295,8 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testVerifySignature() throws Exception {
final byte[] publicKey = getRandomBytes(42);
final byte[] bytes = expectToByteArray(list);
byte[] publicKey = getRandomBytes(42);
byte[] bytes = expectToByteArray(list);
context.checking(new Expectations() {{
oneOf(cryptoComponent).verify(label, bytes, publicKey, rawMessage);
......@@ -309,8 +309,8 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test
public void testVerifyWrongSignature() throws Exception {
final byte[] publicKey = getRandomBytes(42);
final byte[] bytes = expectToByteArray(list);
byte[] publicKey = getRandomBytes(42);
byte[] bytes = expectToByteArray(list);
context.checking(new Expectations() {{
oneOf(cryptoComponent).verify(label, bytes, publicKey, rawMessage);
......@@ -327,8 +327,8 @@ public class ClientHelperImplTest extends BrambleTestCase {
}
}
private byte[] expectToByteArray(final BdfList list) throws Exception {
final BdfWriter bdfWriter = context.mock(BdfWriter.class);
private byte[] expectToByteArray(BdfList list) throws Exception {
BdfWriter bdfWriter = context.mock(BdfWriter.class);
context.checking(new Expectations() {{
oneOf(bdfWriterFactory)
......@@ -339,8 +339,8 @@ public class ClientHelperImplTest extends BrambleTestCase {
return new byte[0];
}
private void expectToList(final boolean eof) throws Exception {
final BdfReader bdfReader = context.mock(BdfReader.class);
private void expectToList(boolean eof) throws Exception {
BdfReader bdfReader = context.mock(BdfReader.class);
context.checking(new Expectations() {{
oneOf(bdfReaderFactory)
......
......@@ -46,10 +46,10 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test
public void testAddContact() throws Exception {
final SecretKey master = getSecretKey();
final long timestamp = 42;
final boolean alice = true;
final Transaction txn = new Transaction(null, false);
SecretKey master = getSecretKey();
long timestamp = 42;
boolean alice = true;
Transaction txn = new Transaction(null, false);
context.checking(new Expectations() {{
oneOf(db).startTransaction(false);
......@@ -64,14 +64,13 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
oneOf(db).endTransaction(txn);
}});
assertEquals(contactId, contactManager
.addContact(remote, local, master, timestamp, alice, verified,
active));
assertEquals(contactId, contactManager.addContact(remote, local,
master, timestamp, alice, verified, active));
}
@Test
public void testGetContact() throws Exception {
final Transaction txn = new Transaction(null, true);
Transaction txn = new Transaction(null, true);
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
will(returnValue(txn));
......@@ -86,8 +85,8 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test
public void testGetContactByAuthor() throws Exception {
final Transaction txn = new Transaction(null, true);
final Collection<Contact> contacts = Collections.singleton(contact);
Transaction txn = new Transaction(null, true);
Collection<Contact> contacts = Collections.singleton(contact);
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
will(returnValue(txn));
......@@ -102,7 +101,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test(expected = NoSuchContactException.class)
public void testGetContactByUnknownAuthor() throws Exception {
final Transaction txn = new Transaction(null, true);
Transaction txn = new Transaction(null, true);
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
will(returnValue(txn));
......@@ -116,8 +115,8 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test(expected = NoSuchContactException.class)
public void testGetContactByUnknownLocalAuthor() throws Exception {
final Transaction txn = new Transaction(null, true);
final Collection<Contact> contacts = Collections.singleton(contact);
Transaction txn = new Transaction(null, true);
Collection<Contact> contacts = Collections.singleton(contact);
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
will(returnValue(txn));
......@@ -132,9 +131,9 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test
public void testActiveContacts() throws Exception {
Collection<Contact> activeContacts = Collections.singletonList(contact);
final Collection<Contact> contacts = new ArrayList<>(activeContacts);
Collection<Contact> contacts = new ArrayList<>(activeContacts);
contacts.add(new Contact(new ContactId(3), remote, local, true, false));
final Transaction txn = new Transaction(null, true);