diff --git a/README.md b/README.md index 3483a4d0..18d2b3c4 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,9 @@ Please ensure that your stack size is at least 1MB (for Saxon). Using the Oracle # News and noteworthy +* v10.0.4 - work in progress + * Added new interface `IValidationExecutorSetMutable` + * Added new class `ValidationExecutorSetAlias` * v10.0.3 - 2024-12-01 * Added default XML serialization of validation results * Added new `EValidationBaseType` entries diff --git a/phive-api/src/main/java/com/helger/phive/api/executorset/IValidationExecutorSetMutable.java b/phive-api/src/main/java/com/helger/phive/api/executorset/IValidationExecutorSetMutable.java new file mode 100644 index 00000000..963ee153 --- /dev/null +++ b/phive-api/src/main/java/com/helger/phive/api/executorset/IValidationExecutorSetMutable.java @@ -0,0 +1,54 @@ +package com.helger.phive.api.executorset; + +import javax.annotation.Nonnull; + +import com.helger.commons.annotation.ChangeNextMajorRelease; +import com.helger.commons.state.EChange; +import com.helger.phive.api.executor.IValidationExecutor; +import com.helger.phive.api.source.IValidationSource; + +/** + * Define a common interface for {@link IValidationExecutorSet} with modifying + * methods. + * + * @author Philip Helger + * @param + * The validation source type to be used. + * @since 10.0.4 + */ +public interface IValidationExecutorSetMutable extends + IValidationExecutorSet +{ + /** + * Add a single executor. + * + * @param aExecutor + * The executor to be added. May not be null. + * @return this for chaining + */ + @Nonnull + IValidationExecutorSetMutable addExecutor (@Nonnull IValidationExecutor aExecutor); + + /** + * Set the cache status to all contained validation executors, that implement + * the IValidationExecutorCacheSupport interface. + * + * @param bCache + * true to enable caching, false to disable + * it. + */ + @ChangeNextMajorRelease ("Change return type to this type") + void setValidationExecutorDoCache (boolean bCache); + + /** + * As some {@link IValidationExecutor} instances may contain a hard reference + * to a {@link ClassLoader} this methods removes all executors and allows for + * them to be garbage collected.
+ * New executors may be added afterwards but this method is mainly meant for + * safe cleanup. + * + * @return {@link EChange} + */ + @Nonnull + EChange removeAllExecutors (); +} diff --git a/phive-api/src/main/java/com/helger/phive/api/executorset/ValidationExecutorSet.java b/phive-api/src/main/java/com/helger/phive/api/executorset/ValidationExecutorSet.java index 015b41df..60c22034 100644 --- a/phive-api/src/main/java/com/helger/phive/api/executorset/ValidationExecutorSet.java +++ b/phive-api/src/main/java/com/helger/phive/api/executorset/ValidationExecutorSet.java @@ -45,7 +45,8 @@ * The validation source type to be used. */ @NotThreadSafe -public class ValidationExecutorSet implements IValidationExecutorSet +public class ValidationExecutorSet implements + IValidationExecutorSetMutable { private final DVRCoordinate m_aVESID; private final String m_sDisplayName; @@ -103,13 +104,6 @@ public final IValidationExecutorSetStatus getStatus () return m_aStatus; } - /** - * Add a single executor. - * - * @param aExecutor - * The executor to be added. May not be null. - * @return this for chaining - */ @Nonnull public ValidationExecutorSet addExecutor (@Nonnull final IValidationExecutor aExecutor) { @@ -125,15 +119,6 @@ public void setValidationExecutorDoCache (final boolean bCache) ((IValidationExecutorCacheSupport) aExecutor).setCacheArtefact (bCache); } - /** - * As some {@link IValidationExecutor} instances may contain a hard reference - * to a {@link ClassLoader} this methods removes all executors and allows for - * them to be garbage collected.
- * New executors may be added afterwards but this method is mainly meant for - * safe cleanup. - * - * @return {@link EChange} - */ @Nonnull public EChange removeAllExecutors () { diff --git a/phive-api/src/main/java/com/helger/phive/api/executorset/ValidationExecutorSetAlias.java b/phive-api/src/main/java/com/helger/phive/api/executorset/ValidationExecutorSetAlias.java new file mode 100644 index 00000000..a1b257a6 --- /dev/null +++ b/phive-api/src/main/java/com/helger/phive/api/executorset/ValidationExecutorSetAlias.java @@ -0,0 +1,149 @@ +/* + * 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.executorset; + +import java.util.Iterator; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.NotThreadSafe; + +import com.helger.commons.ValueEnforcer; +import com.helger.commons.annotation.Nonempty; +import com.helger.commons.annotation.ReturnsMutableCopy; +import com.helger.commons.annotation.ReturnsMutableObject; +import com.helger.commons.collection.impl.ICommonsList; +import com.helger.commons.hashcode.HashCodeGenerator; +import com.helger.commons.state.EChange; +import com.helger.commons.string.ToStringGenerator; +import com.helger.diver.api.coord.DVRCoordinate; +import com.helger.phive.api.executor.IValidationExecutor; +import com.helger.phive.api.executorset.status.IValidationExecutorSetStatus; +import com.helger.phive.api.source.IValidationSource; + +/** + * An implementation of {@link IValidationExecutorSet} that acts as an alias to + * another {@link IValidationExecutorSet} with a different ID. + * + * @author Philip Helger + * @param + * The validation source type to be used. + * @since 10.0.4 + */ +@NotThreadSafe +public class ValidationExecutorSetAlias implements + IValidationExecutorSetMutable +{ + private final DVRCoordinate m_aVESID; + private final String m_sDisplayName; + private final IValidationExecutorSetMutable m_aVES; + + public ValidationExecutorSetAlias (@Nonnull final DVRCoordinate aVESID, + @Nonnull @Nonempty final String sDisplayName, + @Nonnull final IValidationExecutorSetMutable aVES) + { + ValueEnforcer.notNull (aVESID, "ID"); + ValueEnforcer.notEmpty (sDisplayName, "DisplayName"); + ValueEnforcer.notNull (aVES, "Status"); + m_aVESID = aVESID; + m_sDisplayName = sDisplayName; + m_aVES = aVES; + } + + @Nonnull + public final DVRCoordinate getID () + { + return m_aVESID; + } + + @Nonnull + @Nonempty + public final String getDisplayName () + { + return m_sDisplayName; + } + + @Nonnull + public final Iterator > iterator () + { + return m_aVES.iterator (); + } + + @Nonnull + @ReturnsMutableObject + public final ICommonsList > executors () + { + return m_aVES.executors (); + } + + @Nonnull + @ReturnsMutableCopy + public final ICommonsList > getAllExecutors () + { + return m_aVES.getAllExecutors (); + } + + @Nonnull + public final IValidationExecutorSetStatus getStatus () + { + return m_aVES.getStatus (); + } + + @Nonnull + public ValidationExecutorSetAlias addExecutor (@Nonnull final IValidationExecutor aExecutor) + { + m_aVES.addExecutor (aExecutor); + return this; + } + + public void setValidationExecutorDoCache (final boolean bCache) + { + m_aVES.setValidationExecutorDoCache (bCache); + } + + @Nonnull + public EChange removeAllExecutors () + { + return m_aVES.removeAllExecutors (); + } + + @Override + public boolean equals (final Object o) + { + if (o == this) + return true; + if (o == null || !getClass ().equals (o.getClass ())) + return false; + final ValidationExecutorSetAlias rhs = (ValidationExecutorSetAlias ) o; + return m_aVESID.equals (rhs.m_aVESID) && m_sDisplayName.equals (rhs.m_sDisplayName) && m_aVES.equals (rhs.m_aVES); + } + + @Override + public int hashCode () + { + return new HashCodeGenerator (this).append (m_aVESID).append (m_sDisplayName).append (m_aVES).getHashCode (); + } + + @Override + public String toString () + { + return ToStringGenerator.getDerived (super.toString ()) + .append ("ID", m_aVESID) + .append ("DisplayName", m_sDisplayName) + .append ("VES", m_aVES) + .getToString (); + } +}