IIPv4AddressItem.java

/*
 * SPDX-FileCopyrightText: none
 * SPDX-License-Identifier: CC0-1.0
 */

package gov.nist.secauto.metaschema.core.metapath.item.atomic;

import gov.nist.secauto.metaschema.core.datatype.adapter.MetaschemaDataTypeProvider;
import gov.nist.secauto.metaschema.core.metapath.function.InvalidValueForCastFunctionException;

import edu.umd.cs.findbugs.annotations.NonNull;
import inet.ipaddr.ipv4.IPv4Address;

public interface IIPv4AddressItem extends IIPAddressItem {

  /**
   * Construct a new IPv4 item using the provided {@code value}.
   *
   * @param value
   *          an IPv4 value
   * @return the new item
   */
  @NonNull
  static IIPv4AddressItem valueOf(@NonNull IPv4Address value) {
    return new IPv4AddressItemImpl(value);
  }

  /**
   * Cast the provided type to this item type.
   *
   * @param item
   *          the item to cast
   * @return the original item if it is already this type, otherwise a new item
   *         cast to this type
   * @throws InvalidValueForCastFunctionException
   *           if the provided {@code item} cannot be cast to this type
   */
  @NonNull
  static IIPv4AddressItem cast(@NonNull IAnyAtomicItem item) {
    return MetaschemaDataTypeProvider.IP_V4_ADDRESS.cast(item);
  }

  @Override
  IPv4Address asIpAddress();

  @Override
  default IIPv4AddressItem castAsType(IAnyAtomicItem item) {
    return cast(item);
  }

  @Override
  default int compareTo(IAnyAtomicItem item) {
    return compareTo(cast(item));
  }
}