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

org.molgenis.data.support.StaticEntity Maven / Gradle / Ivy

There is a newer version: 8.4.5
Show newest version
package org.molgenis.data.support;

import static java.util.Objects.requireNonNull;

import java.time.Instant;
import java.time.LocalDate;
import org.molgenis.data.Entity;
import org.molgenis.data.meta.model.EntityType;

/** Base class for entities defined in pre-existing Java classes */
public abstract class StaticEntity implements Entity {
  private Entity entity;

  public StaticEntity(Entity entity) {
    this.entity = requireNonNull(entity);
  }

  public StaticEntity(EntityType entityType) {
    this.entity = new DynamicEntity(entityType);
  }

  public StaticEntity(Object id, EntityType entityType) {
    this(entityType);
    setIdValue(id);
  }

  protected StaticEntity() {}

  protected void init(Entity entity) {
    this.entity = requireNonNull(entity);
  }

  @Override
  public Object get(String attributeName) {
    return entity.get(attributeName);
  }

  @Override
  public Iterable getAttributeNames() {
    return entity.getAttributeNames();
  }

  @Override
  public Boolean getBoolean(String attributeName) {
    return entity.getBoolean(attributeName);
  }

  @Override
  public Double getDouble(String attributeName) {
    return entity.getDouble(attributeName);
  }

  @Override
  public Iterable getEntities(String attributeName) {
    return entity.getEntities(attributeName);
  }

  @Override
  public  Iterable getEntities(String attributeName, Class clazz) {
    return entity.getEntities(attributeName, clazz);
  }

  @Override
  public Entity getEntity(String attributeName) {
    return entity.getEntity(attributeName);
  }

  @Override
  public  E getEntity(String attributeName, Class clazz) {
    return entity.getEntity(attributeName, clazz);
  }

  public EntityType getEntityType() {
    return entity.getEntityType();
  }

  @Override
  public Object getIdValue() {
    return entity.getIdValue();
  }

  @Override
  public Integer getInt(String attributeName) {
    if (null == entity) return null;
    return entity.getInt(attributeName);
  }

  @Override
  public Object getLabelValue() {
    return entity.getLabelValue();
  }

  @Override
  public Long getLong(String attributeName) {
    return entity.getLong(attributeName);
  }

  @Override
  public String getString(String attributeName) {
    return entity.getString(attributeName);
  }

  @Override
  public LocalDate getLocalDate(String attributeName) {
    return entity.getLocalDate(attributeName);
  }

  @Override
  public Instant getInstant(String attributeName) {
    return entity.getInstant(attributeName);
  }

  @Override
  public void set(String attributeName, Object value) {
    entity.set(attributeName, value);
  }

  @Override
  public void set(Entity values) {
    entity.set(values);
  }

  @Override
  public void setIdValue(Object id) {
    entity.setIdValue(id);
  }

  @Override
  public String toString() {
    // TODO modify to 'return entity.toString()' once protected protected StaticEntity() constructor
    // has been removed
    return entity != null ? entity.toString() : super.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy