Remove unnecessary unmodifiable collection wrappers.

This commit is contained in:
akwizgran
2016-11-16 16:19:47 +00:00
parent 68abf8ba1a
commit f4c26d9cc7
16 changed files with 68 additions and 56 deletions

View File

@@ -31,7 +31,6 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static android.content.Context.MODE_PRIVATE;
@@ -63,7 +62,7 @@ public class AndroidUtils {
abis.add(Build.CPU_ABI);
if (Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
}
return Collections.unmodifiableList(abis);
return abis;
}
public static void setError(TextInputLayout til, String error,

View File

@@ -40,6 +40,7 @@ import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
@@ -578,7 +579,7 @@ class DroidtoothPlugin implements DuplexPlugin {
private static class DiscoveryReceiver extends BroadcastReceiver {
private final CountDownLatch finished = new CountDownLatch(1);
private final List<String> addresses = new ArrayList<>();
private final List<String> addresses = new CopyOnWriteArrayList<>();
@Override
public void onReceive(Context ctx, Intent intent) {
@@ -598,8 +599,9 @@ class DroidtoothPlugin implements DuplexPlugin {
private List<String> waitForAddresses() throws InterruptedException {
finished.await();
Collections.shuffle(addresses);
return Collections.unmodifiableList(addresses);
List<String> shuffled = new ArrayList<>(addresses);
Collections.shuffle(shuffled);
return shuffled;
}
}

View File

@@ -396,7 +396,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
blogs.add(b);
}
}
return Collections.unmodifiableList(blogs);
return blogs;
}
@Override
@@ -419,7 +419,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
} finally {
db.endTransaction(txn);
}
return Collections.unmodifiableList(blogs);
return blogs;
} catch (FormatException e) {
throw new DbException(e);
}

View File

@@ -29,7 +29,6 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -208,7 +207,7 @@ class ClientHelperImpl implements ClientHelper {
new HashMap<MessageId, BdfDictionary>(raw.size());
for (Entry<MessageId, Metadata> e : raw.entrySet())
parsed.put(e.getKey(), metadataParser.parse(e.getValue()));
return Collections.unmodifiableMap(parsed);
return parsed;
}
@Override
@@ -236,7 +235,7 @@ class ClientHelperImpl implements ClientHelper {
new HashMap<MessageId, BdfDictionary>(raw.size());
for (Entry<MessageId, Metadata> e : raw.entrySet())
parsed.put(e.getKey(), metadataParser.parse(e.getValue()));
return Collections.unmodifiableMap(parsed);
return parsed;
}
@Override

View File

@@ -103,7 +103,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
for (T root : roots) {
traverse(orderedList, root, 0);
}
return Collections.unmodifiableList(orderedList);
return orderedList;
}
}

View File

@@ -329,7 +329,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
if (ids.isEmpty()) return null;
db.lowerRequestedFlag(txn, c, ids);
transaction.attach(new MessagesSentEvent(c, ids));
return Collections.unmodifiableList(messages);
return messages;
}
@Nullable
@@ -379,7 +379,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
if (ids.isEmpty()) return null;
db.lowerRequestedFlag(txn, c, ids);
transaction.attach(new MessagesSentEvent(c, ids));
return Collections.unmodifiableList(messages);
return messages;
}
@Override

View File

@@ -199,7 +199,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
}
List<Forum> forums = new ArrayList<Forum>();
for (Group g : groups) forums.add(parseForum(g));
return Collections.unmodifiableList(forums);
return forums;
} catch (FormatException e) {
throw new DbException(e);
}

View File

