Skip to content

Commit 97e3a3d

Browse files
author
Pavel Manannikov
committed
iluwatar#1284 Use local variable inference
1 parent 2332520 commit 97e3a3d

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

version-number/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class BookRepository {
7878
throw new BookNotFoundException("Not found book with id: " + book.getId());
7979
}
8080

81-
Book latestBook = collection.get(book.getId());
81+
var latestBook = collection.get(book.getId());
8282
if (book.getVersion() != latestBook.getVersion()) {
8383
throw new VersionMismatchException(
8484
"Tried to update stale version " + book.getVersion()
@@ -107,10 +107,10 @@ public class BookRepository {
107107
Here's the concurrency control in action:
108108

109109
```java
110-
long bookId = 1;
110+
var bookId = 1;
111111
// Alice and Bob took the book concurrently
112-
final Book aliceBook = bookRepository.get(bookId);
113-
final Book bobBook = bookRepository.get(bookId);
112+
final var aliceBook = bookRepository.get(bookId);
113+
final var bobBook = bookRepository.get(bookId);
114114

115115
aliceBook.setTitle("Kama Sutra"); // Alice has updated book title
116116
bookRepository.update(aliceBook); // and successfully saved book in database

version-number/src/main/java/com/iluwatar/versionnumber/App.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ public static void main(String[] args) throws
5353
BookDuplicateException,
5454
BookNotFoundException,
5555
VersionMismatchException {
56-
long bookId = 1;
56+
var bookId = 1;
5757

58-
BookRepository bookRepository = new BookRepository();
59-
Book book = new Book();
58+
var bookRepository = new BookRepository();
59+
var book = new Book();
6060
book.setId(bookId);
6161
bookRepository.add(book); // adding a book with empty title and author
6262
LOGGER.info("An empty book with version {} was added to repository", book.getVersion());
6363

6464
// Alice and Bob took the book concurrently
65-
final Book aliceBook = bookRepository.get(bookId);
66-
final Book bobBook = bookRepository.get(bookId);
65+
final var aliceBook = bookRepository.get(bookId);
66+
final var bobBook = bookRepository.get(bookId);
6767

6868
aliceBook.setTitle("Kama Sutra"); // Alice has updated book title
6969
bookRepository.update(aliceBook); // and successfully saved book in database

version-number/src/main/java/com/iluwatar/versionnumber/BookRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void update(Book book) throws BookNotFoundException, VersionMismatchExcep
5656
throw new BookNotFoundException("Not found book with id: " + book.getId());
5757
}
5858

59-
Book latestBook = collection.get(book.getId());
59+
var latestBook = collection.get(book.getId());
6060
if (book.getVersion() != latestBook.getVersion()) {
6161
throw new VersionMismatchException(
6262
"Tried to update stale version " + book.getVersion()

version-number/src/test/java/com/iluwatar/versionnumber/BookRepositoryTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
class BookRepositoryTest {
3434
@Test
3535
void testBookRepository() throws BookDuplicateException, BookNotFoundException, VersionMismatchException {
36-
final long bookId = 1;
36+
final var bookId = 1;
3737

38-
BookRepository bookRepository = new BookRepository();
39-
Book book = new Book();
38+
var bookRepository = new BookRepository();
39+
var book = new Book();
4040
book.setId(bookId);
4141
bookRepository.add(book);
4242

4343
assertEquals(0, book.getVersion());
4444

45-
final Book aliceBook = bookRepository.get(bookId);
46-
final Book bobBook = bookRepository.get(bookId);
45+
final var aliceBook = bookRepository.get(bookId);
46+
final var bobBook = bookRepository.get(bookId);
4747

4848
assertEquals(aliceBook.getTitle(), bobBook.getTitle());
4949
assertEquals(aliceBook.getAuthor(), bobBook.getAuthor());

0 commit comments

Comments
 (0)