I need to draw a UML Activity diagram for a school java software engineering project I’m required to do. I’m quite new to this and I’m not sure what should be shown and what should not be shown. For this question, I’m interested to show the activity diagram from user input till before the statistics feature produces the GUI elements back to the user. The project uses the Command Pattern and these are the 2 most actively involved classes.
StatsCommandParser.java
/**
* Parses input arguments and creates a new StatsCommand object
*/
public class StatsCommandParser implements Parser<StatsCommand> {
public static final List<Prefix> REQUIRED_PREFIXES = Collections.unmodifiableList(List.of());
public static final List<Prefix> OPTIONAL_PREFIXES = Collections.unmodifiableList(List.of(
PREFIX_START_DATE, PREFIX_END_DATE));
/**
* Parses the given {@code String} of arguments in the context of the StatsCommand
* and returns an StatsCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public StatsCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_START_DATE, PREFIX_END_DATE);
if (!argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatsCommand.MESSAGE_USAGE));
}
if (argMultimap.hasRepeatedPrefixes(PREFIX_START_DATE, PREFIX_END_DATE)) {
throw new ParseException(MESSAGE_REPEATED_PREFIX_COMMAND);
}
StatsDescriptor statsDescriptor = new StatsDescriptor();
Timestamp startDate = null;
Timestamp endDate = null;
boolean isStartPresent = argMultimap.getValue(PREFIX_START_DATE).isPresent();
boolean isEndPresent = argMultimap.getValue(PREFIX_END_DATE).isPresent();
if (isStartPresent && isEndPresent) {
startDate = ParserUtil.parseTimestamp(argMultimap.getValue(PREFIX_START_DATE).get());
endDate = ParserUtil.parseTimestamp(argMultimap.getValue(PREFIX_END_DATE).get());
statsDescriptor.setStartDate(startDate);
statsDescriptor.setEndDate(endDate);
if (!statsDescriptor.isStartBeforeEnd()) {
throw new ParseException(Messages.MESSAGE_CONSTRAINTS_END_DATE);
}
} else if (isStartPresent) {
startDate = ParserUtil.parseTimestamp(argMultimap.getValue(PREFIX_START_DATE).get());
statsDescriptor.setStartDate(startDate);
} else if (isEndPresent) {
endDate = ParserUtil.parseTimestamp(argMultimap.getValue(PREFIX_END_DATE).get());
statsDescriptor.setEndDate(endDate);
}
return new StatsCommand(statsDescriptor);
}
}
StatsCommand.java
/**
* Represents a StatsCommand that is meant to output statistics using the visual
* representation of a pie chart
*/
public class StatsCommand extends Command {
public static final String COMMAND_WORD = "statsbasic" + CommandGroup.GENERAL;
public static final String MESSAGE_SUCCESS = "Pie Chart calculated!";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Calculates statistics between the Start Date and End Date "
+ "Parameters: "
+ "[" + PREFIX_START_DATE + "START_DATE] "
+ "[" + PREFIX_END_DATE + "END_DATE] "
+ "\nExample: " + COMMAND_WORD + " "
+ PREFIX_START_DATE + "11-11-1111 "
+ PREFIX_END_DATE + "12-12-1212 ";
private StatsDescriptor statsDescriptor;
/**
* Creates a StatsCommand to calculate statistics between 2 dates {@code Timestamp}
*/
public StatsCommand(StatsDescriptor statsDescriptor) {
requireNonNull(statsDescriptor);
this.statsDescriptor = statsDescriptor;
}
@Override
protected void validate(Model model) throws CommandException {
requireNonNull(model);
if (!model.hasPrimaryBudget()) {
throw new CommandException(MESSAGE_DISPLAY_STATISTICS_WITHOUT_BUDGET);
}
}
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
Budget primaryBudget = model.getPrimaryBudget();
Statistics statistics = createPieChartStatistics(primaryBudget, statsDescriptor);
model.setStatistics(statistics);
return new CommandResult(MESSAGE_SUCCESS, false, false, StatsPanel.PANEL_NAME);
}
@Override
public boolean equals(Object other) {
return other == this //short circuit if same object
|| (other instanceof StatsCommand // instance of handles nulls
&& statsDescriptor.equals(((StatsCommand) other).statsDescriptor));
}
/**
* Creates and returns a {@code Statistics} with the details of {@code statsDescriptor}
* and {@code primaryBudget} where necessary.
*/
private Statistics createPieChartStatistics(Budget primaryBudget, StatsDescriptor statsDescriptor) {
requireNonNull(primaryBudget);
Optional<Timestamp> startDate = statsDescriptor.getStartDate();
Optional<Timestamp> endDate = statsDescriptor.getEndDate();
boolean isStartPresent = startDate.isPresent();
boolean isEndPresent = endDate.isPresent();
if (!isStartPresent && !isEndPresent) {
startDate = Optional.of(primaryBudget.getWindowStartDate());
endDate = Optional.of(primaryBudget.getWindowEndDate());
} else if (isStartPresent && !isEndPresent) {
endDate = Optional.of(startDate.get().createForwardTimestamp(primaryBudget.getBudgetPeriod()).minusDays(1));
} else if (!isStartPresent) {
startDate = Optional.of(endDate.get().createBackwardTimestamp(primaryBudget.getBudgetPeriod()).plusDays(1));
}
PieChartStatistics statistics = new PieChartStatistics(primaryBudget.getExpenses(),
startDate.get(), endDate.get());
statistics.populateData();
return statistics;
}
}
Can anyone give me some feedback about my Activity Diagram? Do inform me if more information and files are required.