From 082493402763533a059fdf36ae4109588414bd13 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 30 Jun 2019 16:37:31 +0530 Subject: [PATCH] [BAEL-14274] - Fixed article code for https://www.baeldung.com/intro-to-project-lombok --- .../baeldung/lombok/getter/GetterLazy.java | 4 +-- .../com/baeldung/lombok/intro/Utility.java | 26 +++++++++++++++++++ lombok/src/main/resources/sure_in_my_jar.txt | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 lombok/src/main/java/com/baeldung/lombok/intro/Utility.java create mode 100644 lombok/src/main/resources/sure_in_my_jar.txt diff --git a/lombok/src/main/java/com/baeldung/lombok/getter/GetterLazy.java b/lombok/src/main/java/com/baeldung/lombok/getter/GetterLazy.java index 5ac82a74d8..604c45be3b 100644 --- a/lombok/src/main/java/com/baeldung/lombok/getter/GetterLazy.java +++ b/lombok/src/main/java/com/baeldung/lombok/getter/GetterLazy.java @@ -13,9 +13,9 @@ public class GetterLazy { private static final String DELIMETER = ","; @Getter(lazy = true) - private final Map transactions = readTxnsFromFile(); + private final Map transactions = getTransactions(); - private Map readTxnsFromFile() { + private Map getTransactions() { final Map cache = new HashMap<>(); List txnRows = readTxnListFromFile(); diff --git a/lombok/src/main/java/com/baeldung/lombok/intro/Utility.java b/lombok/src/main/java/com/baeldung/lombok/intro/Utility.java new file mode 100644 index 0000000000..07198d2ffc --- /dev/null +++ b/lombok/src/main/java/com/baeldung/lombok/intro/Utility.java @@ -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 + "]"); + } +} diff --git a/lombok/src/main/resources/sure_in_my_jar.txt b/lombok/src/main/resources/sure_in_my_jar.txt new file mode 100644 index 0000000000..5ab2f8a432 --- /dev/null +++ b/lombok/src/main/resources/sure_in_my_jar.txt @@ -0,0 +1 @@ +Hello \ No newline at end of file