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;
}
Aggregations