private void checkProperInterfaceType(@Nonnull final WriteContext writeContext, @Nonnull final InstanceIdentifier<D> id) { final InstanceIdentifier<Interface> ifcTypeFromIid = id.firstIdentifierOf(Interface.class); checkArgument(ifcTypeFromIid != null, "Instance identifier does not contain {} type", Interface.class); checkArgument(id.firstKeyOf(Interface.class) != null, "Instance identifier does not contain keyed {} type", Interface.class); final Optional<Interface> interfaceConfig = writeContext.readAfter(ifcTypeFromIid); checkState(interfaceConfig.isPresent(), "Unable to get Interface configuration for an interface: %s currently being updated", ifcTypeFromIid); IllegalInterfaceTypeException .checkInterfaceType(interfaceConfig.get(), getExpectedInterfaceType()); }
/** * Check the type of interface equals expected type * * @throws IllegalInterfaceTypeException if type of interface is null or not expected */ static void checkInterfaceType(@Nonnull final Interface ifc, @Nonnull final Class<? extends InterfaceType> expectedType) { if (ifc.getType() == null || !expectedType.equals(ifc.getType())) { throw new IllegalInterfaceTypeException(String.format( "Unexpected interface type: %s for interface: %s. Expected interface is: %s", ifc.getType(), ifc.getName(), expectedType)); } }