@@ -42,6 +42,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
contactCounts = new HashMap<ContactId, Integer>();
}
@Override
public void registerConnection(ContactId c, TransportId t,
boolean incoming) {
if (LOG.isLoggable(INFO)) {
@@ -76,6 +77,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
}
}
@Override
public void unregisterConnection(ContactId c, TransportId t,
boolean incoming) {
if (LOG.isLoggable(INFO)) {
@@ -112,6 +114,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
}
}
@Override
public Collection<ContactId> getConnectedContacts(TransportId t) {
lock.lock();
try {
@@ -120,12 +123,13 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
List<ContactId> ids = new ArrayList<ContactId>(m.keySet());
if (LOG.isLoggable(INFO))
LOG.info(ids.size() + " contacts connected");
return Collections.unmodifiableList(ids);
return ids;
} finally {
lock.unlock();
}
}
@Override
public boolean isConnected(ContactId c, TransportId t) {
lock.lock();
try {
@@ -136,6 +140,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
}
}
@Override
public boolean isConnected(ContactId c) {
lock.lock();
try {

View File

@@ -156,12 +156,12 @@ class PluginManagerImpl implements PluginManager, Service {
@Override
public Collection<SimplexPlugin> getSimplexPlugins() {
return Collections.unmodifiableList(simplexPlugins);
return new ArrayList<SimplexPlugin>(simplexPlugins);
}
@Override
public Collection<DuplexPlugin> getDuplexPlugins() {
return Collections.unmodifiableList(duplexPlugins);
return new ArrayList<DuplexPlugin>(duplexPlugins);
}
@Override
@@ -169,7 +169,7 @@ class PluginManagerImpl implements PluginManager, Service {
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
for (DuplexPlugin d : duplexPlugins)
if (d.supportsInvitations()) supported.add(d);
return Collections.unmodifiableList(supported);
return supported;
}
@Override
@@ -177,7 +177,7 @@ class PluginManagerImpl implements PluginManager, Service {
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
for (DuplexPlugin d : duplexPlugins)
if (d.supportsKeyAgreement()) supported.add(d);
return Collections.unmodifiableList(supported);
return supported;
}
private class PluginStarter implements Runnable {

View File

@@ -22,7 +22,6 @@ import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
import org.briarproject.api.system.Clock;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -101,7 +100,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
} finally {
db.endTransaction(txn);
}
return Collections.unmodifiableMap(local);
return local;
}
@Override
@@ -176,7 +175,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
} finally {
db.endTransaction(txn);
}
return Collections.unmodifiableMap(remote);
return remote;
} catch (FormatException e) {
throw new DbException(e);
}

View File

@@ -46,7 +46,6 @@ import java.security.SecureRandom;
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;
@@ -443,7 +442,8 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
@Override
public Collection<SharingInvitationItem> getInvitations() throws DbException {
List<SharingInvitationItem> invitations = new ArrayList<SharingInvitationItem>();
List<SharingInvitationItem> invitations =
new ArrayList<SharingInvitationItem>();
Transaction txn = db.startTransaction(true);
try {
Set<S> shareables = new HashSet<S>();
@@ -474,7 +474,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
invitations.add(invitation);
}
db.commitTransaction(txn);
return Collections.unmodifiableCollection(invitations);
return invitations;
} catch (FormatException e) {
throw new DbException(e);
} finally {
@@ -523,7 +523,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
} finally {
db.endTransaction(txn);
}
return Collections.unmodifiableList(subscribers);
return subscribers;
}
private List<Contact> getSharedBy(Transaction txn, GroupId g)
@@ -556,7 +556,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
} finally {
db.endTransaction(txn);
}
return Collections.unmodifiableList(shared);
return shared;
} catch (FormatException e) {
throw new DbException(e);
}

View File

