2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.translate.v3po.interfaces.ip.subnet.validation;
19 import static com.google.common.base.Preconditions.checkNotNull;
21 import java.util.Collection;
22 import javax.annotation.Nonnull;
23 import org.apache.commons.lang3.StringUtils;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address;
27 * Thrown as negative result of subnet validation
29 public class SubnetValidationException extends Exception {
31 private SubnetValidationException(@Nonnull final String message) {
35 public static SubnetValidationException forConflictingData(@Nonnull final Short prefix, @Nonnull Collection<Address> addresses) {
36 return new SubnetValidationException(
37 "Attempt to define multiple addresses for same subnet[prefixLen = " + prefixToString(prefix) + "], "
38 + "addresses : " + addressesToString(addresses));
41 private static String prefixToString(final Short prefix) {
42 return checkNotNull(prefix, "Cannot create " + SubnetValidationException.class.getName() + " for null prefix")
46 private static String addressesToString(final Collection<Address> addresses) {
47 return StringUtils.join(checkNotNull(addresses,
48 "Cannot create " + SubnetValidationException.class.getName() + " for null address list"), " | ");