diff options
author | ajay priyadarshi <ajay.priyadarshi@ril.com> | 2018-03-20 14:34:19 +0530 |
---|---|---|
committer | ajay priyadarshi <ajay.priyadarshi@ril.com> | 2018-03-20 14:34:19 +0530 |
commit | c61edb4b613c8eeb415aa5b0227c2ab1d2055765 (patch) | |
tree | c3b02c7defc0577464120de7e8295dc4e5b9bd9b | |
parent | 9e852f4d4578f3f65d6a9ee241da5e09dc1b2aa3 (diff) |
sonar fix:Code smells in Date Utils
commons/utils/DateUtil.java
file name: DateUtil.java
Change-Id: Iae0a465734bb52017ee97a0aab0b113a080825c1
Issue-ID: VFC-835
Signed-off-by: ajay priyadarshi <ajay.priyadarshi@ril.com>
-rw-r--r-- | ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java | 27 | ||||
-rw-r--r-- | ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtilTest.java | 6 |
2 files changed, 19 insertions, 14 deletions
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java index 6b4037a..9e84374 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java @@ -24,8 +24,8 @@ public class DateUtil { public static long[] getScanScope(Date fireTime, long collectPeriod) { Calendar fire = Calendar.getInstance(); - long start = 0L; - long end = 0L; + long start ; + long end ; fire.setTime(fireTime); fire.set(Calendar.SECOND, 0); fire.set(Calendar.MILLISECOND, 0); @@ -50,7 +50,7 @@ public class DateUtil { if (collectPeriod > 0) { end = fire.getTimeInMillis() - (fire.getTimeInMillis() + 8 * 60 * 60 * 1000) % (collectPeriod * 1000); } else { - return null; + return new long[0]; } start = end - collectPeriod * 1000; } @@ -58,7 +58,7 @@ public class DateUtil { return new long[]{start, end}; } - public static String TimeString(String timeString) { + public static String getTimeString(String timeString) { if (timeString == null) { return ""; } else { @@ -71,13 +71,18 @@ public class DateUtil { } public static String addTime(String srcTimeString, String period) throws ParseException { - String finaldate = TimeString(srcTimeString); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date date = sdf.parse(finaldate); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - calendar.add(Calendar.MINUTE, Integer.valueOf(period)); - return sdf.format(calendar.getTime()); + try{ + String finaldate = getTimeString(srcTimeString); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = sdf.parse(finaldate); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.MINUTE, Integer.valueOf(period)); + return sdf.format(calendar.getTime()); + }catch( ParseException e){ + throw e; + } + } } diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtilTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtilTest.java index b9e2aa3..5681985 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtilTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtilTest.java @@ -62,9 +62,9 @@ public class DateUtilTest { @Test public void testTimeString() { - String timeString = DateUtil.TimeString(null); - String timeString1 = DateUtil.TimeString("20180206T"); - String timeString2 = DateUtil.TimeString("20180206T+12"); + String timeString = DateUtil.getTimeString(null); + String timeString1 = DateUtil.getTimeString("20180206T"); + String timeString2 = DateUtil.getTimeString("20180206T+12"); assertNotNull(timeString); assertNotNull(timeString1); assertNotNull(timeString2); |