From e75a8ef2372722c0b22669fb427d47bacc5b8d5e Mon Sep 17 00:00:00 2001 From: HuabingZhao Date: Thu, 7 Sep 2017 14:33:18 +0800 Subject: Fix java check style warning Change-Id: I98a6d7237a213d007ad4d954989cb0b0fa150a10 Issue-Id: MSB-67 Signed-off-by: HuabingZhao --- .../apiroute/wrapper/service/IuiRouteService.java | 48 +++++++++++----------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/service/IuiRouteService.java') diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/service/IuiRouteService.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/service/IuiRouteService.java index c602456..87a5e30 100644 --- a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/service/IuiRouteService.java +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/service/IuiRouteService.java @@ -1,20 +1,22 @@ /******************************************************************************* * Copyright 2016-2017 ZTE, Inc. and others. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. ******************************************************************************/ package org.onap.msb.apiroute.wrapper.service; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + import org.onap.msb.apiroute.api.IuiRouteInfo; import org.onap.msb.apiroute.api.RouteServer; import org.onap.msb.apiroute.wrapper.dao.DAOFactory; @@ -26,10 +28,6 @@ import org.onap.msb.apiroute.wrapper.dao.route.bean.Spec; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; - public class IuiRouteService { private static final Logger LOGGER = LoggerFactory.getLogger(CustomRouteService.class); @@ -37,15 +35,14 @@ public class IuiRouteService { private static final IuiRouteService instance = new IuiRouteService(); private IRouteDAO routeDAO = DAOFactory.getRouteDAO(); - private IuiRouteService() { - } + private IuiRouteService() {} public static IuiRouteService getInstance() { return instance; } public void saveIuiRouteService2Redis(IuiRouteInfo iuiRouteInfo, String routeKey) throws Exception { - if(iuiRouteInfo ==null){ + if (iuiRouteInfo == null) { throw new Exception("input apiRouteInfo to be saved is null!"); } RouteInfo routeInfo = IuiRouteAdapter.toRouteInfo(iuiRouteInfo); @@ -64,7 +61,7 @@ public class IuiRouteService { IuiRouteInfo iuiRouteInfo = null; RouteInfo routeInfo = null; routeInfo = routeDAO.queryRoute(routeKey); - if(routeInfo!=null) { + if (routeInfo != null) { iuiRouteInfo = IuiRouteAdapter.fromRouteInfo(routeInfo); } return iuiRouteInfo; @@ -82,18 +79,19 @@ public class IuiRouteService { return iuiRouteList; } - public void updateIuiRouteStatus2Redis(String routeKey,String status) throws Exception { + public void updateIuiRouteStatus2Redis(String routeKey, String status) throws Exception { RouteInfo routeInfo = routeDAO.queryRoute(routeKey); - if(routeInfo != null){ + if (routeInfo != null) { routeInfo.setStatus(status); - routeDAO.saveRoute(routeKey,routeInfo); - }else{ + routeDAO.saveRoute(routeKey, routeInfo); + } else { throw new Exception("service to be updated is not exist! Update failed"); } } } + class IuiRouteAdapter { public static RouteInfo toRouteInfo(IuiRouteInfo iuiRouteInfo) { RouteInfo routeInfo = new RouteInfo(); @@ -112,14 +110,14 @@ class IuiRouteAdapter { spec.setControl(iuiRouteInfo.getControl()); RouteServer[] routeServers = iuiRouteInfo.getServers(); List nodeList = new ArrayList<>(); - for (RouteServer server: routeServers){ + for (RouteServer server : routeServers) { Node node = new Node(); node.setIp(server.getIp()); node.setPort(Integer.parseInt(server.getPort())); node.setWeight(server.getWeight()); nodeList.add(node); } - spec.setNodes(nodeList.toArray(new Node[]{})); + spec.setNodes(nodeList.toArray(new Node[] {})); routeInfo.setSpec(spec); Metadata metadata = new Metadata(); @@ -148,14 +146,14 @@ class IuiRouteAdapter { iuiRouteInfo.setControl(spec.getControl()); Node[] nodes = spec.getNodes(); List routeServerList = new ArrayList<>(); - for (Node node: nodes){ + for (Node node : nodes) { RouteServer routeServer = new RouteServer(); routeServer.setIp(node.getIp()); routeServer.setPort(String.valueOf(node.getPort())); routeServer.setWeight(node.getWeight()); routeServerList.add(routeServer); } - iuiRouteInfo.setServers(routeServerList.toArray(new RouteServer[]{})); + iuiRouteInfo.setServers(routeServerList.toArray(new RouteServer[] {})); Metadata metadata = routeInfo.getMetadata(); iuiRouteInfo.setServiceName(metadata.getName()); -- cgit 1.2.3-korg