All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.helger.phive.api.execute.AbstractValidationExecutor Maven / Gradle / Ivy

/*
 * Copyright (C) 2014-2024 Philip Helger (www.helger.com)
 * philip[at]helger[dot]com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.helger.phive.api.execute;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;

import com.helger.commons.ValueEnforcer;
import com.helger.commons.hashcode.HashCodeGenerator;
import com.helger.commons.string.ToStringGenerator;
import com.helger.commons.traits.IGenericImplTrait;
import com.helger.phive.api.artefact.IValidationArtefact;
import com.helger.phive.api.source.IValidationSource;

/**
 * Abstract base implementation of {@link IValidationExecutor}.
 *
 * @author Philip Helger
 * @param 
 *        The validation source type to be used.
 * @param 
 *        Implementation type (Since v5.3.1)
 */
@Immutable
public abstract class AbstractValidationExecutor >
                                                 implements
                                                 IValidationExecutor ,
                                                 IGenericImplTrait 
{
  public static final boolean DEFAULT_STOP_VALIDATION_ON_ERROR = false;

  private final IValidationArtefact m_aValidationArtefact;
  private boolean m_bStopValidationOnError = DEFAULT_STOP_VALIDATION_ON_ERROR;

  public AbstractValidationExecutor (@Nonnull final IValidationArtefact aValidationArtefact)
  {
    m_aValidationArtefact = ValueEnforcer.notNull (aValidationArtefact, "ValidationArtefact");
  }

  @Nonnull
  public final IValidationArtefact getValidationArtefact ()
  {
    return m_aValidationArtefact;
  }

  @Override
  public final boolean isStopValidationOnError ()
  {
    return m_bStopValidationOnError;
  }

  /**
   * Set the "stop on validation" flag for this executor. If the flag is set, no
   * further validation will be performed.
   *
   * @param bStopValidationOnError
   *        true to stop validation on error, false to
   *        continue anyway.
   * @return this for chaining
   */
  @Nonnull
  public final IMPLTYPE setStopValidationOnError (final boolean bStopValidationOnError)
  {
    m_bStopValidationOnError = bStopValidationOnError;
    return thisAsT ();
  }

  @Override
  public boolean equals (final Object o)
  {
    if (o == this)
      return true;
    if (o == null || !getClass ().equals (o.getClass ()))
      return false;
    final AbstractValidationExecutor  rhs = (AbstractValidationExecutor ) o;
    return m_aValidationArtefact.equals (rhs.m_aValidationArtefact);
  }

  @Override
  public int hashCode ()
  {
    return new HashCodeGenerator (this).append (m_aValidationArtefact).getHashCode ();
  }

  @Override
  public String toString ()
  {
    return new ToStringGenerator (this).append ("ValidationArtefact", m_aValidationArtefact)
                                       .append ("StopValidationOnError", m_bStopValidationOnError)
                                       .getToString ();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy