Fixed checkstyle errors causing build failures.

This commit is contained in:
Toxic Dreamz 2020-08-19 13:27:08 +04:00
parent 57e45a329f
commit 6921b0dce0
10 changed files with 151 additions and 108 deletions

View File

@ -74,6 +74,7 @@ public class RemoteService implements RemoteServiceInterface {
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOGGER.error("Thread sleep state interrupted", e); LOGGER.error("Thread sleep state interrupted", e);
} }
return waitTime <= THRESHOLD ? value * 10 : RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue(); return waitTime <= THRESHOLD ? value * 10
: RemoteServiceStatus.FAILURE.getRemoteServiceStatusValue();
} }
} }

View File

@ -1,10 +1,35 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.ambassador; package com.iluwatar.ambassador;
/** /**
* Holds information regarding the status of the Remote Service. * Holds information regarding the status of the Remote Service.
* *
* !Attention - This Enum replaces the integer value previously stored in {@link RemoteServiceInterface} * <p> This Enum replaces the integer value previously
* as SonarCloud was identifying it as an issue. All test cases have been checked after changes, without failures. * stored in {@link RemoteServiceInterface} as SonarCloud was identifying
* it as an issue. All test cases have been checked after changes,
* without failures. </p>
*/ */
public enum RemoteServiceStatus { public enum RemoteServiceStatus {

View File

@ -36,10 +36,10 @@ import com.iluwatar.commander.queue.QueueDatabase;
import com.iluwatar.commander.queue.QueueTask; import com.iluwatar.commander.queue.QueueTask;
import com.iluwatar.commander.queue.QueueTask.TaskType; import com.iluwatar.commander.queue.QueueTask.TaskType;
import com.iluwatar.commander.shippingservice.ShippingService; import com.iluwatar.commander.shippingservice.ShippingService;
import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
/** /**
* <p>Commander pattern is used to handle all issues that can come up while making a * <p>Commander pattern is used to handle all issues that can come up while making a
@ -171,23 +171,6 @@ public class Commander {
var list = paymentService.exceptionsList; var list = paymentService.exceptionsList;
var t = new Thread(() -> { var t = new Thread(() -> {
Retry.Operation op = (l) -> { Retry.Operation op = (l) -> {
handlePaymentRetryOperation(order, l);
};
Retry.HandleErrorIssue<Order> handleError = (o, err) -> {
handlePaymentErrorIssue(order, o, err);
};
var r = new Retry<>(op, handleError, numOfRetries, retryDuration,
e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass()));
try {
r.perform(list, order);
} catch (Exception e1) {
e1.printStackTrace();
}
});
t.start();
}
private void handlePaymentRetryOperation(Order order, List<Exception> l) throws Exception {
if (!l.isEmpty()) { if (!l.isEmpty()) {
if (DatabaseUnavailableException.class.isAssignableFrom(l.get(0).getClass())) { if (DatabaseUnavailableException.class.isAssignableFrom(l.get(0).getClass())) {
LOG.debug("Order " + order.id + ": Error in connecting to payment service," LOG.debug("Order " + order.id + ": Error in connecting to payment service,"
@ -201,16 +184,14 @@ public class Commander {
var transactionId = paymentService.receiveRequest(order.price); var transactionId = paymentService.receiveRequest(order.price);
order.paid = PaymentStatus.DONE; order.paid = PaymentStatus.DONE;
LOG.info("Order " + order.id + ": Payment successful, transaction Id: " + transactionId); LOG.info("Order " + order.id + ": Payment successful, transaction Id: " + transactionId);
if (!finalSiteMsgShown) { if (!finalSiteMsgShown) {
LOG.info("Payment made successfully, thank you for shopping with us!!"); LOG.info("Payment made successfully, thank you for shopping with us!!");
finalSiteMsgShown = true; finalSiteMsgShown = true;
} }
sendSuccessMessage(order); sendSuccessMessage(order);
} }
} };
Retry.HandleErrorIssue<Order> handleError = (o, err) -> {
private void handlePaymentErrorIssue(Order order, Order o, Exception err) {
if (PaymentDetailsErrorException.class.isAssignableFrom(err.getClass())) { if (PaymentDetailsErrorException.class.isAssignableFrom(err.getClass())) {
if (!finalSiteMsgShown) { if (!finalSiteMsgShown) {
LOG.info("There was an error in payment. Your account/card details " LOG.info("There was an error in payment. Your account/card details "
@ -237,6 +218,16 @@ public class Commander {
updateQueue(qt); updateQueue(qt);
} }
} }
};
var r = new Retry<>(op, handleError, numOfRetries, retryDuration,
e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass()));
try {
r.perform(list, order);
} catch (Exception e1) {
e1.printStackTrace();
}
});
t.start();
} }
private void updateQueue(QueueTask qt) { private void updateQueue(QueueTask qt) {
@ -483,7 +474,8 @@ public class Commander {
} }
} }
private void handlePaymentPossibleErrorMsgRetryOperation(Order order, List<Exception> l) throws Exception { private void handlePaymentPossibleErrorMsgRetryOperation(Order order, List<Exception> l)
throws Exception {
if (!l.isEmpty()) { if (!l.isEmpty()) {
if (DatabaseUnavailableException.class.isAssignableFrom(l.get(0).getClass())) { if (DatabaseUnavailableException.class.isAssignableFrom(l.get(0).getClass())) {
LOG.debug("Order " + order.id + ": Error in connecting to messaging service " LOG.debug("Order " + order.id + ": Error in connecting to messaging service "

View File

@ -40,7 +40,7 @@ public class AiComponentManager {
private final int numEntities; private final int numEntities;
private final Component[] AI_COMPONENTS = new AiComponent[MAX_ENTITIES]; private final Component[] aiComponents = new AiComponent[MAX_ENTITIES];
public AiComponentManager(int numEntities) { public AiComponentManager(int numEntities) {
this.numEntities = numEntities; this.numEntities = numEntities;
@ -51,7 +51,7 @@ public class AiComponentManager {
*/ */
public void start() { public void start() {
LOGGER.info("Start AI Game Component"); LOGGER.info("Start AI Game Component");
IntStream.range(0, numEntities).forEach(i -> AI_COMPONENTS[i] = new AiComponent()); IntStream.range(0, numEntities).forEach(i -> aiComponents[i] = new AiComponent());
} }
/** /**
@ -60,7 +60,7 @@ public class AiComponentManager {
public void update() { public void update() {
LOGGER.info("Update AI Game Component"); LOGGER.info("Update AI Game Component");
IntStream.range(0, numEntities) IntStream.range(0, numEntities)
.filter(i -> AI_COMPONENTS.length > i && AI_COMPONENTS[i] != null) .filter(i -> aiComponents.length > i && aiComponents[i] != null)
.forEach(i -> AI_COMPONENTS[i].update()); .forEach(i -> aiComponents[i].update());
} }
} }

View File

@ -40,7 +40,7 @@ public class PhysicsComponentManager {
private final int numEntities; private final int numEntities;
private final Component[] PHYSICS_COMPONENTS = new PhysicsComponent[MAX_ENTITIES]; private final Component[] physicsComponents = new PhysicsComponent[MAX_ENTITIES];
public PhysicsComponentManager(int numEntities) { public PhysicsComponentManager(int numEntities) {
this.numEntities = numEntities; this.numEntities = numEntities;
@ -51,7 +51,7 @@ public class PhysicsComponentManager {
*/ */
public void start() { public void start() {
LOGGER.info("Start Physics Game Component "); LOGGER.info("Start Physics Game Component ");
IntStream.range(0, numEntities).forEach(i -> PHYSICS_COMPONENTS[i] = new PhysicsComponent()); IntStream.range(0, numEntities).forEach(i -> physicsComponents[i] = new PhysicsComponent());
} }
@ -62,7 +62,7 @@ public class PhysicsComponentManager {
LOGGER.info("Update Physics Game Component "); LOGGER.info("Update Physics Game Component ");
// Process physics. // Process physics.
IntStream.range(0, numEntities) IntStream.range(0, numEntities)
.filter(i -> PHYSICS_COMPONENTS.length > i && PHYSICS_COMPONENTS[i] != null) .filter(i -> physicsComponents.length > i && physicsComponents[i] != null)
.forEach(i -> PHYSICS_COMPONENTS[i].update()); .forEach(i -> physicsComponents[i].update());
} }
} }

