Skip to content

Commit

Permalink
Style error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
blackpanther9229 committed Oct 24, 2024
1 parent ab792c4 commit e79eb84
Showing 1 changed file with 51 additions and 54 deletions.
105 changes: 51 additions & 54 deletions src/main/java/seedu/address/logic/parser/AddTagCommandParser.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
package seedu.address.logic.parser;
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.AddTagCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.tag.Tag;

/**
* Parses input arguments and creates a new AddTagCommand object
*/
public class AddTagCommandParser implements Parser<AddTagCommand> {
/**
* Parses the given {@code String} of arguments in the context of the AddTagCommand
* and returns an AddTagCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public AddTagCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_TAG);

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Index index;

try {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
} catch (ParseException pe) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTagCommand.MESSAGE_USAGE), pe);
}

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
AddTagCommand.AddTagDescriptor addTagDescriptor = new AddTagCommand.AddTagDescriptor();

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.AddTagCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.tag.Tag;
parseTagsToAdd(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(addTagDescriptor::setTags);

Check warning on line 41 in src/main/java/seedu/address/logic/parser/AddTagCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddTagCommandParser.java#L41

Added line #L41 was not covered by tests

return new AddTagCommand(index, addTagDescriptor);
}

/**
* Parses input arguments and creates a new AddTagCommand object
* Parses {@code Collection<String> tags} into a {@code Set<Tag>} if {@code tags} is non-empty.
* If {@code tags} contain only one element which is an empty string, it will be parsed into a
* {@code Set<Tag>} containing zero tags.
*/
public class AddTagCommandParser implements Parser<AddTagCommand> {
/**
* Parses the given {@code String} of arguments in the context of the AddTagCommand
* and returns an AddTagCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public AddTagCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_TAG);

Index index;

try {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
} catch (ParseException pe) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTagCommand.MESSAGE_USAGE), pe);
}

AddTagCommand.AddTagDescriptor addTagDescriptor = new AddTagCommand.AddTagDescriptor();

parseTagsToAdd(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(addTagDescriptor::setTags);

return new AddTagCommand(index, addTagDescriptor);
}
private Optional<Set<Tag>> parseTagsToAdd(Collection<String> tags) throws ParseException {
assert tags != null;

/**
* Parses {@code Collection<String> tags} into a {@code Set<Tag>} if {@code tags} is non-empty.
* If {@code tags} contain only one element which is an empty string, it will be parsed into a
* {@code Set<Tag>} containing zero tags.
*/
private Optional<Set<Tag>> parseTagsToAdd(Collection<String> tags) throws ParseException {
assert tags != null;

if (tags.isEmpty()) {
return Optional.empty();
}
Collection<String> tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags;
return Optional.of(ParserUtil.parseTags(tagSet));
if (tags.isEmpty()) {
return Optional.empty();
}
Collection<String> tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags;
return Optional.of(ParserUtil.parseTags(tagSet));
}
}

0 comments on commit e79eb84

Please sign in to comment.