Subversion Repositories SmartDukaan

Rev

Rev 21543 | Rev 21652 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21543 ashik.ali 1
package com.spice.profitmandi.common.util;
2
 
3
import java.time.LocalDate;
4
import java.time.LocalTime;
5
import java.time.format.DateTimeParseException;
21570 ashik.ali 6
import java.util.ArrayList;
7
import java.util.List;
21543 ashik.ali 8
 
9
import javax.mail.internet.InternetAddress;
10
 
21570 ashik.ali 11
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13
 
14
import com.fasterxml.jackson.core.JsonProcessingException;
15
import com.fasterxml.jackson.databind.ObjectMapper;
16
 
21543 ashik.ali 17
public class StringUtils {
21570 ashik.ali 18
 
19
	private static ObjectMapper objectMapper = new ObjectMapper();
20
 
21
	private static final Logger LOGGER = LoggerFactory.getLogger(StringUtils.class);
22
 
21543 ashik.ali 23
	private StringUtils(){
24
 
25
	}
26
	public static final LocalDate toDate(String dateString)throws DateTimeParseException{
27
		return LocalDate.parse(dateString);
28
	}
29
 
30
	public static final LocalTime toTime(String timeString) throws DateTimeParseException{
31
		return LocalTime.parse(timeString);
32
	}
33
 
34
	public static boolean isValidMobile(String mobile){
35
		try{
36
			Long.valueOf(mobile);
37
		}
38
		catch(Exception e){
39
			return false;
40
		}
41
 
42
		if (mobile.startsWith("0")){
43
			return false;
44
		}
45
		if (mobile.length()!=10){
46
			return false;
47
		}
48
		return true;
49
	}
50
 
51
	public static boolean isValidEmailAddress(String email) {
52
		boolean result = true;
53
		try {
54
			InternetAddress emailAddr = new InternetAddress(email);
55
			emailAddr.validate();
56
		} catch (Exception ex) {
57
			result = false;
58
		}
59
		return result;
60
	}
21570 ashik.ali 61
 
62
	public static List<String> getDuplicateElements(List<String> elements){
63
		List<String> duplicates = new ArrayList<>();
64
		for(int i = 0; i < elements.size(); i++){
65
			for(int j = i + 1; j < elements.size(); j++){
66
				if(elements.get(i).equals(elements.get(j))){
67
					duplicates.add(elements.get(i));
68
				}
69
			}
70
		}
71
		return duplicates;
72
	}
73
 
74
	public static String toString(Object object) throws Exception{
75
		try {
76
			return objectMapper.writeValueAsString(object);
77
		} catch (JsonProcessingException e) {
78
			LOGGER.error("Error occured while converting object to json", e);
79
			throw e;
80
		}
81
	}
21543 ashik.ali 82
}