Skip to content

Instantly share code, notes, and snippets.

View wsoczynski's full-sized avatar

Wojciech Soczyński wsoczynski

  • London, United Kingdom
View GitHub Profile
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);
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).
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);
}
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).
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));
}
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);
public class GenerateTest {
@Test
public void testGenerate() {
//given
Set<Integer> expected = new LinkedHashSet<Integer>();
for (int i = 1; i < 101; i++) {
expected.add(i);
}
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).
public class FluentIterableExample {
public static void main(String... args){
List<String> input = newArayList();
FluentIterable<String> iterable = FluentIterable.from(input);
//the rest of processing
}
}
@wsoczynski
wsoczynski / gist:4025133
Created November 6, 2012 14:48
Optional 3
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){