Skip to content

Commit

Permalink
more ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 24, 2024
1 parent c9a2ccc commit 58e4a61
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/org/takes/facets/auth/PsBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.net.HttpURLConnection;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
Expand Down Expand Up @@ -224,6 +225,14 @@ public static final class Default implements PsBasic.Entry {
*/
private final Map<String, String> usernames;

/**
* Public ctor.
* @param users Strings with user's login, password and URNs
*/
public Default(final Iterable<String> users) {
this.usernames = Default.converted(users);
}

/**
* Public ctor.
* @param users Strings with user's login, password and URN with
Expand All @@ -232,7 +241,7 @@ public static final class Default implements PsBasic.Entry {
* {@code "mike my%20password urn:jcabi-users:michael"}.
*/
public Default(final String... users) {
this.usernames = Default.converted(users);
this(Arrays.asList(users));
}

@Override
Expand Down Expand Up @@ -268,8 +277,8 @@ public Opt<Identity> enter(final String user, final String pwd) {
* {@code "mike my%20password urn:jcabi-users:michael"}.
* @return Map from login/password pairs to URNs.
*/
private static Map<String, String> converted(final String... users) {
final Map<String, String> result = new HashMap<>(users.length);
private static Map<String, String> converted(final Iterable<String> users) {
final Map<String, String> result = new HashMap<>(0);
for (final String user : users) {
final String unified = user.replace("%20", "+");
PsBasic.Default.validateUser(unified);
Expand Down

0 comments on commit 58e4a61

Please sign in to comment.