@@ -202,26 +202,6 @@ public static Transformer keyMap(Map<String, String> map) {
202202 };
203203 }
204204
205- /**
206- * Return a {@link Transformer} that replaces whitespace characters with an
207- * underscore in keys.
208- *
209- * @return the {@link Transformer}
210- */
211- public static Transformer keyWhitespaceToUnderscore () {
212- return keyReplaceChars (ImmutableMap .of (' ' , '_' ));
213- }
214-
215- /**
216- * Return a {@link Transformer} that removes all whitespace characters from
217- * a key.
218- *
219- * @return the {@link Transformer}
220- */
221- public static Transformer keyRemoveWhitespace () {
222- return keyRemoveInvalidChars (Character ::isWhitespace );
223- }
224-
225205 /**
226206 * Return a {@link Transformer} that removes all the character in the
227207 * {@code invalid} collection.
@@ -269,6 +249,16 @@ public static Transformer keyRemoveInvalidChars(
269249 };
270250 }
271251
252+ /**
253+ * Return a {@link Transformer} that removes all whitespace characters from
254+ * a key.
255+ *
256+ * @return the {@link Transformer}
257+ */
258+ public static Transformer keyRemoveWhitespace () {
259+ return keyRemoveInvalidChars (Character ::isWhitespace );
260+ }
261+
272262 /**
273263 * Return a {@link Transformer} that replaces all the character keys in the
274264 * {@code replacements} mapping with their associated character values in
@@ -366,6 +356,16 @@ public static Transformer keyValueStripQuotes() {
366356 return keyValueRemoveQuotes ();
367357 }
368358
359+ /**
360+ * Return a {@link Transformer} that replaces whitespace characters with an
361+ * underscore in keys.
362+ *
363+ * @return the {@link Transformer}
364+ */
365+ public static Transformer keyWhitespaceToUnderscore () {
366+ return keyReplaceChars (ImmutableMap .of (' ' , '_' ));
367+ }
368+
369369 /**
370370 * Return a {@link Transformer} that does not perform any key or value
371371 * transformations.
@@ -388,10 +388,6 @@ public static Transformer nullSafe(Transformer transformer) {
388388 : null ;
389389 }
390390
391- public static Transformer valueRemoveIfEmpty () {
392- return valueRemoveIf (Empty .ness ());
393- }
394-
395391 /**
396392 * Return a {@link Transformer} that will cause a key/value pair to be
397393 * "removed" if the value is described by the provided {@code adjective}.
@@ -408,21 +404,6 @@ public static Transformer removeValuesThatAre(Adjective adjective) {
408404 return valueRemoveIf (adjective );
409405 }
410406
411- /**
412- * Return a {@link Transformer} that will cause a key/value pair to be
413- * "removed" if the value is described by the provided {@code adjective}.
414- * <p>
415- * Removal is accomplished by returning an empty map for the transformation.
416- * </p>
417- *
418- * @param adjective
419- * @return the {@link Transformer}
420- */
421- public static Transformer valueRemoveIf (Adjective adjective ) {
422- return (key , value ) -> adjective .describes (value ) ? ImmutableMap .of ()
423- : null ;
424- }
425-
426407 /**
427408 * Return a {@link Transformer} that, For EVERY key, transform values to a
428409 * {@link Boolean} if possible. If the value cannot be transformed, an
@@ -564,6 +545,41 @@ public static Transformer valueAsResolvableLinkInstruction(String... keys) {
564545 }
565546 }
566547
548+ /**
549+ * Return a {@link Transformer} that, for EVERY key, transforms values to a
550+ * {@link String}.
551+ *
552+ * @return the {@link Transformer}
553+ */
554+ public static Transformer valueAsString () {
555+ return (key , value ) -> value instanceof String ? null
556+ : Transformation .to (key , value .toString ());
557+ }
558+
559+ /**
560+ * Return a {@link Transformer} that, for the specified {@code key}as,
561+ * transforms values to a {@link String}.
562+ *
563+ * @param keys
564+ * @return the {@link Transformer}
565+ */
566+ public static Transformer valueAsString (String ... keys ) {
567+ if (keys .length == 0 ) {
568+ return valueAsString ();
569+ }
570+ else {
571+ Set <String > _keys = Arrays .stream (keys ).collect (Collectors .toSet ());
572+ return (key , value ) -> {
573+ if (_keys .contains (key )) {
574+ return valueAsString ().transform (key , value );
575+ }
576+ else {
577+ return null ;
578+ }
579+ };
580+ }
581+ }
582+
567583 /**
568584 * Return a {@link Transformer} that, For EVERY key, transform values to a
569585 * {@link Number} if possible. If the value cannot be transformed, an
@@ -687,6 +703,25 @@ public static Transformer valueNullifyIfEmpty(Empty empty) {
687703 };
688704 }
689705
706+ /**
707+ * Return a {@link Transformer} that will cause a key/value pair to be
708+ * "removed" if the value is described by the provided {@code adjective}.
709+ * <p>
710+ * Removal is accomplished by returning an empty map for the transformation.
711+ * </p>
712+ *
713+ * @param adjective
714+ * @return the {@link Transformer}
715+ */
716+ public static Transformer valueRemoveIf (Adjective adjective ) {
717+ return (key , value ) -> adjective .describes (value ) ? ImmutableMap .of ()
718+ : null ;
719+ }
720+
721+ public static Transformer valueRemoveIfEmpty () {
722+ return valueRemoveIf (Empty .ness ());
723+ }
724+
690725 /**
691726 * Return a {@link Transformer} that splits a String value into multiple
692727 * strings that are all mapped from the original key.
0 commit comments