This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConcatPath implements Function<String,String> { | |
private final String subPath; | |
private ConcatPath(String subPath){ | |
this.subPath = subPath; | |
} | |
@Override | |
public String apply(String basePath){ | |
return FilenameUtils.concat(basePath,subPath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HierarchyAwareResourceLoader { | |
private final List<String> searchPaths; | |
public HierarchyAwareResourceLoader(List<String> searchPaths){ | |
this.searchPaths = searchPaths; | |
} | |
public Optional<File> load(String name){ | |
Optional<File> result = FluentIterable.from(searchPaths). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PerfTest extends SimpleBenchmark { | |
private List<Integer> input; | |
public void setUp() { | |
List<Integer> input = new LinkedList<Integer>(); | |
for (int i = 0; i < 10000; i++) { | |
input.add(i); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Sample { | |
public List<Double> allEvenNumberToSecondPower(List<Integer> input) { | |
EvenFilter evenFilter = new EvenFilter(); | |
PowerFunction powerFunction = new PowerFunction(2); | |
ImmutableList<Double> result = FluentIterable.from(input). | |
filter(evenFilter). | |
transform(powerFunction). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Sample { | |
public List<Double> allEvenNumberToSecondPower(List<Integer> input) { | |
List<Double> result = new LinkedList<Double>(); | |
for (Integer item : input) { | |
if (item % 2 == 0) { | |
result.add(Math.pow(item, 2)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TransformAndConcatTest{ | |
@Test | |
public void testTransformAndConcat() throws Exception { | |
//given | |
List<List<Integer>> input = newLinkedList(); | |
for (int i = 0; i < 10; i++) { | |
List<Integer> subList = newLinkedList(); | |
for (int j = 0; j < 10; j++) { | |
subList.add(j); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenerateTest { | |
@Test | |
public void testGenerate() { | |
//given | |
Set<Integer> expected = new LinkedHashSet<Integer>(); | |
for (int i = 1; i < 101; i++) { | |
expected.add(i); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FluentIterableExample { | |
public static void main(String... args){ | |
List<Integer> input = generateInput(); | |
EvenFilter evenFilter = new EvenFilter(); | |
PowerFunction powerFunction = new PowerFunction(2); | |
RangeFilter rangeFilter = new RangeFilter(17, 50); | |
Optional<Double> result = FluentIterable.from(input). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FluentIterableExample { | |
public static void main(String... args){ | |
List<String> input = newArayList(); | |
FluentIterable<String> iterable = FluentIterable.from(input); | |
//the rest of processing | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public Optional<String> someValue = Optional.of("test"); | |
public void main(String... args){ | |
Main m = new Main(); | |
Optional<Int> result = m.someValue.transform(new Function<String,Int>(){ | |
@Override | |
public String apply(@Nullable String input){ |
NewerOlder