Created
March 4, 2018 00:21
-
-
Save ondrej-kvasnovsky/b4dd6096d1e3d4ecc37e5e2e08ff41b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package counter; | |
import io.vertx.core.shareddata.LocalMap; | |
import io.vertx.core.shareddata.SharedData; | |
import java.util.Optional; | |
public class CounterRepository { | |
private SharedData data; | |
CounterRepository(SharedData data) { | |
this.data = data; | |
} | |
public Optional<Integer> get() { | |
LocalMap<String, String> counter = data.getLocalMap("key"); | |
return Optional.of(counter) | |
.filter(map -> !map.isEmpty()) | |
.map(map -> Integer.valueOf(map.get("counter"))); | |
} | |
public void update(Integer counter) { | |
LocalMap<String, String> map = data.getLocalMap("key"); | |
map.put("counter", counter.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment