uint16.go 490 B

123456789101112131415161718192021222324252627282930313233343536
  1. package optional
  2. type Uint16 struct {
  3. isSet bool
  4. value uint16
  5. }
  6. func NewUint16(value uint16) Uint16 {
  7. return Uint16{
  8. true,
  9. value,
  10. }
  11. }
  12. // EmptyUint16 returns a new Uint16 that does not have a value set.
  13. func EmptyUint16() Uint16 {
  14. return Uint16{
  15. false,
  16. 0,
  17. }
  18. }
  19. func (i Uint16) IsSet() bool {
  20. return i.isSet
  21. }
  22. func (i Uint16) Value() uint16 {
  23. return i.value
  24. }
  25. func (i Uint16) Default(defaultValue uint16) uint16 {
  26. if i.isSet {
  27. return i.value
  28. }
  29. return defaultValue
  30. }