@@ -15,7 +15,6 @@ import org.briarproject.util.ByteUtils;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.briarproject.api.sync.PacketTypes.ACK;
@@ -74,19 +73,22 @@ class PacketReaderImpl implements PacketReader {
state = State.BUFFER_FULL;
}
@Override
public boolean eof() throws IOException {
if (state == State.BUFFER_EMPTY) readPacket();
if (state == State.BUFFER_EMPTY) throw new IllegalStateException();
return state == State.EOF;
}
@Override
public boolean hasAck() throws IOException {
return !eof() && header[1] == ACK;
}
@Override
public Ack readAck() throws IOException {
if (!hasAck()) throw new FormatException();
return new Ack(Collections.unmodifiableList(readMessageIds()));
return new Ack(readMessageIds());
}
private List<MessageId> readMessageIds() throws IOException {
@@ -102,10 +104,12 @@ class PacketReaderImpl implements PacketReader {
return ids;
}
@Override
public boolean hasMessage() throws IOException {
return !eof() && header[1] == MESSAGE;
}
@Override
public Message readMessage() throws IOException {
if (!hasMessage()) throw new FormatException();
if (payloadLength <= MESSAGE_HEADER_LENGTH) throw new FormatException();
@@ -125,21 +129,25 @@ class PacketReaderImpl implements PacketReader {
return new Message(messageId, groupId, timestamp, raw);
}
@Override
public boolean hasOffer() throws IOException {
return !eof() && header[1] == OFFER;
}
@Override
public Offer readOffer() throws IOException {
if (!hasOffer()) throw new FormatException();
return new Offer(Collections.unmodifiableList(readMessageIds()));
return new Offer(readMessageIds());
}
@Override
public boolean hasRequest() throws IOException {
return !eof() && header[1] == REQUEST;
}
@Override
public Request readRequest() throws IOException {
if (!hasRequest()) throw new FormatException();
return new Request(Collections.unmodifiableList(readMessageIds()));
return new Request(readMessageIds());
}
}

View File

@@ -1,19 +1,5 @@
package org.briarproject.lifecycle;
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
import static com.sun.jna.Library.OPTION_TYPE_MAPPER;
import static java.util.logging.Level.WARNING;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
import org.briarproject.util.OsUtils;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HINSTANCE;
@@ -28,6 +14,20 @@ import com.sun.jna.win32.StdCallLibrary.StdCallCallback;
import com.sun.jna.win32.W32APIFunctionMapper;
import com.sun.jna.win32.W32APITypeMapper;
import org.briarproject.util.OsUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
import static com.sun.jna.Library.OPTION_TYPE_MAPPER;
import static java.util.logging.Level.WARNING;
class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
private static final Logger LOG =
@@ -44,7 +44,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
WindowsShutdownManagerImpl() {
// Use the Unicode versions of Win32 API calls
Map<String, Object> m = new HashMap<String, Object>();
Map<String, Object> m = new HashMap<>();
m.put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
m.put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
options = Collections.unmodifiableMap(m);
@@ -112,6 +112,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
User32.class, options);
// Create a callback to handle the WM_QUERYENDSESSION message
WindowProc proc = new WindowProc() {
@Override
public LRESULT callback(HWND hwnd, int msg, WPARAM wp,
LPARAM lp) {
if (msg == WM_QUERYENDSESSION) {

View File

@@ -9,7 +9,6 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
@@ -114,7 +113,7 @@ implements RemovableDriveMonitor.Callback {
} catch (IOException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
}
return Collections.unmodifiableList(matches);
return matches;
}
@Override

View File

@@ -3,7 +3,6 @@ package org.briarproject.plugins.file;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
@@ -13,8 +12,9 @@ abstract class UnixRemovableDriveFinder implements RemovableDriveFinder {
protected abstract String parseMountPoint(String line);
protected abstract boolean isRemovableDriveMountPoint(String path);
@Override
public List<File> findRemovableDrives() throws IOException {
List<File> drives = new ArrayList<File>();
List<File> drives = new ArrayList<>();
Process p = new ProcessBuilder(getMountCommand()).start();
Scanner s = new Scanner(p.getInputStream(), "UTF-8");
try {
@@ -35,6 +35,6 @@ abstract class UnixRemovableDriveFinder implements RemovableDriveFinder {
} finally {
s.close();
}
return Collections.unmodifiableList(drives);
return drives;
}
}

View File

@@ -1,23 +1,23 @@
package org.briarproject.plugins.file;
import com.sun.jna.platform.win32.Kernel32;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import com.sun.jna.platform.win32.Kernel32;
class WindowsRemovableDriveFinder implements RemovableDriveFinder {
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa364939.aspx
private static final int DRIVE_REMOVABLE = 2;
@Override
public Collection<File> findRemovableDrives() throws IOException {
File[] roots = File.listRoots();
if (roots == null) throw new IOException();
List<File> drives = new ArrayList<File>();
List<File> drives = new ArrayList<>();
for (File root : roots) {
try {
int type = Kernel32.INSTANCE.GetDriveType(root.getPath());
@@ -26,6 +26,6 @@ class WindowsRemovableDriveFinder implements RemovableDriveFinder {
throw new IOException(e);
}
}
return Collections.unmodifiableList(drives);
return drives;
}
}