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

io.github.mmm.property.builder.container.MapPropertyBuilder Maven / Gradle / Ivy

/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0 */
package io.github.mmm.property.builder.container;

import java.util.Map;

import io.github.mmm.property.AttributeReadOnly;
import io.github.mmm.property.Property;
import io.github.mmm.property.PropertyMetadata;
import io.github.mmm.property.builder.PropertyBuilder;
import io.github.mmm.property.container.map.MapProperty;
import io.github.mmm.property.object.SimpleProperty;
import io.github.mmm.validation.collection.ValidatorBuilderMap;

/**
 * {@link ProcessBuilder} for {@link MapProperty}.
 *
 * @param  type of the {@link Map#containsKey(Object) keys}.
 * @param  type of the {@link Map#containsValue(Object) values}.
 * @since 1.0.0
 * @see PropertyBuilder#asMap()
 */
public class MapPropertyBuilder extends
    PropertyBuilder, MapProperty, ValidatorBuilderMap>, MapPropertyBuilder> {

  private SimpleProperty keyProperty;

  private Property valueProperty;

  /**
   * The constructor.
   *
   * @param lock the {@link #getLock() lock}.
   */
  public MapPropertyBuilder(AttributeReadOnly lock) {

    this(lock, null, null);
  }

  /**
   * The constructor.
   *
   * @param lock the {@link #getLock() lock}.
   * @param valueProperty the {@link MapProperty#getValueProperty() value property}.
   */
  public MapPropertyBuilder(AttributeReadOnly lock, Property valueProperty) {

    this(lock, null, valueProperty);
  }

  /**
   * The constructor.
   *
   * @param lock the {@link #getLock() lock}.
   * @param keyProperty the {@link MapProperty#getKeyProperty() key property}.
   * @param valueProperty the {@link MapProperty#getValueProperty() value property}.
   */
  public MapPropertyBuilder(AttributeReadOnly lock, SimpleProperty keyProperty, Property valueProperty) {

    super(lock);
    this.keyProperty = keyProperty;
    this.valueProperty = valueProperty;
  }

  /**
   * @param property the {@link MapProperty#getKeyProperty() key property}.
   * @return this builder itself ({@code this}) for fluent API calls.
   */
  public MapPropertyBuilder keyProperty(SimpleProperty property) {

    this.keyProperty = property;
    return this;
  }

  /**
   * @param property the {@link MapProperty#getValueProperty() value property}.
   * @return this builder itself ({@code this}) for fluent API calls.
   */
  public MapPropertyBuilder valueProperty(Property property) {

    this.valueProperty = property;
    return this;
  }

  @Override
  protected ValidatorBuilderMap> createValidatorBuilder() {

    return new ValidatorBuilderMap<>(this);
  }

  @Override
  protected MapProperty build(String name, PropertyMetadata> metadata) {

    return new MapProperty<>(name, this.keyProperty, this.valueProperty, metadata);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy