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

io.polygenesis.abstraction.data.DataMap Maven / Gradle / Ivy

/*-
 * ==========================LICENSE_START=================================
 * PolyGenesis Platform
 * ========================================================================
 * Copyright (C) 2015 - 2019 Christos Tsakostas, OREGOR LTD
 * ========================================================================
 * 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.
 * ===========================LICENSE_END==================================
 */

package io.polygenesis.abstraction.data;

import io.polygenesis.commons.valueobjects.VariableName;
import java.util.Objects;

/**
 * The type Data map.
 *
 * @author Christos Tsakostas
 */
public class DataMap extends AbstractData {

  // ===============================================================================================
  // STATE
  // ===============================================================================================

  private final Data key;
  private final Data value;

  // ===============================================================================================
  // STATIC
  // ===============================================================================================

  /**
   * Of data map.
   *
   * @param key the key
   * @param value the value
   * @param variableName the variable name
   * @return the data map
   */
  public static DataMap of(Data key, Data value, String variableName) {
    return new DataMap(
        new VariableName(variableName), DataPurpose.any(), DataValidator.empty(), key, value);
  }

  // ===============================================================================================
  // CONSTRUCTOR(S)
  // ===============================================================================================

  /**
   * Instantiates a new Data map.
   *
   * @param variableName the variable name
   * @param dataPurpose the data business type
   * @param dataValidator the data validator
   * @param key the key
   * @param value the value
   */
  public DataMap(
      VariableName variableName,
      DataPurpose dataPurpose,
      DataValidator dataValidator,
      Data key,
      Data value) {
    super(DataPrimaryType.MAP, variableName, dataPurpose, dataValidator, DataSourceType.DEFAULT);
    this.key = key;
    this.value = value;
  }

  // ===============================================================================================
  // GETTERS
  // ===============================================================================================

  /**
   * Gets key.
   *
   * @return the key
   */
  public Data getKey() {
    return key;
  }

  /**
   * Gets value.
   *
   * @return the value
   */
  public Data getValue() {
    return value;
  }

  // ===============================================================================================
  // ABSTRACT IMPLEMENTATIONS
  // ===============================================================================================

  @Override
  public String getDataType() {
    return DataPrimaryType.MAP.name();
  }

  // ===============================================================================================
  // OVERRIDES
  // ===============================================================================================

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    if (!super.equals(o)) {
      return false;
    }
    DataMap dataMap = (DataMap) o;
    return Objects.equals(key, dataMap.key) && Objects.equals(value, dataMap.value);
  }

  @Override
  public int hashCode() {
    return Objects.hash(super.hashCode(), key, value);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy