In this screencast, I will explain how to setup IntelliJ live templates with Google Guava, and how to add a bit a Functional Programming to your Java code when using Java 7 or below. The templates used in the video, including the configuration for them, can be found below.
The code to make the filter work, is the following. You’ll have to go to Preferences -> Editor -> Live templates and add a new template there. The following code need to be entered for the filter:
Filter
com.google.common.collect.FluentIterable<$ELEMENT_TYPE$> $VAR2$ = FluentIterable.from($ITERABLE_TYPE$).filter(new com.google.common.base.Predicate<$ELEMENT_TYPE$>() { public boolean apply($ELEMENT_TYPE$ $VAR$) { return $END$true; } });
And the following variables have to be used:
For the transformation, another template needs to be added, similar to the template above.
Transform
com.google.common.collect.FluentIterable<$TO_TYPE$> $VAR2$ = FluentIterable.from($ITERABLE_TYPE$).transform(new com.google.common.base.Function<$ELEMENT_TYPE$, $TO_TYPE$>() { public $TO_TYPE$ apply($ELEMENT_TYPE$ $VAR$) { return new $TO_TYPE$($END$); } });
With these variables:
If you’ve setup the above, functional programming will become a lot easier, even in Java versions older than Java 8!
The post IntelliJ Live Templates with Google Guava appeared first on Jworks.