| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.common.util;
|
1 |
package com.spice.profitmandi.common.util;
|
| 2 |
|
2 |
|
| - |
|
3 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
| - |
|
4 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| - |
|
5 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
| - |
|
6 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
7 |
import org.apache.logging.log4j.Logger;
|
| - |
|
8 |
|
| - |
|
9 |
import javax.mail.internet.InternetAddress;
|
| 3 |
import java.time.*;
|
10 |
import java.time.*;
|
| 4 |
import java.time.format.DateTimeFormatter;
|
11 |
import java.time.format.DateTimeFormatter;
|
| 5 |
import java.time.format.DateTimeParseException;
|
12 |
import java.time.format.DateTimeParseException;
|
| 6 |
import java.util.ArrayList;
|
13 |
import java.util.ArrayList;
|
| 7 |
import java.util.List;
|
14 |
import java.util.List;
|
| 8 |
|
- |
|
| 9 |
import javax.mail.internet.InternetAddress;
|
15 |
import java.util.regex.Matcher;
|
| 10 |
|
- |
|
| 11 |
import org.apache.logging.log4j.Logger;
|
16 |
import java.util.regex.Pattern;
|
| 12 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 13 |
|
- |
|
| 14 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
- |
|
| 15 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
- |
|
| 16 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
- |
|
| 17 |
|
17 |
|
| 18 |
public class StringUtils {
|
18 |
public class StringUtils {
|
| 19 |
|
19 |
|
| 20 |
private static ObjectMapper objectMapper = new ObjectMapper();
|
20 |
private static ObjectMapper objectMapper = new ObjectMapper();
|
| 21 |
|
21 |
|
| Line 23... |
Line 23... |
| 23 |
private static final String DATE_PATTERN = "dd/MM/yyyy";
|
23 |
private static final String DATE_PATTERN = "dd/MM/yyyy";
|
| 24 |
private static final String GADGET_COP_DATE_PATTERN = "MM/dd/yyyy";
|
24 |
private static final String GADGET_COP_DATE_PATTERN = "MM/dd/yyyy";
|
| 25 |
private static final String DATE_TIME_PATTERN = "dd/MM/yyyy HH:mm:ss";
|
25 |
private static final String DATE_TIME_PATTERN = "dd/MM/yyyy HH:mm:ss";
|
| 26 |
private static final String DATE_PATTERN_HYPHENATED = "dd-MM-yyyy";
|
26 |
private static final String DATE_PATTERN_HYPHENATED = "dd-MM-yyyy";
|
| 27 |
private static final String DATE_TIME_ABBR = "dd/MM/yyyy hh:mma";
|
27 |
private static final String DATE_TIME_ABBR = "dd/MM/yyyy hh:mma";
|
| - |
|
28 |
private static final DateTimeFormatter SHORT_MONTH_DATE_FORMATTER = DateTimeFormatter.ofPattern("d-MMM-yyyy");
|
| - |
|
29 |
private static final DateTimeFormatter SHORT_MONTH_DATE_YEAR_FORMATTER = DateTimeFormatter.ofPattern("dd-MMM-yy");
|
| 28 |
private StringUtils(){
|
30 |
private StringUtils(){
|
| 29 |
|
31 |
|
| 30 |
}
|
32 |
}
|
| - |
|
33 |
|
| - |
|
34 |
public static final LocalDate fromShortMonthDateYear(String dateString) throws DateTimeParseException {
|
| - |
|
35 |
dateString = dateString.toLowerCase();
|
| - |
|
36 |
dateString = StringUtils.capitalizeFirstChar(dateString);
|
| - |
|
37 |
return LocalDate.parse(dateString, SHORT_MONTH_DATE_YEAR_FORMATTER);
|
| - |
|
38 |
}
|
| - |
|
39 |
|
| - |
|
40 |
public static final LocalDate fromShortMonthDate(String dateString) throws DateTimeParseException {
|
| - |
|
41 |
dateString = StringUtils.capitalizeFirstChar(dateString);
|
| - |
|
42 |
return LocalDate.parse(dateString, SHORT_MONTH_DATE_FORMATTER);
|
| - |
|
43 |
}
|
| - |
|
44 |
|
| 31 |
public static final LocalDate toDate(String dateString)throws DateTimeParseException{
|
45 |
public static final LocalDate toDate(String dateString)throws DateTimeParseException{
|
| 32 |
LOGGER.info("Converting dateString [{}] with pattern[{}]", dateString, DATE_PATTERN);
|
46 |
LOGGER.info("Converting dateString [{}] with pattern[{}]", dateString, DATE_PATTERN);
|
| 33 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_PATTERN);
|
47 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_PATTERN);
|
| 34 |
return LocalDate.parse(dateString, dateTimeFormatter);
|
48 |
return LocalDate.parse(dateString, dateTimeFormatter);
|
| 35 |
}
|
49 |
}
|
| Line 38... |
Line 52... |
| 38 |
LOGGER.info("Converting dateString [{}] with pattern[{}]", dateString, pattern);
|
52 |
LOGGER.info("Converting dateString [{}] with pattern[{}]", dateString, pattern);
|
| 39 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
|
53 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
|
| 40 |
return LocalDate.parse(dateString, dateTimeFormatter);
|
54 |
return LocalDate.parse(dateString, dateTimeFormatter);
|
| 41 |
}
|
55 |
}
|
| 42 |
|
56 |
|
| 43 |
public static final String toGadgetCopDateString(LocalDate ldt) {
|
57 |
public static final String toGadgetCopDateString(LocalDate ldt) {
|
| 44 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(GADGET_COP_DATE_PATTERN);
|
58 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(GADGET_COP_DATE_PATTERN);
|
| 45 |
return dateTimeFormatter.format(ldt);
|
59 |
return dateTimeFormatter.format(ldt);
|
| 46 |
}
|
60 |
}
|
| 47 |
|
61 |
|
| 48 |
public static final LocalDate fromHypendatedDate(String dateString)throws DateTimeParseException{
|
62 |
public static final LocalDate fromHypendatedDate(String dateString)throws DateTimeParseException{
|
| Line 115... |
Line 129... |
| 115 |
}
|
129 |
}
|
| 116 |
LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
130 |
LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
| 117 |
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(DATE_TIME_ABBR);
|
131 |
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(DATE_TIME_ABBR);
|
| 118 |
return dateTime.format(outputFormatter);
|
132 |
return dateTime.format(outputFormatter);
|
| 119 |
}
|
133 |
}
|
| 120 |
|
134 |
|
| 121 |
public static final LocalDateTime toDateTime(String dateTimeString, DateTimePattern dateTimePattern) throws DateTimeParseException{
|
135 |
public static final LocalDateTime toDateTime(String dateTimeString, DateTimePattern dateTimePattern) throws DateTimeParseException{
|
| 122 |
if(dateTimeString == null || dateTimeString.equals("0") || dateTimeString.isEmpty()){
|
136 |
if(dateTimeString == null || dateTimeString.equals("0") || dateTimeString.isEmpty()){
|
| 123 |
return null;
|
137 |
return null;
|
| 124 |
}
|
138 |
}
|
| 125 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimePattern.getValue());
|
139 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimePattern.getValue());
|
| Line 238... |
Line 252... |
| 238 |
int minute = Integer.parseInt(oxigenRechargeRequestDate.substring(10, 11));
|
252 |
int minute = Integer.parseInt(oxigenRechargeRequestDate.substring(10, 11));
|
| 239 |
int second = Integer.parseInt(oxigenRechargeRequestDate.substring(12, 13));
|
253 |
int second = Integer.parseInt(oxigenRechargeRequestDate.substring(12, 13));
|
| 240 |
return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second);
|
254 |
return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second);
|
| 241 |
}
|
255 |
}
|
| 242 |
|
256 |
|
| - |
|
257 |
public static String capitalizeFirstChar(String input) {
|
| - |
|
258 |
if (input == null || input.isEmpty()) {
|
| - |
|
259 |
return input; // Return the input if it's null or empty
|
| - |
|
260 |
}
|
| - |
|
261 |
|
| - |
|
262 |
// Define the regular expression to match the first alphabetic character
|
| - |
|
263 |
Pattern pattern = Pattern.compile("([a-zA-Z])");
|
| - |
|
264 |
Matcher matcher = pattern.matcher(input);
|
| - |
|
265 |
|
| - |
|
266 |
// If the first character matches, capitalize it
|
| - |
|
267 |
if (matcher.find()) {
|
| - |
|
268 |
return matcher.replaceFirst(matcher.group(1).toUpperCase());
|
| - |
|
269 |
}
|
| - |
|
270 |
|
| - |
|
271 |
return input; // If no match is found, return the original string
|
| - |
|
272 |
}
|
| - |
|
273 |
|
| 243 |
public static String formatDistance(double distanceInMeters) {
|
274 |
public static String formatDistance(double distanceInMeters) {
|
| 244 |
if (distanceInMeters >= 1000) {
|
275 |
if (distanceInMeters >= 1000) {
|
| 245 |
return String.format("%.2f km", distanceInMeters / 1000.0);
|
276 |
return String.format("%.2f km", distanceInMeters / 1000.0);
|
| 246 |
} else if (distanceInMeters >= 1) {
|
277 |
} else if (distanceInMeters >= 1) {
|
| 247 |
return String.format("%.0f m", distanceInMeters);
|
278 |
return String.format("%.0f m", distanceInMeters);
|