Skip to content

Commit 1e2fab5

Browse files
author
Thidas Senavirathna
committed
Docs: Add Javadoc Comments to Public Methods in Command.java #9
1 parent e31dfbd commit 1e2fab5

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
package com.mycmd;
22

3+
/**
4+
* Represents a shell command that can be executed inside the MyCMD shell.
5+
* Implementations perform their operation when {@link #execute(String[], ShellContext)} is called.
6+
*/
37
public interface Command {
8+
/**
9+
* Execute the command.
10+
*
11+
* <p>Implementations should perform all output to standard output or use the provided
12+
* {@link ShellContext} for interactions that depend on the shell state (for example,
13+
* changing the current directory).</p>
14+
*
15+
* @param args command-line style arguments passed to the command. May be empty but
16+
* will not be null.
17+
* @param context current shell context containing state such as the current working
18+
* directory. Implementations may read and/or modify this context.
19+
* @throws Exception if the command cannot complete successfully. The caller (shell)
20+
* is responsible for catching and reporting exceptions.
21+
*
22+
* @implNote Common concrete commands include `date` and `time` which simply print the
23+
* current date/time to standard output. See their implementations for formatting details.
24+
*/
425
void execute(String[] args, ShellContext context);
526
}

src/main/java/com/mycmd/commands/DateCommand.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@
44
import com.mycmd.ShellContext;
55
import java.time.LocalDate;
66

7+
/**
8+
* Command that prints the current date to standard output.
9+
*
10+
* <p>This command does not use the provided {@link ShellContext} but keeps the
11+
* parameter to conform to the {@link Command} contract. The output is produced
12+
* using {@link LocalDate#now()} and printed in ISO-8601 format (yyyy-MM-dd).</p>
13+
*/
714
public class DateCommand implements Command {
15+
/**
16+
* Print the current date.
17+
*
18+
* @param args ignored for this command; may be empty or contain unused tokens.
19+
* @param context the current shell context; not used by this command.
20+
*/
821
@Override
922
public void execute(String[] args, ShellContext context) {
1023
System.out.println("The current date is: " + java.time.LocalDate.now());

src/main/java/com/mycmd/commands/TimeCommand.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,26 @@
55
import java.time.LocalTime;
66
import java.time.format.DateTimeFormatter;
77

8+
/**
9+
* Command that prints the current local time to standard output using a simple
10+
* custom formatter.
11+
*
12+
* <p>The time is formatted with the pattern "H.mm.ss.SS" where:
13+
* <ul>
14+
* <li>H - hour-of-day (0-23)</li>
15+
* <li>mm - minute-of-hour</li>
16+
* <li>ss - second-of-minute</li>
17+
* <li>SS - fraction-of-second (two digits)</li>
18+
* </ul>
19+
* Example output: "The current time is: 13.5.07.12"</p>
20+
*/
821
public class TimeCommand implements Command {
22+
/**
23+
* Print the current time.
24+
*
25+
* @param args ignored for this command; may be empty or contain unused tokens.
26+
* @param context the current shell context; not used by this command.
27+
*/
928
@Override
1029
public void execute(String[] args, ShellContext context) {
1130
LocalTime now = LocalTime.now();

0 commit comments

Comments
 (0)