switch to error-prone annotations to replace LGPL dependency (#50)
[storage-units.git] / storage-units-model / src / main / java / wtf / metio / storageunits / model / Byte.java
blobf64ddecfdcdaf765f8df20253af9492ec624fa48
1 /*
2 * SPDX-FileCopyrightText: The Storage-Units Authors
3 * SPDX-License-Identifier: 0BSD
4 */
5 package wtf.metio.storageunits.model;
7 import com.google.errorprone.annotations.CheckReturnValue;
8 import org.jetbrains.annotations.NotNull;
10 import java.io.Serial;
11 import java.math.BigInteger;
12 import java.util.function.Function;
14 /**
15 * Byte as specified in ISO IEC 80000-13:2008 (1 Byte).
17 public final class Byte extends StorageUnit<Byte> {
19 @Serial
20 private static final long serialVersionUID = 6952239416014811456L;
22 Byte(final @NotNull BigInteger numberOfBytes) {
23 super(numberOfBytes);
26 /**
27 * @param numberOfBytes The amount of bytes the Byte contains.
28 * @return A new Byte unit with the given value.
30 @CheckReturnValue
31 public static @NotNull Byte valueOf(final @NotNull BigInteger numberOfBytes) {
32 return new Byte(numberOfBytes);
35 /**
36 * @param numberOfBytes The amount of bytes the Byte contains.
37 * @return A new Byte unit with the given value.
39 @CheckReturnValue
40 public static @NotNull Byte valueOf(final long numberOfBytes) {
41 return valueOf(BigInteger.valueOf(numberOfBytes));
44 /**
45 * @param numberOfBytes The amount of bytes the Byte contains.
46 * @return A new Byte unit with the given value.
48 @CheckReturnValue
49 public static @NotNull Byte valueOf(final @NotNull Long numberOfBytes) {
50 return valueOf(numberOfBytes.longValue());
53 @Override
54 @CheckReturnValue
55 public @NotNull Byte add(final long bytesToAdd) {
56 return add(BigInteger.valueOf(bytesToAdd));
59 @Override
60 public @NotNull Byte add(final @NotNull BigInteger bytesToAdd) {
61 return new Byte(bytes.add(bytesToAdd));
64 @Override
65 @CheckReturnValue
66 public @NotNull Byte add(final @NotNull StorageUnit<?> storageAmount) {
67 return add(storageAmount.bytes);
70 @Override
71 @CheckReturnValue
72 public @NotNull Byte divide(final long divisor) {
73 return divide(BigInteger.valueOf(divisor));
76 @Override
77 public @NotNull Byte divide(final @NotNull BigInteger divisor) {
78 return new Byte(bytes.divide(divisor));
81 @Override
82 @CheckReturnValue
83 public @NotNull Byte multiply(final long factor) {
84 return new Byte(bytes.multiply(BigInteger.valueOf(factor)));
87 @Override
88 public @NotNull Byte multiply(final @NotNull BigInteger factor) {
89 return new Byte(bytes.multiply(factor));
92 @Override
93 @CheckReturnValue
94 public @NotNull Byte subtract(final long bytesToSubtract) {
95 return new Byte(bytes.subtract(BigInteger.valueOf(bytesToSubtract)));
98 @Override
99 public @NotNull Byte subtract(final @NotNull BigInteger bytesToSubtract) {
100 return new Byte(bytes.subtract(bytesToSubtract));
103 @Override
104 @CheckReturnValue
105 public @NotNull Byte subtract(final @NotNull StorageUnit<?> storageAmount) {
106 return new Byte(bytes.subtract(storageAmount.bytes));
109 @Override
110 protected @NotNull BigInteger getNumberOfBytesPerUnit() {
111 return BigInteger.ONE;
114 @Override
115 @CheckReturnValue
116 protected @NotNull String getSymbol() {
117 return "B";
120 @Override
121 @CheckReturnValue
122 protected @NotNull Function<@NotNull BigInteger, @NotNull StorageUnit<?>> converter() {
123 return StorageUnits::binaryValueOf;