All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.ripe.db.whois.common.ip.IpInterval Maven / Gradle / Ivy

package net.ripe.db.whois.common.ip;

import net.ripe.db.whois.common.domain.CIString;
import net.ripe.db.whois.common.rpsl.AttributeType;

import java.net.Inet4Address;
import java.net.InetAddress;

public abstract class IpInterval> implements Interval {
    public static String removeTrailingDot(final String address) {
        if (address.endsWith(".")) {
            return address.substring(0, address.length() - 1);
        }

        return address;
    }

    public abstract AttributeType getAttributeType();

    public static IpInterval parse(final CIString prefix) {
        return parse(prefix.toString());
    }

    public static IpInterval parse(final String prefix) {
        if (prefix.indexOf(':') == -1) {
            return Ipv4Resource.parse(prefix);
        }

        return Ipv6Resource.parse(prefix);
    }

    public static IpInterval parseReverseDomain(final String reverse) {
        final String result = removeTrailingDot(reverse).toLowerCase();

        if (result.endsWith(Ipv4Resource.IPV4_REVERSE_DOMAIN)) {
            return Ipv4Resource.parseReverseDomain(result);
        }

        return Ipv6Resource.parseReverseDomain(result);
    }

    public static IpInterval asIpInterval(final InetAddress address) {
        if (address instanceof Inet4Address) {
            return new Ipv4Resource(address);
        }

        return Ipv6Resource.parse(address);
    }

    public abstract InetAddress beginAsInetAddress();

    public abstract int getPrefixLength();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy