Skip to content

Commit

Permalink
Merge pull request eugenp#6261 from dev-chirag/master
Browse files Browse the repository at this point in the history
BAEL2567 - New section on Lombok’s @Getter(lazy=true)
  • Loading branch information
eric-martin authored Feb 9, 2019
2 parents f79f427 + 79308e6 commit c60e6f1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lombok/src/main/java/com/baeldung/lombok/getter/GetterLazy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.baeldung.lombok.getter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import lombok.Getter;

public class GetterLazy {

private static final String DELIMETER = ",";

@Getter(lazy = true)
private final Map<String, Long> transactions = readTxnsFromFile();

private Map<String, Long> readTxnsFromFile() {

final Map<String, Long> cache = new HashMap<>();
List<String> txnRows = readTxnListFromFile();

txnRows.forEach(s -> {
String[] txnIdValueTuple = s.split(DELIMETER);
cache.put(txnIdValueTuple[0], Long.parseLong(txnIdValueTuple[1]));
});

return cache;
}

private List<String> readTxnListFromFile() {

// read large file
return Stream.of("file content here").collect(Collectors.toList());
}
}

0 comments on commit c60e6f1

Please sign in to comment.