Java 11 migrate all remaining s (#1120)

* Moves saga to Java 11

* Moves semaphore to Java 11

* Moves servant to Java 11

* Moves serverless to Java 11

* Moves service-layer to Java 11

* Moves service-locator to Java 11

* Moves sharding to Java 11

* Moves singleton to Java 11

* Moves spatial-partition to Java 11

* Moves specification to Java 11

* Moves state to Java 11

* Moves step-builder to Java 11

* Moves strategy to Java 11

* Moves subclass-sandbox to Java 11

* Fixes checkstyle issues
This commit is contained in:
Anurag Agarwal
2020-01-04 22:06:08 +05:30
committed by Ilkka Seppälä
parent 310ae50248
commit cd2a2e7711
98 changed files with 718 additions and 855 deletions

View File

@ -38,7 +38,7 @@ public class App {
* main method.
*/
public static void main(String[] args) {
FruitShop shop = new FruitShop();
var shop = new FruitShop();
new Customer("Peter", shop).start();
new Customer("Paul", shop).start();
new Customer("Mary", shop).start();

View File

@ -64,13 +64,14 @@ public class Customer extends Thread {
public void run() {
while (fruitShop.countFruit() > 0) {
FruitBowl bowl = fruitShop.takeBowl();
Fruit fruit;
if (bowl != null && (fruit = bowl.take()) != null) {
LOGGER.info("{} took an {}", name, fruit);
fruitBowl.put(fruit);
fruitShop.returnBowl(bowl);
var bowl = fruitShop.takeBowl();
if (bowl != null) {
var fruit = bowl.take();
if (fruit != null) {
LOGGER.info("{} took an {}", name, fruit);
fruitBowl.put(fruit);
fruitShop.returnBowl(bowl);
}
}
}

View File

@ -68,11 +68,11 @@ public class FruitBowl {
* toString method.
*/
public String toString() {
int apples = 0;
int oranges = 0;
int lemons = 0;
var apples = 0;
var oranges = 0;
var lemons = 0;
for (Fruit f : fruit) {
for (var f : fruit) {
switch (f.getType()) {
case APPLE:
apples++;

View File

@ -55,7 +55,7 @@ public class FruitShop {
* FruitShop constructor.
*/
public FruitShop() {
for (int i = 0; i < 100; i++) {
for (var i = 0; i < 100; i++) {
bowls[0].put(new Fruit(Fruit.FruitType.APPLE));
bowls[1].put(new Fruit(Fruit.FruitType.ORANGE));
bowls[2].put(new Fruit(Fruit.FruitType.LEMON));

View File

@ -25,15 +25,12 @@ package com.iluwatar.semaphore;
import org.junit.jupiter.api.Test;
import java.io.IOException;
/**
* Application Test Entrypoint
*/
public class AppTest {
@Test
public void test() {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}

View File

@ -23,12 +23,12 @@
package com.iluwatar.semaphore;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
/**
* Test taking from and putting Fruit into a FruitBowl
*/
@ -36,16 +36,16 @@ public class FruitBowlTest {
@Test
public void fruitBowlTest() {
FruitBowl fbowl = new FruitBowl();
var fbowl = new FruitBowl();
assertEquals(0, fbowl.countFruit());
for (int i = 1; i <= 10; i++) {
for (var i = 1; i <= 10; i++) {
fbowl.put(new Fruit(Fruit.FruitType.LEMON));
assertEquals(i, fbowl.countFruit());
}
for (int i = 9; i >= 0; i--) {
for (var i = 9; i >= 0; i--) {
assertNotNull(fbowl.take());
assertEquals(i, fbowl.countFruit());
}

View File

@ -23,11 +23,11 @@
package com.iluwatar.semaphore;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
/**
* Test case for acquiring and releasing a Semaphore
*/
@ -35,11 +35,11 @@ public class SemaphoreTest {
@Test
public void acquireReleaseTest() {
Semaphore sphore = new Semaphore(3);
var sphore = new Semaphore(3);
assertEquals(3, sphore.getAvailableLicenses());
for (int i = 2; i >= 0; i--) {
for (var i = 2; i >= 0; i--) {
try {
sphore.acquire();
assertEquals(i, sphore.getAvailableLicenses());
@ -47,8 +47,8 @@ public class SemaphoreTest {
fail(e.toString());
}
}
for (int i = 1; i <= 3; i++) {
for (var i = 1; i <= 3; i++) {
sphore.release();
assertEquals(i, sphore.getAvailableLicenses());
}