1313
1414public class Options
1515{
16- private final Map <String , Object > fields = new HashMap <>();
16+ private enum Fields {
17+ SCRUBBER , REPORTER , FILE_OPTIONS_FILE_EXTENSION , FILE_OPTIONS_NAMER ;
18+ }
19+ private final Map <Fields , Object > fields = new HashMap <>();
1720 public Options ()
1821 {
1922 }
2023 public Options (Scrubber scrubber )
2124 {
22- fields .put ("scrubber" , scrubber );
25+ fields .put (Fields . SCRUBBER , scrubber );
2326 }
2427 public Options (ApprovalFailureReporter reporter )
2528 {
26- fields .put ("reporter" , reporter );
29+ fields .put (Fields . REPORTER , reporter );
2730 }
28- private Options (Map <String , Object > fields , String key , Object value )
31+ private Options (Map <Fields , Object > fields , Fields key , Object value )
2932 {
3033 this .fields .putAll (fields );
3134 this .fields .put (key , value );
3235 }
33- public Options (Options parent , FileOptions fileOptions )
34- {
35- this (parent .fields , "fileOptions" , fileOptions );
36- }
3736 public ApprovalFailureReporter getReporter ()
3837 {
39- return ArrayUtils .getOrElse (fields , "reporter" , ReporterFactory ::get );
38+ return ArrayUtils .getOrElse (fields , Fields . REPORTER , ReporterFactory ::get );
4039 }
4140 public Options withReporter (ApprovalFailureReporter reporter )
4241 {
43- return new Options (fields , "reporter" , reporter );
42+ return new Options (fields , Fields . REPORTER , reporter );
4443 }
4544 public Options withScrubber (Scrubber scrubber )
4645 {
47- return new Options (fields , "scrubber" , scrubber );
46+ return new Options (fields , Fields . SCRUBBER , scrubber );
4847 }
4948 public String scrub (String input )
5049 {
5150 return getScrubber ().scrub (input );
5251 }
5352 private Scrubber getScrubber ()
5453 {
55- return ArrayUtils .getOrElse (fields , "scrubber" , () -> NoOpScrubber .INSTANCE );
54+ return ArrayUtils .getOrElse (fields , Fields . SCRUBBER , () -> NoOpScrubber .INSTANCE );
5655 }
5756 public FileOptions forFile ()
5857 {
5958 return new FileOptions (this .fields );
6059 }
6160 public static class FileOptions
6261 {
63- private final Map <String , Object > fields ;
64- public FileOptions (Map <String , Object > fields )
62+ private final Map <Fields , Object > fields ;
63+ public FileOptions (Map <Fields , Object > fields )
6564 {
6665 this .fields = fields ;
6766 }
@@ -71,27 +70,27 @@ public Options withExtension(String fileExtensionWithDot)
7170 {
7271 fileExtensionWithDot = "." + fileExtensionWithDot ;
7372 }
74- return new Options (fields , "fileOptions.fileExtension" , fileExtensionWithDot );
73+ return new Options (fields , Fields . FILE_OPTIONS_FILE_EXTENSION , fileExtensionWithDot );
7574 }
7675 public ApprovalNamer getNamer ()
7776 {
78- return ArrayUtils .getOrElse (fields , "fileOptions.namer" , Approvals ::createApprovalNamer );
77+ return ArrayUtils .getOrElse (fields , Fields . FILE_OPTIONS_NAMER , Approvals ::createApprovalNamer );
7978 }
8079 public String getFileExtension ()
8180 {
82- return ArrayUtils .getOrElse (fields , "fileOptions.fileExtension" , () -> ".txt" );
81+ return ArrayUtils .getOrElse (fields , Fields . FILE_OPTIONS_FILE_EXTENSION , () -> ".txt" );
8382 }
8483 public Options withBaseName (String fileBaseName )
8584 {
8685 NamerWrapper approvalNamer = new NamerWrapper (() -> fileBaseName , getNamer ());
87- return new Options (fields , "fileOptions.namer" , approvalNamer );
86+ return new Options (fields , Fields . FILE_OPTIONS_NAMER , approvalNamer );
8887 }
8988 public Options withName (String fileBaseName , String extension )
9089 {
9190 NamerWrapper approvalNamer = new NamerWrapper (() -> fileBaseName , getNamer ());
92- HashMap <String , Object > newFields = new HashMap <>(fields );
93- newFields .put ("fileOptions.fileExtension" , extension );
94- return new Options (newFields , "fileOptions.namer" , approvalNamer );
91+ HashMap <Fields , Object > newFields = new HashMap <>(fields );
92+ newFields .put (Fields . FILE_OPTIONS_FILE_EXTENSION , extension );
93+ return new Options (newFields , Fields . FILE_OPTIONS_NAMER , approvalNamer );
9594 }
9695 }
9796}
0 commit comments