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

@@ -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;
}
}