Clover icon

sunshower-base

  1. Project Clover database Mon May 7 2018 22:12:38 UTC
  2. Package io.sunshower.persistence.core

File AddressValidator.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
8
1
1
30
20
7
0.88
8
1
7

Classes

Class Line # Actions
AddressValidator 7 8 7
1.0100%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package io.sunshower.persistence.core;
2   
3    import java.net.Inet4Address;
4    import java.net.InetAddress;
5    import java.net.UnknownHostException;
6   
 
7    public interface AddressValidator {
8   
9    /**
10    * This method is not 100% correct. I just don't want to add a dependency on Guava or something
11    * else. Use it carefully
12    *
13    * @param value
14    * @return
15    */
 
16  4 toggle default NetworkAddress.Type check(String value) {
17  25 for (int i = 0; i < value.length(); i++) {
18  22 char ch = value.charAt(i);
19  22 if (!(ch == '.' || ch == ':' || Character.digit(ch, 16) != -1)) {
20  1 return NetworkAddress.Type.DNS;
21    }
22    }
23  3 try {
24  3 InetAddress addr = InetAddress.getByName(value);
25  2 return addr instanceof Inet4Address ? NetworkAddress.Type.IPV4 : NetworkAddress.Type.IPV6;
26    } catch (UnknownHostException e) {
27  1 return NetworkAddress.Type.IPV6;
28    }
29    }
30    }