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

com.anaptecs.jeaf.services.scheduling.SchedulingInfo Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
/*
 * anaptecs GmbH, Ricarda-Huch-Str. 71, 72760 Reutlingen, Germany
 * 
 * Copyright 2004 - 2019. All rights reserved.
 */
package com.anaptecs.jeaf.services.scheduling;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import com.anaptecs.jeaf.core.api.AbstractObjectID;
import com.anaptecs.jeaf.core.api.Identifiable;
import com.anaptecs.jeaf.core.api.MessageConstants;
import com.anaptecs.jeaf.core.api.ServiceObject;
import com.anaptecs.jeaf.core.api.ServiceObjectID;
import com.anaptecs.jeaf.tools.api.Tools;
import com.anaptecs.jeaf.xfun.api.XFun;
import com.anaptecs.jeaf.xfun.api.checks.Check;

/**
 * This class describes additional information that may be useful for the scheduled service to do the right things when
 * triggered. The information are optional and will be passed to the executed service. In order to provide a flexible
 * mechanism to pass objects the called service, all SchedulingInfo objects will be stored by the Scheduling Service as
 * serialized objects within the database. This allows that there are task specific subclasses of this class.
 * 
 * @author JEAF Generator
 * @version JEAF Release 1.4.x
 */
public class SchedulingInfo implements ServiceObject, Identifiable {
  /**
   * Default serial version uid.
   */
  private static final long serialVersionUID = 1L;

  /**
   * Constant for the name of attribute "parameters".
   */
  public static final String PARAMETERS = "parameters";

  /**
   * Reference to the identifier of this object. The reference may be null since an id is not mandatory.
   */
  private final ServiceObjectID objectID;

  /**
   * List contains all key value pairs that should be passed to a service when the task will be executed.
   */
  private Set parameters = new HashSet();

  /**
   * Initialize object using the passed builder.
   * 
   * @param pBuilder Builder that should be used to initialize this object. The parameter must not be null.
   */
  protected SchedulingInfo( Builder pBuilder ) {
    // Ensure that builder is not null.
    Check.checkInvalidParameterNull(pBuilder, "pBuilder");
    // Read object ID.
    AbstractObjectID lObjectID = pBuilder.objectID;
    if (lObjectID != null) {
      objectID = new ServiceObjectID(pBuilder.objectID);
    }
    else {
      objectID = null;
    }
    // Read attribute values from builder.
    if (pBuilder.parameters != null) {
      parameters.addAll(pBuilder.parameters);
    }
  }

  /**
   * Class implements builder to create a new instance of class SchedulingInfo. As the class has readonly attributes or
   * associations instances can not be created directly. Instead this builder class has to be used.
   */
  public static class Builder {
    /**
     * Reference to the identifier of this object. The reference may be null since an id is not mandatory.
     */
    private AbstractObjectID objectID;

    /**
     * List contains all key value pairs that should be passed to a service when the task will be executed.
     */
    private Set parameters;

    /**
     * Use {@link #newBuilder()} instead of private constructor to create new builder.
     */
    protected Builder( ) {
    }

    /**
     * Use {@link #newBuilder(SchedulingInfo)} instead of private constructor to create new builder.
     */
    protected Builder( SchedulingInfo pObject ) {
      if (pObject != null) {
        // Read attribute values from passed object.
        objectID = pObject.objectID;
        parameters = pObject.parameters;
      }
    }

    /**
     * Method returns a new builder.
     * 
     * @return {@link Builder} New builder that can be used to create new ImmutablePOJOParent objects.
     */
    public static Builder newBuilder( ) {
      return new Builder();
    }

    /**
     * Method creates a new builder and initialize it with the data from the passed object.
     * 
     * @param pObject Object that should be used to initialize the builder. The parameter may be null.
     * @return {@link Builder} New builder that can be used to create new SchedulingInfo objects. The method never
     * returns null.
     */
    public static Builder newBuilder( SchedulingInfo pObject ) {
      return new Builder(pObject);
    }

    /**
     * Method sets the identifier for the object created using the builder. The reference may be null since an id is not
     * mandatory.
     */
    public Builder setID( AbstractObjectID pObjectID ) {
      objectID = pObjectID;
      return this;
    }

    /**
     * Method sets the association "parameters". List contains all key value pairs that should be passed to a service
     * when the task will be executed.
     * 
     * @param pParameters Collection with objects to which the association should be set.
     */
    public Builder setParameters( Set pParameters ) {
      // To ensure immutability we have to copy the content of the passed collection.
      if (pParameters != null) {
        parameters = new HashSet(pParameters);
      }
      else {
        parameters = null;
      }
      return this;
    }

    /**
     * Method creates a new instance of class SchedulingInfo. The object will be initialized with the values of the
     * builder.
     * 
     * @return SchedulingInfo Created object. The method never returns null.
     */
    public SchedulingInfo build( ) {
      return new SchedulingInfo(this);
    }

