Skip to content

Instantly share code, notes, and snippets.

@ColadaFF
Created January 7, 2020 20:36
Show Gist options
  • Save ColadaFF/055e3214dc76538e2fa2aaf17cdf448a to your computer and use it in GitHub Desktop.
Save ColadaFF/055e3214dc76538e2fa2aaf17cdf448a to your computer and use it in GitHub Desktop.
import com.google.common.base.Preconditions;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.math.BigDecimal;
@ToString
@EqualsAndHashCode
public class Price {
// factory
public static Price of(BigDecimal value){
return new Price(value);
}
private final BigDecimal value;
private Price(BigDecimal value) {
Preconditions.checkNotNull(value, "El valor no puede ser nulo");
Preconditions.checkArgument(value.compareTo(BigDecimal.ZERO) != -1, "El valor no puede ser negativo");
this.value = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment