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

io.oasp.module.basic.common.api.reference.IdRef Maven / Gradle / Ivy

Go to download

Basic code for common usage (such as base classes for transfer objects) of the Open Application Standard Platform for Java (OASP4J).

The newest version!
package io.oasp.module.basic.common.api.reference;

import net.sf.mmm.util.entity.api.GenericEntity;

/**
 * A {@link Ref} using {@link Long} values as {@link #getId() ID}.
 *
 * @param  generic type of the referenced {@link net.sf.mmm.util.entity.api.Entity}.
 */
public class IdRef extends GenericIdRef {

  private static final long serialVersionUID = 1L;

  /**
   * The constructor.
   *
   * @param id the {@link #getId() ID}.
   */
  public IdRef(Long id) {

    super(id);
  }

  /**
   * @param  generic type of the referenced {@link GenericEntity}.
   * @param entity the {@link GenericEntity} to reference.
   * @return the {@link IdRef} pointing to the given {@link GenericEntity} or {@code null} if the {@link GenericEntity}
   *         or its {@link GenericEntity#getId() ID} is {@code null}.
   */
  public static > IdRef of(E entity) {

    if (entity == null) {
      return null;
    }
    return of(entity.getId());
  }

  /**
   * @param  generic type of the referenced {@link GenericEntity}.
   * @param id the {@link #getId() ID} to wrap.
   * @return the {@link IdRef} pointing to an entity with the specified {@link #getId() ID} or {@code null} if the given
   *         {@code ID} was {@code null}.
   */
  public static  IdRef of(Long id) {

    if (id == null) {
      return null;
    }
    return new IdRef<>(id);
  }

  /**
   * @param  generic type of the referenced {@link GenericEntity}.
   * @param id the {@link #getId() ID} to wrap.
   * @return the {@link IdRef} pointing to an entity with the specified {@link #getId() ID}.
   */
  public static  IdRef of(long id) {

    return new IdRef<>(Long.valueOf(id));
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy