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

com.anaptecs.jeaf.services.scheduling.KeyValuePair 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 com.anaptecs.jeaf.core.api.MessageConstants;
import com.anaptecs.jeaf.core.api.ServiceObject;
import com.anaptecs.jeaf.tools.api.Tools;
import com.anaptecs.jeaf.xfun.api.XFun;
import com.anaptecs.jeaf.xfun.api.checks.Check;

/**
 * Class describes a simple key value pair that can be passed to a service.
 * 
 * @author JEAF Generator
 * @version JEAF Release 1.4.x
 */
public class KeyValuePair implements ServiceObject {
  /**
   * Default serial version uid.
   */
  private static final long serialVersionUID = 1L;

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

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

  /**
   * Key of the object. The attribute must not be null
   */
  private String key;

  /**
   * Value of the object. The attribute may be null.
   */
  private String value;

  /**
   * Initialize object using the passed builder.
   * 
   * @param pBuilder Builder that should be used to initialize this object. The parameter must not be null.
   */
  protected KeyValuePair( Builder pBuilder ) {
    // Ensure that builder is not null.
    Check.checkInvalidParameterNull(pBuilder, "pBuilder");
    // Read attribute values from builder.
    key = pBuilder.key;
    value = pBuilder.value;
  }

  /**
   * Class implements builder to create a new instance of class KeyValuePair. 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 {
    /**
     * Key of the object. The attribute must not be null
     */
    private String key;

    /**
     * Value of the object. The attribute may be null.
     */
    private String value;

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

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

    /**
     * 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 KeyValuePair objects. The method never returns
     * null.
     */
    public static Builder newBuilder( KeyValuePair pObject ) {
      return new Builder(pObject);
    }

    /**
     * Method sets the attribute "key". Key of the object. The attribute must not be null
     * 
     * @param pKey Value to which the attribute "key" should be set.
     */
    public Builder setKey( String pKey ) {
      // Assign value to attribute
      key = pKey;
      return this;
    }

    /**
     * Method sets the attribute "value". Value of the object. The attribute may be null.
     * 
     * @param pValue Value to which the attribute "value" should be set.
     */
    public Builder setValue( String pValue ) {
      // Assign value to attribute
      value = pValue;
      return this;
    }

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

    /**
     * Method creates a new instance of class KeyValuePair. 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 KeyValuePair Created object. The method never returns null.
     */
    public KeyValuePair build( boolean pValidate ) {
      KeyValuePair lPOJO = this.build();
      if (pValidate == true) {
        Tools.getValidationTools().validateObject(lPOJO);
      }
      return lPOJO;
    }
  }

  /**
   * Method returns the attribute "key". Key of the object. The attribute must not be null
   * 
   * @return String Value to which the attribute "key" is set.
   */
  public String getKey( ) {
    return key;
  }

  /**
   * Method sets the attribute "key". Key of the object. The attribute must not be null
   * 
   * @param pKey Value to which the attribute "key" should be set.
   */
  public void setKey( String pKey ) {
    // Assign value to attribute
    key = pKey;
  }

  /**
   * Method returns the attribute "value". Value of the object. The attribute may be null.
   * 
   * @return String Value to which the attribute "value" is set.
   */
  public String getValue( ) {
    return value;
  }

  /**
   * Method sets the attribute "value". Value of the object. The attribute may be null.
   * 
   * @param pValue Value to which the attribute "value" should be set.
   */
  public void setValue( String pValue ) {
    // Assign value to attribute
    value = pValue;
  }

  /**
   * 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');
    lBuilder.append(XFun.getMessageRepository().getMessage(MessageConstants.OBJECT_ATTRIBUTE, "key", "" + key));
    lBuilder.append('\n');
    lBuilder.append(XFun.getMessageRepository().getMessage(MessageConstants.OBJECT_ATTRIBUTE, "value", "" + value));
    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