    /**
     * Method creates a new instance of class SchedulingInfo. The object will be initialized with the values of the
     * builder.
     * 
     * @param pValidate Parameter defines if the created POJO should be validated using Java Validation.
     * @return SchedulingInfo Created object. The method never returns null.
     */
    public SchedulingInfo build( boolean pValidate ) {
      SchedulingInfo lPOJO = this.build();
      if (pValidate == true) {
        Tools.getValidationTools().validateObject(lPOJO);
      }
      return lPOJO;
    }
  }

  /**
   * Method returns the id of this object.
   * 
   * @return {@link ServiceObjectID} ID of this object. Since an object must not have an id the method may also return
   * null.
   */
  @Override
  public final ServiceObjectID getID( ) {
    return objectID;
  }

  /**
   * Method returns the unversioned object id of this object.
   * 
   * @return {@link ServiceObjectID} ID of this object. Since an object must not have an id the method may also return
   * null.
   */
  @Override
  public final ServiceObjectID getUnversionedID( ) {
    ServiceObjectID lUnversionedID;
    if (objectID != null) {
      lUnversionedID = objectID.getUnversionedObjectID();
    }
    else {
      lUnversionedID = null;
    }
    return lUnversionedID;
  }

  /**
   * Method returns the association "parameters". List contains all key value pairs that should be passed to a service
   * when the task will be executed.
   *
   * @return Collection All KeyValuePair objects that belong to the association "parameters". The method never returns
   * null and the returned collection is unmodifiable.
   */
  public Set getParameters( ) {
    // Return all KeyValuePair objects as unmodifiable collection.
    return Collections.unmodifiableSet(parameters);
  }

  /**
   * Method sets the association "parameters" to the passed collection. All objects that formerly were part of the
   * association will be removed from it. List contains all key value pairs that should be passed to a service when the
   * task will be executed.
   * 
   * @param pParameters Collection with objects to which the association should be set. The parameter must not be null.
   */
  void setParameters( Set pParameters ) {
    // Check of parameter is not required.
    // Remove all objects from association "parameters".
    this.clearParameters();
    // If the association is null, removing all entries is sufficient.
    if (pParameters != null) {
      parameters = new HashSet(pParameters);
    }
  }

  /**
   * Method adds the passed KeyValuePair object to the association "parameters". List contains all key value pairs that
   * should be passed to a service when the task will be executed.
   * 
   * @param pParameters Object that should be added to the association "parameters". The parameter must not be null.
   */
  public void addToParameters( KeyValuePair pParameters ) {
    // Check parameter "pParameters" for invalid value null.
    Check.checkInvalidParameterNull(pParameters, "pParameters");
    // Add passed object to collection of associated KeyValuePair objects.
    parameters.add(pParameters);
  }

  /**
   * Method adds all passed objects to the association "parameters". List contains all key value pairs that should be
   * passed to a service when the task will be executed.
   * 
   * @param pParameters Collection with all objects that should be added to the association "parameters". The parameter
   * must not be null.
   */
  public void addToParameters( Collection pParameters ) {
    // Check parameter "pParameters" for invalid value null.
    Check.checkInvalidParameterNull(pParameters, "pParameters");
    // Add all passed objects.
    for (KeyValuePair lNextObject : pParameters) {
      this.addToParameters(lNextObject);
    }
  }

  /**
   * Method removes the passed KeyValuePair object from the association "parameters". List contains all key value pairs
   * that should be passed to a service when the task will be executed.
   * 
   * @param pParameters Object that should be removed from the association "parameters". The parameter must not be null.
   */
  public void removeFromParameters( KeyValuePair pParameters ) {
    // Check parameter for invalid value null.
    Check.checkInvalidParameterNull(pParameters, "pParameters");
    // Remove passed object from collection of associated KeyValuePair objects.
    parameters.remove(pParameters);
  }

  /**
   * Method removes all objects from the association "parameters". List contains all key value pairs that should be
   * passed to a service when the task will be executed.
   */
  public void clearParameters( ) {
    // Remove all objects from association "parameters".
    Collection lParameters = new HashSet(parameters);
    Iterator lIterator = lParameters.iterator();
    while (lIterator.hasNext()) {
      this.removeFromParameters(lIterator.next());
    }
  }

  /**
   * Method returns a StringBuilder that can be used to create a String representation of this object. the returned
   * StringBuilder also takes care about attributes of super classes.
   *
   * @return {@link StringBuilder} StringBuilder representing this object. The method never returns null.
   */
  protected StringBuilder toStringBuilder( ) {
    StringBuilder lBuilder = new StringBuilder(256);
    lBuilder.append(XFun.getMessageRepository().getMessage(MessageConstants.OBJECT_INFO, this.getClass().getName()));
    lBuilder.append('\n');
    lBuilder.append(XFun.getMessageRepository().getMessage(MessageConstants.OBJECT_ATTRIBUTES_SECTION));
    lBuilder.append('\n');
    return lBuilder;
  }

  /**
   * Method creates a new String with the values of all attributes of this class. All references to other objects will
   * be ignored.
   * 
   * @return {@link String} String representation of this object. The method never returns null.
   */
  @Override
  public String toString( ) {
    return this.toStringBuilder().toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy