class DhcpLeaseParser {

    public static List<DhcpLease> parseLeaseFile( final String dhcpLeaseFile )
    {

        // check that dhcp lease file is not null or blank.
        if ( StringUtils.isBlank( dhcpLeaseFile ) )
        {
            logger.warn( "In parseLeaseFile, DHCP lease file is either null or blank." );
            return null;
        }

        // check that dhcp lease file exists.
        if ( !FileUtil.isFileExists( dhcpLeaseFile ) )
        {
            logger.warn( "In parseLeaseFile, DHCP lease file '{}' does not exist.", dhcpLeaseFile );
            return null;
        }

        // read dhcp file contents
        final String dhcpLeaseFileContent = FileUtil.readFileToString( dhcpLeaseFile );
        if ( StringUtils.isBlank( dhcpLeaseFileContent ) )
        {
            logger.warn( "In parseLeaseFile, DHCP lease file '{}' content is either null or blank." );
            return null;
        }

        Map<String, DhcpLease> dhcpLeasesMap = new HashMap<String, DhcpLease>();
        Pattern pattern = Pattern.compile( DHCP_LEASE_REGEX_PATTERN, Pattern.DOTALL );
        Matcher matcher = pattern.matcher( dhcpLeaseFileContent );
        DhcpLease dhcpLease = null;
        String macAddress = null;
        while ( matcher.find() )
        {
            dhcpLease = parseLeaseContent( matcher.group() );
            if ( dhcpLease != null )
            {
                macAddress = dhcpLease.getMacAddress();
                if ( !dhcpLeasesMap.containsKey( macAddress ) )
                {
                    dhcpLeasesMap.put( macAddress, dhcpLease );
                }
                else
                {
                    if ( isLatestLease( dhcpLeasesMap.get( macAddress ), dhcpLease ) )
                    {
                        dhcpLeasesMap.put( macAddress, dhcpLease );
                    }
                }
            }
        }
        return new ArrayList<DhcpLease>( dhcpLeasesMap.values() );
    }

    private  DhcpLeaseParser();

}