From 1b703515dd8a12ddc56c3d34732626dfaf55a688 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Wed, 16 May 2018 00:16:06 -0400 Subject: [PATCH] Refactor code. --- .../MPIncorrectMasterPasswordException.java | 1 - .../masterpassword/model/MPUserManager.java | 1 - .../model/impl/MPBasicQuestion.java | 3 +- .../model/impl/MPFileQuestion.java | 4 +- .../model/impl/MPFileUserManager.java | 3 +- .../model/impl/MPFlatMarshaller.java | 2 +- .../model/impl/MPFlatUnmarshaller.java | 6 +- .../masterpassword/model/impl/MPJSONFile.java | 6 +- .../model/impl/MPJSONMarshaller.java | 2 +- .../model/impl/MPJSONUnmarshaller.java | 2 +- .../src/main/resources/test.mpsites.json | 132 +++++++++--------- .../masterpassword/EmergencyActivity.java | 4 +- .../lyndir/masterpassword/Preferences.java | 6 +- .../gui/model/MPIncognitoUser.java | 2 +- .../gui/view/ModelAuthenticationPanel.java | 3 +- 15 files changed, 89 insertions(+), 88 deletions(-) diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPIncorrectMasterPasswordException.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPIncorrectMasterPasswordException.java index ab1497b8..dd5a52c6 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPIncorrectMasterPasswordException.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/MPIncorrectMasterPasswordException.java @@ -18,7 +18,6 @@ package com.lyndir.masterpassword.model; - /** * @author lhunath, 14-12-17 */ 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 1590161a..308c1df1 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,7 +19,6 @@ package com.lyndir.masterpassword.model; import com.google.common.collect.*; -import com.lyndir.masterpassword.model.impl.MPFileUser; import java.util.Map; import java.util.SortedSet; 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 a4c7780b..7f072ebd 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 @@ -18,7 +18,7 @@ package com.lyndir.masterpassword.model.impl; -import static com.lyndir.lhunath.opal.system.util.StringUtils.strf; +import static com.lyndir.lhunath.opal.system.util.StringUtils.*; import com.lyndir.masterpassword.*; import com.lyndir.masterpassword.model.MPQuestion; @@ -70,7 +70,6 @@ public abstract class MPBasicQuestion implements MPQuestion { @Override public abstract MPBasicSite getSite(); - @Override public int hashCode() { return Objects.hashCode( getKeyword() ); diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileQuestion.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileQuestion.java index 8e2da324..8a874eff 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileQuestion.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileQuestion.java @@ -18,7 +18,7 @@ package com.lyndir.masterpassword.model.impl; -import static com.lyndir.lhunath.opal.system.util.ObjectUtils.ifNotNullElse; +import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*; import com.lyndir.masterpassword.*; import javax.annotation.Nonnull; @@ -33,7 +33,7 @@ public class MPFileQuestion extends MPBasicQuestion { private final MPFileSite site; @Nullable - private String state; + private String state; public MPFileQuestion(final MPFileSite site, final String keyword, @Nullable final MPResultType type, @Nullable final String state) { 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 52a2539a..4bc1073f 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 @@ -24,7 +24,8 @@ import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import com.google.common.io.CharSink; import com.lyndir.lhunath.opal.system.logging.Logger; -import com.lyndir.masterpassword.*; +import com.lyndir.masterpassword.MPKeyUnavailableException; +import com.lyndir.masterpassword.MPMasterKey; import com.lyndir.masterpassword.model.*; import java.io.*; import java.util.HashMap; diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatMarshaller.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatMarshaller.java index 3b648441..171bed0f 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatMarshaller.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatMarshaller.java @@ -21,7 +21,7 @@ package com.lyndir.masterpassword.model.impl; import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*; import static com.lyndir.lhunath.opal.system.util.StringUtils.*; -import com.lyndir.masterpassword.*; +import com.lyndir.masterpassword.MPKeyUnavailableException; import com.lyndir.masterpassword.model.MPConstant; import javax.annotation.Nonnull; import org.joda.time.Instant; 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 59314a10..f50cac07 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 @@ -78,7 +78,7 @@ public class MPFlatUnmarshaller implements MPUnmarshaller { // Ends the header. user = new MPFileUser( fullName, keyID, MPAlgorithm.Version.fromInt( mpVersion ).getAlgorithm(), avatar, defaultType, new DateTime( 0 ), MPMarshalFormat.Flat, - clearContent? MPMarshaller.ContentMode.VISIBLE : MPMarshaller.ContentMode.PROTECTED ); + clearContent? MPMarshaller.ContentMode.VISIBLE: MPMarshaller.ContentMode.PROTECTED ); // Comment. else if (line.startsWith( "#" )) { @@ -118,7 +118,7 @@ public class MPFlatUnmarshaller implements MPUnmarshaller { case 0: site = new MPFileSite( user, // siteMatcher.group( 5 ), MPAlgorithm.Version.fromInt( ConversionUtils.toIntegerNN( - colon.matcher( siteMatcher.group( 4 ) ).replaceAll( "" ) ) ).getAlgorithm(), + colon.matcher( siteMatcher.group( 4 ) ).replaceAll( "" ) ) ).getAlgorithm(), user.getAlgorithm().mpw_default_counter(), MPResultType.forType( ConversionUtils.toIntegerNN( siteMatcher.group( 3 ) ) ), clearContent? null: siteMatcher.group( 6 ), @@ -131,7 +131,7 @@ public class MPFlatUnmarshaller implements MPUnmarshaller { case 1: site = new MPFileSite( user, // siteMatcher.group( 7 ), MPAlgorithm.Version.fromInt( ConversionUtils.toIntegerNN( - colon.matcher( siteMatcher.group( 4 ) ).replaceAll( "" ) ) ).getAlgorithm(), + colon.matcher( siteMatcher.group( 4 ) ).replaceAll( "" ) ) ).getAlgorithm(), UnsignedInteger.valueOf( colon.matcher( siteMatcher.group( 5 ) ).replaceAll( "" ) ), MPResultType.forType( ConversionUtils.toIntegerNN( siteMatcher.group( 3 ) ) ), clearContent? null: siteMatcher.group( 8 ), diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java index 39eade62..00846456 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java @@ -21,13 +21,14 @@ package com.lyndir.masterpassword.model.impl; import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*; import com.fasterxml.jackson.annotation.*; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.primitives.UnsignedInteger; import com.lyndir.lhunath.opal.system.CodeUtils; import com.lyndir.masterpassword.*; import com.lyndir.masterpassword.model.MPConstant; import com.lyndir.masterpassword.model.MPIncorrectMasterPasswordException; -import java.util.*; +import java.util.LinkedHashMap; +import java.util.Map; import javax.annotation.Nullable; import org.joda.time.Instant; @@ -220,6 +221,7 @@ public class MPJSONFile extends MPJSONAnyObject { @Nullable Ext _ext_mpw; + public static class Ext extends MPJSONAnyObject { @Nullable diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONMarshaller.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONMarshaller.java index de8dee2b..35d1af93 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONMarshaller.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONMarshaller.java @@ -18,7 +18,7 @@ package com.lyndir.masterpassword.model.impl; -import static com.lyndir.masterpassword.model.impl.MPJSONFile.objectMapper; +import static com.lyndir.masterpassword.model.impl.MPJSONFile.*; import com.fasterxml.jackson.core.JsonProcessingException; import com.lyndir.masterpassword.MPKeyUnavailableException; diff --git a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONUnmarshaller.java b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONUnmarshaller.java index 6e31d06a..d38c7e75 100644 --- a/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONUnmarshaller.java +++ b/core/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONUnmarshaller.java @@ -18,7 +18,7 @@ package com.lyndir.masterpassword.model.impl; -import static com.lyndir.masterpassword.model.impl.MPJSONFile.objectMapper; +import static com.lyndir.masterpassword.model.impl.MPJSONFile.*; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; diff --git a/core/java/tests/src/main/resources/test.mpsites.json b/core/java/tests/src/main/resources/test.mpsites.json index edaa668d..dba1adf8 100644 --- a/core/java/tests/src/main/resources/test.mpsites.json +++ b/core/java/tests/src/main/resources/test.mpsites.json @@ -1,67 +1,67 @@ { - "export": { - "format": 1, - "redacted": true, - "date": "2018-05-10T03:41:18Z", - "_ext_mpw": { - "save": "me" - }, - "_ext_other": { - "save": "me" - } - }, - "user": { - "avatar": 3, - "full_name": "Robert Lee Mitchell", - "last_used": "2018-05-10T03:41:18Z", - "key_id": "98EEF4D1DF46D849574A82A03C3177056B15DFFCA29BB3899DE4628453675302", - "algorithm": 3, - "default_type": 17, - "_ext_mpw": { - "save": "me" - }, - "_ext_other": { - "save": "me" - } - }, - "sites": { - "masterpasswordapp.com": { - "type": 17, - "counter": 1, - "algorithm": 3, - "login_type": 30, - "uses": 2, - "last_used": "2018-05-10T03:41:18Z", - "questions": { - "": { - "type": 31 - }, - "mother": { - "type": 31 - } - }, - "_ext_mpw": { - "url": "https://masterpasswordapp.com", - "save": "me" - }, - "_ext_other": { - "save": "me" - } - }, - "personal.site": { - "type": 1056, - "counter": 1, - "algorithm": 3, - "password": "ZTgr4cY6L28wG7DsO+iz\/hrTQxM3UHz0x8ZU99LjgxjHG+bLIJygkbg\/7HdjEIFH6A3z+Dt2H1gpt9yPyQGZcewTiPXJX0pNpVsIKAAdzVNcUfYoqkWjoFRoZD7sM\/ctxWDH4JUuJ+rjoBkWtRLK9kYBvu7UD1QdlEZI\/wPKv1A=", - "login_type": 30, - "uses": 1, - "last_used": "2018-05-10T03:48:35Z" - } - }, - "_ext_mpw": { - "save": "me" - }, - "_ext_other": { - "save": "me" - } - } + "export": { + "format": 1, + "redacted": true, + "date": "2018-05-10T03:41:18Z", + "_ext_mpw": { + "save": "me" + }, + "_ext_other": { + "save": "me" + } + }, + "user": { + "avatar": 3, + "full_name": "Robert Lee Mitchell", + "last_used": "2018-05-10T03:41:18Z", + "key_id": "98EEF4D1DF46D849574A82A03C3177056B15DFFCA29BB3899DE4628453675302", + "algorithm": 3, + "default_type": 17, + "_ext_mpw": { + "save": "me" + }, + "_ext_other": { + "save": "me" + } + }, + "sites": { + "masterpasswordapp.com": { + "type": 17, + "counter": 1, + "algorithm": 3, + "login_type": 30, + "uses": 2, + "last_used": "2018-05-10T03:41:18Z", + "questions": { + "": { + "type": 31 + }, + "mother": { + "type": 31 + } + }, + "_ext_mpw": { + "url": "https://masterpasswordapp.com", + "save": "me" + }, + "_ext_other": { + "save": "me" + } + }, + "personal.site": { + "type": 1056, + "counter": 1, + "algorithm": 3, + "password": "ZTgr4cY6L28wG7DsO+iz\/hrTQxM3UHz0x8ZU99LjgxjHG+bLIJygkbg\/7HdjEIFH6A3z+Dt2H1gpt9yPyQGZcewTiPXJX0pNpVsIKAAdzVNcUfYoqkWjoFRoZD7sM\/ctxWDH4JUuJ+rjoBkWtRLK9kYBvu7UD1QdlEZI\/wPKv1A=", + "login_type": 30, + "uses": 1, + "last_used": "2018-05-10T03:48:35Z" + } + }, + "_ext_mpw": { + "save": "me" + }, + "_ext_other": { + "save": "me" + } +} diff --git a/platform-android/src/main/java/com/lyndir/masterpassword/EmergencyActivity.java b/platform-android/src/main/java/com/lyndir/masterpassword/EmergencyActivity.java index 81a5dcb1..d88f5f09 100644 --- a/platform-android/src/main/java/com/lyndir/masterpassword/EmergencyActivity.java +++ b/platform-android/src/main/java/com/lyndir/masterpassword/EmergencyActivity.java @@ -306,8 +306,8 @@ public class EmergencyActivity extends Activity { @Override public void run() { try { - sitePassword = masterKey.siteResult( siteName, version.getAlgorithm(), counter, MPKeyPurpose.Authentication, null, type, null - ); + sitePassword = masterKey.siteResult( siteName, version.getAlgorithm(), counter, + MPKeyPurpose.Authentication, null, type, null ); runOnUiThread( new Runnable() { @Override 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 cae9e7ba..271513dc 100644 --- a/platform-android/src/main/java/com/lyndir/masterpassword/Preferences.java +++ b/platform-android/src/main/java/com/lyndir/masterpassword/Preferences.java @@ -148,7 +148,8 @@ public final class Preferences { @Nonnull public MPResultType getDefaultResultType() { - return MPResultType.values()[prefs().getInt( PREF_RESULT_TYPE, getDefaultVersion().getAlgorithm().mpw_default_result_type().ordinal() )]; + return MPResultType.values()[ + prefs().getInt( PREF_RESULT_TYPE, getDefaultVersion().getAlgorithm().mpw_default_result_type().ordinal() )]; } public boolean setDefaultVersion(final MPAlgorithm.Version value) { @@ -161,6 +162,7 @@ public final class Preferences { @Nonnull public MPAlgorithm.Version getDefaultVersion() { - return MPAlgorithm.Version.values()[prefs().getInt( PREF_ALGORITHM_VERSION, MPAlgorithm.Version.CURRENT.ordinal() )]; + return MPAlgorithm.Version.values()[ + prefs().getInt( PREF_ALGORITHM_VERSION, MPAlgorithm.Version.CURRENT.ordinal() )]; } } diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoUser.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoUser.java index 63e490bf..80e929e4 100755 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoUser.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/model/MPIncognitoUser.java @@ -29,7 +29,7 @@ import javax.annotation.Nullable; public class MPIncognitoUser extends MPBasicUser { public MPIncognitoUser(final String fullName) { - super( fullName, MPAlgorithm.Version.CURRENT.getAlgorithm()); + super( fullName, MPAlgorithm.Version.CURRENT.getAlgorithm() ); } @Nullable 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 5f88ea39..9ae2d4e1 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 @@ -28,9 +28,8 @@ import com.lyndir.masterpassword.MPAlgorithm; import com.lyndir.masterpassword.MPResultType; import com.lyndir.masterpassword.gui.Res; import com.lyndir.masterpassword.gui.util.Components; -import com.lyndir.masterpassword.model.*; +import com.lyndir.masterpassword.model.MPUser; import com.lyndir.masterpassword.model.impl.*; -import com.lyndir.masterpassword.model.impl.MPFileSite; import java.awt.*; import java.awt.event.*; import javax.annotation.Nonnull;