001package arez.component;
002
003import arez.Arez;
004import javax.annotation.Nonnull;
005
006/**
007 * Interface implemented by components that can verify their internal state.
008 */
009public interface Verifiable
010{
011  /**
012   * verify the state of the component and raise an exception if any state fails to verify.
013   *
014   * @throws Exception if entity invalid.
015   */
016  void verify()
017    throws Exception;
018
019  /**
020   * Verify they supplied object if it is verifiable.
021   *
022   * @param object the object to verify.
023   * @throws Exception if entity invalid.
024   */
025  static void verify( @Nonnull final Object object )
026    throws Exception
027  {
028    if ( Arez.isVerifyEnabled() )
029    {
030      if ( object instanceof Verifiable )
031      {
032        ( (Verifiable) object ).verify();
033      }
034    }
035  }
036}