Search in sources :

Example 6 with Range

use of org.opennms.netmgt.config.snmp.Range in project opennms by OpenNMS.

the class MergeableRange method removeSpecificFromRange.

/**
     * Changes the current Range by moving the end before the specific and
     * creates a new range to the right of the specific ending with the
     * current Range's end address.
     *
     * @return a new Range to be added to Definition
     * @param spec a {@link java.lang.String} object.
     */
protected Range removeSpecificFromRange(final String spec) {
    if (!coversSpecific(spec))
        throw new IllegalArgumentException("Specific: " + spec + ", doesn't affect range: ");
    MergeableSpecific specific = new MergeableSpecific(spec);
    Range newRange = null;
    ByteArrayComparator comparator = new ByteArrayComparator();
    try {
        if (comparator.compare(specific.getValue(), getFirst().getValue()) == 0) {
            getRange().setBegin(InetAddressUtils.incr(specific.getSpecific()));
        } else if (comparator.compare(specific.getValue(), getLast().getValue()) == 0) {
            getRange().setEnd(InetAddressUtils.decr(specific.getSpecific()));
        } else {
            newRange = new Range();
            newRange.setBegin(InetAddressUtils.incr(specific.getSpecific()));
            newRange.setEnd(getRange().getEnd());
            getRange().setEnd(InetAddressUtils.decr(specific.getSpecific()));
        }
    } catch (UnknownHostException e) {
        LOG.error("Error converting string to IP address", e);
    }
    return newRange;
}
Also used : UnknownHostException(java.net.UnknownHostException) Range(org.opennms.netmgt.config.snmp.Range) ByteArrayComparator(org.opennms.core.utils.ByteArrayComparator)

Aggregations

Range (org.opennms.netmgt.config.snmp.Range)6 IPAddressRange (org.opennms.core.network.IPAddressRange)2 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 ByteArrayComparator (org.opennms.core.utils.ByteArrayComparator)1 Definition (org.opennms.netmgt.config.snmp.Definition)1