diff --git a/lombok/src/main/java/com/baeldung/lombok/getter/GetterLazy.java b/lombok/src/main/java/com/baeldung/lombok/getter/GetterLazy.java new file mode 100644 index 0000000000..5ac82a74d8 --- /dev/null +++ b/lombok/src/main/java/com/baeldung/lombok/getter/GetterLazy.java @@ -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 transactions = readTxnsFromFile(); + + private Map readTxnsFromFile() { + + final Map cache = new HashMap<>(); + List txnRows = readTxnListFromFile(); + + txnRows.forEach(s -> { + String[] txnIdValueTuple = s.split(DELIMETER); + cache.put(txnIdValueTuple[0], Long.parseLong(txnIdValueTuple[1])); + }); + + return cache; + } + + private List readTxnListFromFile() { + + // read large file + return Stream.of("file content here").collect(Collectors.toList()); + } +}