me.gosimple.nbvcxz.resources.Feedback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nbvcxz Show documentation
Show all versions of nbvcxz Show documentation
Nbvcxz takes heavy inspiration from the zxcvbn library built by Dropbox, and in a lot of ways is
similar.
I built this library to be heavily extensible for every use case, with sane defaults.
package me.gosimple.nbvcxz.resources;
import me.gosimple.nbvcxz.scoring.Result;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author Adam Brusselback.
*/
public class Feedback
{
private final String result;
private final String warning;
private final List suggestions;
private final Configuration configuration;
/**
* @param configuration the {@link Configuration} object.
* @param result the primary message to display.
*/
public Feedback(final Configuration configuration, final String result)
{
this.configuration = configuration;
this.result = result;
this.warning = null;
this.suggestions = new ArrayList<>();
}
/**
* @param configuration the {@link Configuration} object.
* @param result the primary message to display.
* @param warning warning string
* @param suggestions suggestions
*/
public Feedback(final Configuration configuration, final String result, final String warning, final String... suggestions)
{
this.configuration = configuration;
this.result = result;
this.warning = warning;
this.suggestions = new ArrayList<>();
Collections.addAll(this.suggestions, suggestions);
}
/**
* @return if the password was secure enough or not (not null)
*/
public String getResult()
{
return result;
}
/**
* Get the raw untranslated warning key.
*
* @return the warning key (nullable)
*/
public String getWarningKey()
{
return warning;
}
/**
* @return the warning (nullable)
*/
public String getWarning()
{
try
{
return configuration.getFeedbackResource().getString(warning);
}
catch (Exception e)
{
return null;
}
}
/**
* Get the raw untranslated suggestion keys.
*
* @return list of suggestion keys (list is not null)
*/
public List getSuggestionKeys()
{
return suggestions;
}
/**
* @return list of suggestions (list is not null)
*/
public List getSuggestion()
{
List convertedSuggestions = new ArrayList<>();
for (String suggestion : suggestions)
{
convertedSuggestions.add(configuration.getFeedbackResource().getString(suggestion));
}
return convertedSuggestions;
}
}