Collections initial size

This commit is contained in:
Emmanuel Bigeon 2018-10-11 12:08:59 -04:00
parent f8da1c0119
commit 98d22782c1
2 changed files with 7 additions and 4 deletions

View File

@ -43,6 +43,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.bigeon.gclc.exception.CommandParsingException;
@ -55,9 +56,9 @@ public final class CommandParameters {
/** Number of element for a string argument. */
private static final int STRINGARG_NUMBER_OF_ELEMENTS = 2;
/** Boolean arguments. */
private final Map<String, Boolean> booleanArguments = new HashMap<>();
private final Map<String, Boolean> booleanArguments;
/** String arguments. */
private final Map<String, String> stringArguments = new HashMap<>();
private final Map<String, String> stringArguments;
/** Arguments restriction on the named ones. */
private final boolean strict;
/** additional (unnamed) parameters. */
@ -70,9 +71,11 @@ public final class CommandParameters {
* @param strict if the argument are restricted to the declared ones */
public CommandParameters(final Set<String> bools, final Set<String> strings,
final boolean strict) {
booleanArguments = new ConcurrentHashMap<>(bools.size());
for (final String string : bools) {
booleanArguments.put(string, Boolean.FALSE);
}
stringArguments = new ConcurrentHashMap<>(strings.size());
for (final String string : strings) {
stringArguments.put(string, null);
}

View File

@ -432,7 +432,7 @@ public final class CLIPrompter {
final String message) throws IOException {
final List<Integer> indices = promptMultiChoice(manager, input, keys,
message);
final List<U> userChoices = new ArrayList<>();
final List<U> userChoices = new ArrayList<>(indices.size());
for (final Integer integer : indices) {
userChoices.add(choices.get(integer.intValue()));
}
@ -457,7 +457,7 @@ public final class CLIPrompter {
final String message) throws IOException {
final List<Integer> chs = promptMultiChoice(manager, input, choices,
message);
final List<T> userChoices = new ArrayList<>();
final List<T> userChoices = new ArrayList<>(chs.size());
for (final Integer integer : chs) {
userChoices.add(choicesMap.get(choices.get(integer.intValue())));
}