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

io.spotnext.spring.web.http.Payload Maven / Gradle / Ivy

There is a newer version: 1.0.21-BETA-20190513
Show newest version
package io.spotnext.spring.web.http;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

/**
 * 

Payload class.

* * @author mojo2012 * @version 1.0 * @since 1.0 */ @JsonInclude(value = Include.NON_NULL) public class Payload { final protected List errors = new ArrayList<>(); final protected List warnings = new ArrayList<>(); protected T data; /** *

of.

* * @param data a T object. * @param a T object. * @return a {@link io.spotnext.spring.web.http.Payload} object. */ public static Payload of(final T data) { return new Payload<>(data); } /** *

of.

* * @param data a {@link java.util.Optional} object. * @param a T object. * @return a {@link io.spotnext.spring.web.http.Payload} object. */ public static Payload of(final Optional data) { return new Payload<>(data.orElse(null)); } /** *

empty.

* * @param a T object. * @return a {@link io.spotnext.spring.web.http.Payload} object. */ public static Payload empty() { return new Payload<>(); } /** *

Constructor for Payload.

*/ public Payload() { // no data } /** *

Constructor for Payload.

* * @param data a T object. */ public Payload(final T data) { this.data = data; } /** *

Getter for the field data.

* * @return a T object. */ public T getData() { return data; } /** *

Setter for the field data.

* * @param data a T object. */ public void setData(final T data) { this.data = data; } /** *

Getter for the field errors.

* * @return a {@link java.util.List} object. */ public List getErrors() { return errors; } /** *

Getter for the field warnings.

* * @return a {@link java.util.List} object. */ public List getWarnings() { return warnings; } /** *

addError.

* * @param error a {@link io.spotnext.spring.web.http.Status} object. */ public void addError(final Status error) { this.errors.add(error); } /** *

addWarning.

* * @param warning a {@link io.spotnext.spring.web.http.Status} object. */ public void addWarning(final Status warning) { this.warnings.add(warning); } /** {@inheritDoc} */ @Override public int hashCode() { return Objects.hashCode(this); } /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { return Objects.equals(this, obj); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy