// sort in asc order by (beginIp, type, owner)
Collections.sort(ipBlocks);
List<IpBlockEntity> newBlocks = new ArrayList<IpBlockEntity>(ipBlocks.size());
Iterator<IpBlockEntity> iter = ipBlocks.iterator();
IpBlockEntity prev = iter.next();
while (iter.hasNext()) {
IpBlockEntity curr = iter.next();
if (prev.canConcatWith(curr)) {
if (prev.isOverlapedWith(curr)) {
logger.warn("detected overlapped IP blocks: " + prev + ", " + curr);
if (!silentWhenOverlap) {
throw NetworkException.OVERLAPPED_IP_BLOCKS(prev, curr);
}
}
if ((ignoreOwner || prev.getOwnerId().equals(curr.getOwnerId()))
&& (ignoreType || prev.getType() == curr.getType())) {
prev.setEndIp(Math.max(curr.getEndIp(), prev.getEndIp()));
/**
* If curr is an persistent entity, delete it
*/
if (curr.getId() != null) {
if (inHibernateSession) {
/**
* The input blocks must be Hibernate-aware entities.
*/
delete(curr);