View File

@ -40,7 +40,7 @@ public class RenderComponentManager {
private final int numEntities; private final int numEntities;
private final Component[] RENDER_COMPONENTS = new RenderComponent[MAX_ENTITIES]; private final Component[] renderComponents = new RenderComponent[MAX_ENTITIES];
public RenderComponentManager(int numEntities) { public RenderComponentManager(int numEntities) {
this.numEntities = numEntities; this.numEntities = numEntities;
@ -51,7 +51,7 @@ public class RenderComponentManager {
*/ */
public void start() { public void start() {
LOGGER.info("Start Render Game Component "); LOGGER.info("Start Render Game Component ");
IntStream.range(0, numEntities).forEach(i -> RENDER_COMPONENTS[i] = new RenderComponent()); IntStream.range(0, numEntities).forEach(i -> renderComponents[i] = new RenderComponent());
} }
@ -62,7 +62,7 @@ public class RenderComponentManager {
LOGGER.info("Update Render Game Component "); LOGGER.info("Update Render Game Component ");
// Process Render. // Process Render.
IntStream.range(0, numEntities) IntStream.range(0, numEntities)
.filter(i -> RENDER_COMPONENTS.length > i && RENDER_COMPONENTS[i] != null) .filter(i -> renderComponents.length > i && renderComponents[i] != null)
.forEach(i -> RENDER_COMPONENTS[i].render()); .forEach(i -> renderComponents[i].render());
} }
} }

View File

@ -47,6 +47,7 @@
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -35,6 +35,7 @@ public class App {
* *
* @param args no argument sent * @param args no argument sent
*/ */
public static void main(String[] args) { public static void main(String[] args) {
var ram = new Student(1, "Ram", "Street 9, Cupertino"); var ram = new Student(1, "Ram", "Street 9, Cupertino");
var shyam = new Student(2, "Shyam", "Z bridge, Pune"); var shyam = new Student(2, "Shyam", "Z bridge, Pune");

View File

@ -1,10 +1,32 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.unitofwork; package com.iluwatar.unitofwork;
public enum UnitActions { public enum UnitActions {
INSERT("INSERT"), INSERT("INSERT"),
DELETE("DELETE"), DELETE("DELETE"),
MODIFY("MODIFY") MODIFY("MODIFY");
;
private final String actionValue; private final String actionValue;

View File

@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
* AppTest * AppTest
*/ */
public class AppTest { public class AppTest {
@Test @Test
public void shouldExecuteWithoutException() { public void shouldExecuteWithoutException() {
assertDoesNotThrow(() -> App.main(new String[]{})); assertDoesNotThrow(() -> App.main(new String[]{}));