Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenquotes.git

Add listing option

AuthorDave Jarvis <email>
Date2021-06-17 21:32:55 GMT-0700
Commit583ae16801daf02ab40442f371fde27048dc6b01
Parent5f3aa53
src/main/java/com/whitemagicsoftware/keenquotes/Contractions.java
package com.whitemagicsoftware.keenquotes;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
+import static java.lang.String.format;
import static java.util.Collections.emptySet;
+import static java.util.Collections.sort;
/**
private Set<String> getEndedAmbiguous() {
return mBuilder.mEndedAmbiguous;
+ }
+
+
+ @Override
+ public String toString() {
+ return
+ toString( getBeganAmbiguous(), "Ambiguous Began", "'%s" ) +
+ toString( getEndedAmbiguous(), "Ambiguous Ended", "%s'" ) +
+ toString( getBeganUnambiguous(), "Unambiguous Began", "'%s" ) +
+ toString( getEndedUnambiguous(), "Unambiguous Ended", "%s'" );
+ }
+
+ private String toString(
+ final Set<String> words, final String category, final String fmt ) {
+ final var sb = new StringBuilder( 16384 );
+ final var newline = System.lineSeparator();
+ final var list = new ArrayList<>( words );
+
+ sort( list );
+ sb.append( format( "%n%s%n", category ) );
+ list.forEach( ( s ) -> sb.append( format( fmt, s ) ).append( newline ) );
+
+ return sb.toString();
}
src/main/java/com/whitemagicsoftware/keenquotes/KeenQuotes.java
public void run() {
+ if( getSettings().displayList() ) {
+ displayList();
+ }
+ else {
+ convert();
+ }
+ }
+
+ private void displayList() {
+ System.out.println( new Contractions.Builder().build().toString() );
+ }
+
+ private void convert() {
final StringBuilder sb = new StringBuilder();
src/main/java/com/whitemagicsoftware/keenquotes/Settings.java
private final KeenQuotes mMain;
- /**
- * List of unambiguous contractions having leading apostrophes.
- */
- @CommandLine.Option(
- names = {"-ub", "--unamb-began"},
- description =
- "Contractions to treat as unambiguous (e.g., cause,bout)",
- paramLabel = "words"
- )
- private String[] mUnambiguousBegan;
-
- /**
- * List of unambiguous contractions having lagging apostrophes.
- */
- @CommandLine.Option(
- names = {"-ue", "--unamb-ended"},
- description =
- "Contractions to treat as unambiguous (e.g., frien,thinkin)",
- paramLabel = "words"
- )
- private String[] mUnambiguousEnded;
-
- /**
- * List of ambiguous contractions having leading apostrophes.
- */
- @CommandLine.Option(
- names = {"-ab", "--amb-began"},
- description =
- "Contractions to treat as ambiguous (e.g., sup,kay)",
- paramLabel = "words"
- )
- private String[] mAmbiguousBegan;
-
- /**
- * List of ambiguous contractions having lagging apostrophes.
- */
- @CommandLine.Option(
- names = {"-ae", "--amb-ended"},
- description =
- "Contractions to treat as ambiguous (e.g., gi,o)",
- paramLabel = "words"
- )
- private String[] mAmbiguousEnded;
-
+// /**
+// * List of unambiguous contractions having leading apostrophes.
+// */
+// @CommandLine.Option(
+// names = {"-ub", "--unamb-began"},
+// description =
+// "Contractions to treat as unambiguous (e.g., cause,bout)",
+// paramLabel = "words"
+// )
+// private String[] mUnambiguousBegan;
+//
+// /**
+// * List of unambiguous contractions having lagging apostrophes.
+// */
+// @CommandLine.Option(
+// names = {"-ue", "--unamb-ended"},
+// description =
+// "Contractions to treat as unambiguous (e.g., frien,thinkin)",
+// paramLabel = "words"
+// )
+// private String[] mUnambiguousEnded;
+//
+// /**
+// * List of ambiguous contractions having leading apostrophes.
+// */
+// @CommandLine.Option(
+// names = {"-ab", "--amb-began"},
+// description =
+// "Contractions to treat as ambiguous (e.g., sup,kay)",
+// paramLabel = "words"
+// )
+// private String[] mAmbiguousBegan;
+//
+// /**
+// * List of ambiguous contractions having lagging apostrophes.
+// */
+// @CommandLine.Option(
+// names = {"-ae", "--amb-ended"},
+// description =
+// "Contractions to treat as ambiguous (e.g., gi,o)",
+// paramLabel = "words"
+// )
+// private String[] mAmbiguousEnded;
+//
/**
* Display default values.
assert main != null;
mMain = main;
+ }
+
+ /**
+ * Answers whether the contractions listings should be displayed.
+ *
+ * @return {@code true} to list the contractions.
+ */
+ public boolean displayList() {
+ return mDisplayList;
}
Delta92 lines added, 44 lines removed, 48-line increase