Skip to content

Commit 46160c2

Browse files
committed
renamed the keyMap transformer to keyRename for better clarity
1 parent 81f32b1 commit 46160c2

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
#### Version 1.5.0 (TBD)
4+
* Deprecated `Transformers#keyMap` in favor of `Transformers#keyRename` because the latter is a better semantic representation of what the transformer actaually does.
5+
* Added `Transformers#keyRename` that takes a single `from` key and a single `to` key and performs the appropriate renaming.
6+
37
#### Version 1.4.0 (December 24, 2018)
48
* Added `Transformers#nest` which takes another `Transformer` and applies it to each level of a nested data structure (e.g. `Map` or `Sequence`).
59
* Added `Transformers#copy` which copies the value associated with one key and also associates it with another key.

src/main/java/com/cinchapi/etl/Transformers.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,11 @@ public static Transformer keyEnsureCaseFormat(CaseFormat format) {
211211
*
212212
* @param map
213213
* @return the {@link Transformer}
214+
* @deprecated use {@link #keyRename(Map)} instead
214215
*/
216+
@Deprecated
215217
public static Transformer keyMap(Map<String, String> map) {
216-
return (key, value) -> {
217-
key = map.get(key);
218-
if(key != null) {
219-
return Transformation.to(key, value);
220-
}
221-
else {
222-
return null;
223-
}
224-
};
218+
return keyRename(map);
225219
}
226220

227221
/**
@@ -281,6 +275,38 @@ public static Transformer keyRemoveWhitespace() {
281275
return keyRemoveInvalidChars(Character::isWhitespace);
282276
}
283277

278+
/**
279+
* Return a {@link Transformer} that renames keys. The renaming rules are
280+
* that each key in the provided {@code map} is renamed to its associated
281+
* value.
282+
*
283+
* @param map
284+
* @return the {@link Transformer}
285+
*/
286+
public static Transformer keyRename(Map<String, String> map) {
287+
return (key, value) -> {
288+
key = map.get(key);
289+
if(key != null) {
290+
return Transformation.to(key, value);
291+
}
292+
else {
293+
return null;
294+
}
295+
};
296+
}
297+
298+
/**
299+
* Return a {@link Transformer} that renames key {@code from} to the
300+
* specified {@code to} key.
301+
*
302+
* @param from
303+
* @param to
304+
* @return the {@link Transformer}
305+
*/
306+
public static Transformer keyRename(String from, String to) {
307+
return keyRename(ImmutableMap.of(from, to));
308+
}
309+
284310
/**
285311
* Return a {@link Transformer} that replaces all the character keys in the
286312
* {@code replacements} mapping with their associated character values in

0 commit comments

Comments
 (0)