io.github.mmm.entity.property.link.LinkPropertyBuilder 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.entity.property.link;
import java.util.function.Function;
import io.github.mmm.entity.bean.EntityBean;
import io.github.mmm.entity.id.Id;
import io.github.mmm.entity.link.Link;
import io.github.mmm.property.AttributeReadOnly;
import io.github.mmm.property.PropertyMetadata;
import io.github.mmm.property.builder.PropertyBuilder;
import io.github.mmm.validation.main.ValidatorBuilderObject;
/**
* {@link PropertyBuilder} for {@link LinkProperty}.
*
* @param the generic type of the {@link io.github.mmm.entity.bean.EntityBean entity}.
* @since 1.0.0
*/
public final class LinkPropertyBuilder extends
PropertyBuilder, LinkProperty, ValidatorBuilderObject, LinkPropertyBuilder>, LinkPropertyBuilder> {
private Class entityClass;
private Function, E> resolver;
/**
* The constructor.
*
* @param lock the {@link #getLock() lock}.
*/
public LinkPropertyBuilder(AttributeReadOnly lock) {
this(lock, null);
}
/**
* The constructor.
*
* @param lock the {@link #getLock() lock}.
* @param entityClass the {@link Class} reflecting the entity.
*/
public LinkPropertyBuilder(AttributeReadOnly lock, Class entityClass) {
super(lock);
this.entityClass = entityClass;
}
/**
* @param entityType the {@link Class} reflecting the entity.
* @return this builder itself ({@code this}) for fluent API calls.
*/
public LinkPropertyBuilder entityClass(Class entityType) {
this.entityClass = entityType;
return this;
}
/**
* @param entityResolver the {@link Function} to load {@link io.github.mmm.entity.Entity entities} by their
* {@link Id}.
* @return this builder itself ({@code this}) for fluent API calls.
*/
public LinkPropertyBuilder resolver(Function, E> entityResolver) {
this.resolver = entityResolver;
return this;
}
@Override
protected ValidatorBuilderObject, LinkPropertyBuilder> createValidatorBuilder() {
return new ValidatorBuilderObject<>(this);
}
@Override
protected LinkProperty build(String name, PropertyMetadata> metadata) {
return new LinkProperty<>(name, this.entityClass, metadata, this.resolver);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy