-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new class ValidationExecutorSetAlias
- Loading branch information
Showing
4 changed files
with
208 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
phive-api/src/main/java/com/helger/phive/api/executorset/IValidationExecutorSetMutable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <SOURCETYPE> | ||
* The validation source type to be used. | ||
* @since 10.0.4 | ||
*/ | ||
public interface IValidationExecutorSetMutable <SOURCETYPE extends IValidationSource> extends | ||
IValidationExecutorSet <SOURCETYPE> | ||
{ | ||
/** | ||
* Add a single executor. | ||
* | ||
* @param aExecutor | ||
* The executor to be added. May not be <code>null</code>. | ||
* @return this for chaining | ||
*/ | ||
@Nonnull | ||
IValidationExecutorSetMutable <SOURCETYPE> addExecutor (@Nonnull IValidationExecutor <SOURCETYPE> aExecutor); | ||
|
||
/** | ||
* Set the cache status to all contained validation executors, that implement | ||
* the <code>IValidationExecutorCacheSupport</code> interface. | ||
* | ||
* @param bCache | ||
* <code>true</code> to enable caching, <code>false</code> 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.<br> | ||
* New executors may be added afterwards but this method is mainly meant for | ||
* safe cleanup. | ||
* | ||
* @return {@link EChange} | ||
*/ | ||
@Nonnull | ||
EChange removeAllExecutors (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
phive-api/src/main/java/com/helger/phive/api/executorset/ValidationExecutorSetAlias.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <SOURCETYPE> | ||
* The validation source type to be used. | ||
* @since 10.0.4 | ||
*/ | ||
@NotThreadSafe | ||
public class ValidationExecutorSetAlias <SOURCETYPE extends IValidationSource> implements | ||
IValidationExecutorSetMutable <SOURCETYPE> | ||
{ | ||
private final DVRCoordinate m_aVESID; | ||
private final String m_sDisplayName; | ||
private final IValidationExecutorSetMutable <SOURCETYPE> m_aVES; | ||
|
||
public ValidationExecutorSetAlias (@Nonnull final DVRCoordinate aVESID, | ||
@Nonnull @Nonempty final String sDisplayName, | ||
@Nonnull final IValidationExecutorSetMutable <SOURCETYPE> 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 <IValidationExecutor <SOURCETYPE>> iterator () | ||
{ | ||
return m_aVES.iterator (); | ||
} | ||
|
||
@Nonnull | ||
@ReturnsMutableObject | ||
public final ICommonsList <IValidationExecutor <SOURCETYPE>> executors () | ||
{ | ||
return m_aVES.executors (); | ||
} | ||
|
||
@Nonnull | ||
@ReturnsMutableCopy | ||
public final ICommonsList <IValidationExecutor <SOURCETYPE>> getAllExecutors () | ||
{ | ||
return m_aVES.getAllExecutors (); | ||
} | ||
|
||
@Nonnull | ||
public final IValidationExecutorSetStatus getStatus () | ||
{ | ||
return m_aVES.getStatus (); | ||
} | ||
|
||
@Nonnull | ||
public ValidationExecutorSetAlias <SOURCETYPE> addExecutor (@Nonnull final IValidationExecutor <SOURCETYPE> 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 (); | ||
} | ||
} |