This commit is contained in:
amit2103 2019-06-30 16:37:31 +05:30
parent 447c8c3599
commit 0824934027
3 changed files with 29 additions and 2 deletions

View File

@ -13,9 +13,9 @@ public class GetterLazy {
private static final String DELIMETER = ",";
@Getter(lazy = true)
private final Map<String, Long> transactions = readTxnsFromFile();
private final Map<String, Long> transactions = getTransactions();
private Map<String, Long> readTxnsFromFile() {
private Map<String, Long> getTransactions() {
final Map<String, Long> cache = new HashMap<>();
List<String> txnRows = readTxnListFromFile();

View File

@ -0,0 +1,26 @@
package com.baeldung.lombok.intro;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import lombok.SneakyThrows;
import lombok.Synchronized;
public class Utility {
@SneakyThrows
public String resourceAsString() throws IOException {
try (InputStream is = this.getClass().getResourceAsStream("sure_in_my_jar.txt")) {
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
return br.lines().collect(Collectors.joining("\n"));
}
}
@Synchronized
public void putValueInCache(String key, String value) {
System.out.println("Thread safe here with key : [" + key + "] and value[" + value + "]");
}
}

View File

@ -0,0 +1 @@
Hello