2
0

Resolve warnings and inspections.

This commit is contained in:
Maarten Billemont 2018-05-16 12:30:28 -04:00
parent c51262ccc2
commit 2db0bb35d5
17 changed files with 52 additions and 88 deletions

View File

@ -48,5 +48,5 @@ public interface MPQuestion extends Comparable<MPQuestion> {
// -- Relationship
@Nonnull
MPSite getSite();
MPSite<?> getSite();
}

View File

@ -27,7 +27,7 @@ import javax.annotation.Nullable;
/**
* @author lhunath, 2018-05-14
*/
public interface MPSite<Q extends MPQuestion> extends Comparable<MPSite<Q>> {
public interface MPSite<Q extends MPQuestion> extends Comparable<MPSite<?>> {
// - Meta

View File

@ -29,13 +29,13 @@ import org.jetbrains.annotations.NotNull;
*/
public class MPSiteResult implements Comparable<MPSiteResult> {
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;
}

View File

@ -27,7 +27,7 @@ import javax.annotation.Nullable;
/**
* @author lhunath, 2018-05-14
*/
public interface MPUser<S extends MPSite> extends Comparable<MPUser<?>> {
public interface MPUser<S extends MPSite<?>> extends Comparable<MPUser<?>> {
// - Meta

View File

@ -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<U extends MPUser<?>> {
usersByName.put( user.getFullName(), user );
}
public SortedSet<U> getUsers() {
return FluentIterable.from( usersByName.values() ).toSortedSet( Ordering.natural() );
public Collection<U> getUsers() {
return ImmutableList.copyOf( usersByName.values() );
}
public U getUserNamed(final String fullName) {

View File

@ -68,7 +68,7 @@ public abstract class MPBasicQuestion implements MPQuestion {
@Nonnull
@Override
public abstract MPBasicSite getSite();
public abstract MPBasicSite<?> getSite();
@Override
public int hashCode() {

View File

@ -164,7 +164,7 @@ public abstract class MPBasicSite<Q extends MPQuestion> implements MPSite<Q> {
}
@Override
public int compareTo(@NotNull final MPSite<Q> o) {
public int compareTo(@NotNull final MPSite<?> o) {
return getName().compareTo( o.getName() );
}

View File

@ -33,7 +33,7 @@ import javax.annotation.Nullable;
/**
* @author lhunath, 2014-06-08
*/
public abstract class MPBasicUser<S extends MPBasicSite> implements MPUser<S> {
public abstract class MPBasicUser<S extends MPBasicSite<?>> implements MPUser<S> {
private int avatar;
private final String fullName;

View File

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

View File

@ -96,15 +96,12 @@ public class MPFileUserManager extends MPUserManager<MPFileUser> {
}
private static ImmutableList<File> listUserFiles(final File userFilesDirectory) {
return ImmutableList.copyOf( ifNotNullElse( userFilesDirectory.listFiles( new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return ImmutableList.copyOf( ifNotNullElse( userFilesDirectory.listFiles( (dir, name) -> {
for (final MPMarshalFormat format : MPMarshalFormat.values())
if (name.endsWith( format.fileSuffix() ))
return true;
return false;
}
} ), new File[0] ) );
}
@ -124,7 +121,7 @@ public class MPFileUserManager extends MPUserManager<MPFileUser> {
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()

View File

@ -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.

View File

@ -25,6 +25,7 @@ import javax.annotation.Nonnull;
/**
* @author lhunath, 14-12-07
*/
@FunctionalInterface
public interface MPMarshaller {
@Nonnull

View File

@ -86,7 +86,7 @@ public final class Preferences {
}
public Set<String> getTestsPassed() {
return prefs().getStringSet( PREF_TESTS_PASSED, ImmutableSet.<String>of() );
return prefs().getStringSet( PREF_TESTS_PASSED, ImmutableSet.of() );
}
public boolean setRememberFullName(final boolean enabled) {

View File

@ -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<Boolean> testFuture;
@Nullable
private Runnable action;
private ImmutableSet<String> testNames;
private Set<String> 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) {
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<MPTests.Case, String>() {
@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() {
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() {
runOnUiThread( () -> {
logView.append( strf( "%n" + messageFormat, args ) );
progressView.setMax( max );
progressView.setProgress( current );
}
} );
}
}

View File

@ -189,15 +189,11 @@ public class ModelAuthenticationPanel extends AuthenticationPanel<MPFileUser> im
}
}, new JButton( Res.iconQuestion() ) {
{
addActionListener( new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
JOptionPane.showMessageDialog( ModelAuthenticationPanel.this, //
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 );
}
} );
"Help", JOptionPane.INFORMATION_MESSAGE ) );
setToolTipText( "More information." );
}
} );

View File

@ -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<U extends MPUser<S>, S extends MPBasicSite> extends JFrame implements DocumentListener {
public abstract class PasswordFrame<U extends MPUser<S>, S extends MPSite<?>> extends JFrame implements DocumentListener {
@SuppressWarnings("FieldCanBeLocal")
private final Components.GradientPanel root;

View File

@ -48,7 +48,7 @@ public class UnlockFrame extends JFrame {
private Future<?> identiconFuture;
private boolean incognito;
@Nullable
private MPUser<? extends MPSite> user;
private MPUser<? extends MPSite<?>> 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<? extends MPSite> user) {
void updateUser(@Nullable final MPUser<? extends MPSite<?>> user) {
this.user = user;
checkSignIn();
}