22
33import java .util .Timer ;
44import java .util .TimerTask ;
5+ import lombok .AllArgsConstructor ;
6+ import lombok .Getter ;
7+ import lombok .NoArgsConstructor ;
8+ import lombok .NonNull ;
9+ import lombok .Setter ;
510import org .apache .commons .cli .CommandLine ;
611import org .apache .commons .cli .GnuParser ;
712import org .apache .commons .cli .HelpFormatter ;
813import org .apache .commons .cli .Option ;
914import org .apache .commons .cli .Options ;
1015
1116/**
12- * The main class.
13- *
14- * This is the main class of the application. It contains the main()
15- * method, the first method called.
17+ * The main class of the application. It contains the main() method,
18+ * the first method called.
1619 */
20+ @ NoArgsConstructor
21+ @ AllArgsConstructor
1722public class SampleJavaProject extends TimerTask {
1823
1924 /** The delay between printed messages. */
2025 private static final long PRINT_DELAY = 1000L ;
2126
2227 /** The name to printed in the output message. */
23- private static String name = "world" ;
28+ @ Getter @ Setter @ NonNull
29+ private String name = "world" ;
2430
2531 /**
26- * The main class.
27- *
2832 * Print the "Hello, world!" string.
29- *
3033 * @param args application input arguments
3134 */
3235 public static void main (final String [] args ) {
@@ -44,37 +47,26 @@ public static void main(final String[] args) {
4447 }
4548
4649 /* Handle each argument. */
50+ SampleJavaProject sjp ;
4751 if (line .hasOption ("help" )) {
4852 HelpFormatter formatter = new HelpFormatter ();
4953 formatter .printHelp ("SampleJavaProject [options]" , options );
5054 System .exit (0 );
5155 }
5256 if (line .hasOption ("name" )) {
53- name = line .getOptionValue ("name" );
57+ sjp = new SampleJavaProject (line .getOptionValue ("name" ));
58+ } else {
59+ sjp = new SampleJavaProject ();
5460 }
5561 if (line .hasOption ("loop" )) {
56- new Timer ().schedule (new SampleJavaProject () , 0L , PRINT_DELAY );
62+ new Timer ().schedule (sjp , 0L , PRINT_DELAY );
5763 } else {
58- new SampleJavaProject () .run ();
64+ sjp .run ();
5965 }
6066 }
6167
6268 @ Override
6369 public final void run () {
6470 System .out .printf ("Hello, %s!\n " , name );
6571 }
66-
67- /**
68- * Add two integers together.
69- *
70- * This is a dumb method that is here for the purposed of unit
71- * testing.
72- *
73- * @param a first number
74- * @param b second number
75- * @return sum of the numbers
76- */
77- public final int add (final int a , final int b ) {
78- return a + b ;
79- }
8072}
0 commit comments