From 2db0bb35d5b57358d4da18f8dab626568bf75cf3 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Wed, 16 May 2018 12:30:28 -0400 Subject: [PATCH] Resolve warnings and inspections. --- .../masterpassword/model/MPQuestion.java | 2 +- .../lyndir/masterpassword/model/MPSite.java | 2 +- .../masterpassword/model/MPSiteResult.java | 6 +- .../lyndir/masterpassword/model/MPUser.java | 2 +- .../masterpassword/model/MPUserManager.java | 8 +-- .../model/impl/MPBasicQuestion.java | 2 +- .../model/impl/MPBasicSite.java | 2 +- .../model/impl/MPBasicUser.java | 2 +- .../masterpassword/model/impl/MPFileSite.java | 2 - .../model/impl/MPFileUserManager.java | 15 ++-- .../model/impl/MPFlatUnmarshaller.java | 3 +- .../model/impl/MPMarshaller.java | 1 + .../lyndir/masterpassword/Preferences.java | 2 +- .../lyndir/masterpassword/TestActivity.java | 70 ++++++------------- .../gui/view/ModelAuthenticationPanel.java | 14 ++-- .../gui/view/PasswordFrame.java | 3 +- .../masterpassword/gui/view/UnlockFrame.java | 4 +- 17 files changed, 52 insertions(+), 88 deletions(-) diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPQuestion.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPQuestion.java index 4f57ce9c..e0e6ef40 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPQuestion.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPQuestion.java @@ -48,5 +48,5 @@ public interface MPQuestion extends Comparable { // -- Relationship @Nonnull - MPSite getSite(); + MPSite getSite(); } diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSite.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSite.java index d11b5667..77498ad9 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSite.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSite.java @@ -27,7 +27,7 @@ import javax.annotation.Nullable; /** * @author lhunath, 2018-05-14 */ -public interface MPSite extends Comparable> { +public interface MPSite extends Comparable> { // - Meta diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSiteResult.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSiteResult.java index c5845e22..c4b98356 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSiteResult.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPSiteResult.java @@ -29,13 +29,13 @@ import org.jetbrains.annotations.NotNull; */ public class MPSiteResult implements Comparable { - private final MPSite site; + private final MPSite site; - public MPSiteResult(final MPSite site) { + public MPSiteResult(final MPSite site) { this.site = site; } - public MPSite getSite() { + public MPSite getSite() { return site; } diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPUser.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPUser.java index 63be260c..ca54cc08 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPUser.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPUser.java @@ -27,7 +27,7 @@ import javax.annotation.Nullable; /** * @author lhunath, 2018-05-14 */ -public interface MPUser extends Comparable> { +public interface MPUser> extends Comparable> { // - Meta diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPUserManager.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPUserManager.java index 308c1df1..5a790b10 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPUserManager.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPUserManager.java @@ -19,8 +19,8 @@ package com.lyndir.masterpassword.model; import com.google.common.collect.*; -import java.util.Map; -import java.util.SortedSet; +import java.util.*; +import java.util.stream.Collectors; /** @@ -35,8 +35,8 @@ public abstract class MPUserManager> { usersByName.put( user.getFullName(), user ); } - public SortedSet getUsers() { - return FluentIterable.from( usersByName.values() ).toSortedSet( Ordering.natural() ); + public Collection getUsers() { + return ImmutableList.copyOf( usersByName.values() ); } public U getUserNamed(final String fullName) { diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicQuestion.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicQuestion.java index 7f072ebd..4d91cb45 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicQuestion.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicQuestion.java @@ -68,7 +68,7 @@ public abstract class MPBasicQuestion implements MPQuestion { @Nonnull @Override - public abstract MPBasicSite getSite(); + public abstract MPBasicSite getSite(); @Override public int hashCode() { diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java index 288495a2..abb774a2 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java @@ -164,7 +164,7 @@ public abstract class MPBasicSite implements MPSite { } @Override - public int compareTo(@NotNull final MPSite o) { + public int compareTo(@NotNull final MPSite o) { return getName().compareTo( o.getName() ); } diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUser.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUser.java index f73aa33e..66949190 100755 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUser.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUser.java @@ -33,7 +33,7 @@ import javax.annotation.Nullable; /** * @author lhunath, 2014-06-08 */ -public abstract class MPBasicUser implements MPUser { +public abstract class MPBasicUser> implements MPUser { private int avatar; private final String fullName; diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileSite.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileSite.java index b833c410..b105f6a2 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileSite.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileSite.java @@ -20,8 +20,6 @@ package com.lyndir.masterpassword.model.impl; import com.google.common.primitives.UnsignedInteger; import com.lyndir.masterpassword.*; -import com.lyndir.masterpassword.model.MPSite; -import com.lyndir.masterpassword.model.MPUser; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.joda.time.Instant; diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserManager.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserManager.java index 4bc1073f..bcb06431 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserManager.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserManager.java @@ -96,15 +96,12 @@ public class MPFileUserManager extends MPUserManager { } private static ImmutableList listUserFiles(final File userFilesDirectory) { - return ImmutableList.copyOf( ifNotNullElse( userFilesDirectory.listFiles( new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - for (final MPMarshalFormat format : MPMarshalFormat.values()) - if (name.endsWith( format.fileSuffix() )) - return true; + return ImmutableList.copyOf( ifNotNullElse( userFilesDirectory.listFiles( (dir, name) -> { + for (final MPMarshalFormat format : MPMarshalFormat.values()) + if (name.endsWith( format.fileSuffix() )) + return true; - return false; - } + return false; } ), new File[0] ) ); } @@ -124,7 +121,7 @@ public class MPFileUserManager extends MPUserManager { public void save(final MPFileUser user, final MPMasterKey masterKey) throws MPKeyUnavailableException { try { - final MPMarshalFormat format = user.getFormat(); + MPMarshalFormat format = user.getFormat(); new CharSink() { @Override public Writer openStream() diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatUnmarshaller.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatUnmarshaller.java index f50cac07..0d513be6 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatUnmarshaller.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatUnmarshaller.java @@ -33,6 +33,7 @@ import java.util.regex.Pattern; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.joda.time.DateTime; +import org.joda.time.Instant; /** @@ -77,7 +78,7 @@ public class MPFlatUnmarshaller implements MPUnmarshaller { else // Ends the header. user = new MPFileUser( fullName, keyID, MPAlgorithm.Version.fromInt( mpVersion ).getAlgorithm(), - avatar, defaultType, new DateTime( 0 ), MPMarshalFormat.Flat, + avatar, defaultType, new Instant( 0 ), MPMarshalFormat.Flat, clearContent? MPMarshaller.ContentMode.VISIBLE: MPMarshaller.ContentMode.PROTECTED ); // Comment. diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPMarshaller.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPMarshaller.java index 7f6c84cc..8f881d67 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPMarshaller.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPMarshaller.java @@ -25,6 +25,7 @@ import javax.annotation.Nonnull; /** * @author lhunath, 14-12-07 */ +@FunctionalInterface public interface MPMarshaller { @Nonnull diff --git a/platform-android/src/main/java/com/lyndir/masterpassword/Preferences.java b/platform-android/src/main/java/com/lyndir/masterpassword/Preferences.java index 271513dc..c792cb98 100644 --- a/platform-android/src/main/java/com/lyndir/masterpassword/Preferences.java +++ b/platform-android/src/main/java/com/lyndir/masterpassword/Preferences.java @@ -86,7 +86,7 @@ public final class Preferences { } public Set getTestsPassed() { - return prefs().getStringSet( PREF_TESTS_PASSED, ImmutableSet.of() ); + return prefs().getStringSet( PREF_TESTS_PASSED, ImmutableSet.of() ); } public boolean setRememberFullName(final boolean enabled) { diff --git a/platform-android/src/main/java/com/lyndir/masterpassword/TestActivity.java b/platform-android/src/main/java/com/lyndir/masterpassword/TestActivity.java index c82dda30..8283441f 100644 --- a/platform-android/src/main/java/com/lyndir/masterpassword/TestActivity.java +++ b/platform-android/src/main/java/com/lyndir/masterpassword/TestActivity.java @@ -28,13 +28,12 @@ import android.view.View; import android.widget.*; import butterknife.BindView; import butterknife.ButterKnife; -import com.google.common.base.Function; -import com.google.common.base.Predicates; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.*; import com.lyndir.lhunath.opal.system.logging.Logger; +import java.util.Objects; +import java.util.Set; import java.util.concurrent.Executors; +import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -67,7 +66,7 @@ public class TestActivity extends Activity implements MPTestSuite.Listener { private ListenableFuture testFuture; @Nullable private Runnable action; - private ImmutableSet testNames; + private Set testNames; public static void startNoSkip(final Context context) { context.startActivity( new Intent( context, TestActivity.class ) ); @@ -80,35 +79,22 @@ public class TestActivity extends Activity implements MPTestSuite.Listener { setContentView( R.layout.activity_test ); ButterKnife.bind( this ); - nativeKDFField.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { - preferences.setNativeKDFEnabled( isChecked ); - // TODO: MasterKey.setAllowNativeByDefault( isChecked ); - } + nativeKDFField.setOnCheckedChangeListener( (buttonView, isChecked) -> { + preferences.setNativeKDFEnabled( isChecked ); + // TODO: MasterKey.setAllowNativeByDefault( isChecked ); } ); try { setStatus( 0, 0, null ); testSuite = new MPTestSuite(); testSuite.setListener( this ); - testNames = FluentIterable.from( testSuite.getTests().getCases() ).transform( - new Function() { - @Nullable - @Override - public String apply(@Nullable final MPTests.Case input) { - return (input == null)? null: input.identifier; - } - } ).filter( Predicates.notNull() ).toSet(); + testNames = testSuite.getTests().getCases().stream() + .map( input -> (input == null)? null: input.identifier ) + .filter( Objects::nonNull ).collect( Collectors.toSet() ); } catch (final MPTestSuite.UnavailableException e) { logger.err( e, "While loading test suite" ); - setStatus( R.string.tests_unavailable, R.string.tests_btn_unavailable, new Runnable() { - @Override - public void run() { - finish(); - } - } ); + setStatus( R.string.tests_unavailable, R.string.tests_btn_unavailable, this::finish ); } } @@ -133,31 +119,18 @@ public class TestActivity extends Activity implements MPTestSuite.Listener { @Override public void onSuccess(@Nullable final Boolean result) { if ((result != null) && result) - setStatus( R.string.tests_passed, R.string.tests_btn_passed, new Runnable() { - @Override - public void run() { - preferences.setTestsPassed( testNames ); - finish(); - } + setStatus( R.string.tests_passed, R.string.tests_btn_passed, () -> { + preferences.setTestsPassed( testNames ); + finish(); } ); else - setStatus( R.string.tests_failed, R.string.tests_btn_failed, new Runnable() { - @Override - public void run() { - startTestSuite(); - } - } ); + setStatus( R.string.tests_failed, R.string.tests_btn_failed, () -> startTestSuite() ); } @Override public void onFailure(final Throwable t) { logger.err( t, "While running test suite" ); - setStatus( R.string.tests_failed, R.string.tests_btn_failed, new Runnable() { - @Override - public void run() { - finish(); - } - } ); + setStatus( R.string.tests_failed, R.string.tests_btn_failed, () -> finish() ); } }, mainExecutor ); } @@ -184,14 +157,11 @@ public class TestActivity extends Activity implements MPTestSuite.Listener { @Override public void progress(final int current, final int max, final String messageFormat, final Object... args) { - runOnUiThread( new Runnable() { - @Override - public void run() { - logView.append( strf( "%n" + messageFormat, args ) ); + runOnUiThread( () -> { + logView.append( strf( "%n" + messageFormat, args ) ); - progressView.setMax( max ); - progressView.setProgress( current ); - } + progressView.setMax( max ); + progressView.setProgress( current ); } ); } } diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/ModelAuthenticationPanel.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/ModelAuthenticationPanel.java index 9ae2d4e1..7d1bc9ed 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/ModelAuthenticationPanel.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/ModelAuthenticationPanel.java @@ -189,15 +189,11 @@ public class ModelAuthenticationPanel extends AuthenticationPanel im } }, new JButton( Res.iconQuestion() ) { { - addActionListener( new ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - JOptionPane.showMessageDialog( ModelAuthenticationPanel.this, // - strf( "Reads users and sites from the directory at:%n%s", - MPFileUserManager.get().getPath().getAbsolutePath() ), // - "Help", JOptionPane.INFORMATION_MESSAGE ); - } - } ); + addActionListener( e -> JOptionPane.showMessageDialog( + ModelAuthenticationPanel.this, // + strf( "Reads users and sites from the directory at:%n%s", + MPFileUserManager.get().getPath().getAbsolutePath() ), // + "Help", JOptionPane.INFORMATION_MESSAGE ) ); setToolTipText( "More information." ); } } ); diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/PasswordFrame.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/PasswordFrame.java index f4aa5614..cd36c5b4 100755 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/PasswordFrame.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/PasswordFrame.java @@ -28,6 +28,7 @@ import com.lyndir.masterpassword.*; import com.lyndir.masterpassword.gui.Res; import com.lyndir.masterpassword.gui.util.Components; import com.lyndir.masterpassword.gui.util.UnsignedIntegerModel; +import com.lyndir.masterpassword.model.MPSite; import com.lyndir.masterpassword.model.MPUser; import com.lyndir.masterpassword.model.impl.*; import java.awt.*; @@ -46,7 +47,7 @@ import javax.swing.event.DocumentListener; /** * @author lhunath, 2014-06-08 */ -public abstract class PasswordFrame, S extends MPBasicSite> extends JFrame implements DocumentListener { +public abstract class PasswordFrame, S extends MPSite> extends JFrame implements DocumentListener { @SuppressWarnings("FieldCanBeLocal") private final Components.GradientPanel root; diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/UnlockFrame.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/UnlockFrame.java index ff9dbb69..f5a80aef 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/UnlockFrame.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/view/UnlockFrame.java @@ -48,7 +48,7 @@ public class UnlockFrame extends JFrame { private Future identiconFuture; private boolean incognito; @Nullable - private MPUser user; + private MPUser> user; public UnlockFrame(final SignInCallback signInCallback) { super( "Unlock Master Password" ); @@ -144,7 +144,7 @@ public class UnlockFrame extends JFrame { SwingUtilities.invokeLater( () -> ifNotNullElse( authenticationPanel.getFocusComponent(), signInButton ).requestFocusInWindow() ); } - void updateUser(@Nullable final MPUser user) { + void updateUser(@Nullable final MPUser> user) { this.user = user; checkSignIn(); }