switch to error-prone annotations to replace LGPL dependency (#50)
[storage-units.git] / storage-units-model / src / main / java / wtf / metio / storageunits / model / Terabyte.java
blob37df3e8c134d6c86fe9b248f99be15e5ff37787b
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 * Terabyte as specified in ISO IEC 80000-13:2008 (1 Terabyte = 1 000 000 000 000 Byte).
17 public final class Terabyte extends StorageUnit<Terabyte> {
19 @Serial
20 private static final long serialVersionUID = 2160488069631638952L;
22 Terabyte(final @NotNull BigInteger numberOfBytes) {
23 super(numberOfBytes);
26 /**
27 * @param numberOfBytes The amount of bytes the Terabyte contains.
28 * @return A new Kilobyte unit with the given value.
30 @CheckReturnValue
31 public static @NotNull Terabyte valueOf(final @NotNull BigInteger numberOfBytes) {
32 return new Terabyte(numberOfBytes);
35 /**
36 * @param numberOfBytes The amount of bytes the Terabyte contains.
37 * @return A new Terabyte unit with the given value.
39 @CheckReturnValue
40 public static @NotNull Terabyte valueOf(final long numberOfBytes) {
41 return valueOf(BigInteger.valueOf(numberOfBytes));
44 /**
45 * @param numberOfBytes The amount of bytes the Terabyte contains.
46 * @return A new Terabyte unit with the given value.
48 @CheckReturnValue
49 public static @NotNull Terabyte valueOf(final @NotNull Long numberOfBytes) {
50 return valueOf(numberOfBytes.longValue());
53 @Override
54 @CheckReturnValue
55 public @NotNull Terabyte add(final long bytesToAdd) {
56 return add(BigInteger.valueOf(bytesToAdd));
59 @Override
60 @CheckReturnValue
61 public @NotNull Terabyte add(final @NotNull BigInteger bytesToAdd) {
62 return new Terabyte(bytes.add(bytesToAdd));
65 @Override
66 @CheckReturnValue
67 public @NotNull Terabyte add(final @NotNull StorageUnit<?> storageAmount) {
68 return add(storageAmount.bytes);
71 @Override
72 @CheckReturnValue
73 public @NotNull Terabyte divide(final long divisor) {
74 return divide(BigInteger.valueOf(divisor));
77 @Override
78 @CheckReturnValue
79 public @NotNull Terabyte divide(final @NotNull BigInteger divisor) {
80 return new Terabyte(bytes.divide(divisor));
83 @Override
84 @CheckReturnValue
85 public @NotNull Terabyte multiply(final long factor) {
86 return multiply(BigInteger.valueOf(factor));
89 @Override
90 @CheckReturnValue
91 public @NotNull Terabyte multiply(final @NotNull BigInteger factor) {
92 return new Terabyte(bytes.multiply(factor));
95 @Override
96 @CheckReturnValue
97 public @NotNull Terabyte subtract(final long bytesToSubtract) {
98 return subtract(BigInteger.valueOf(bytesToSubtract));
101 @Override
102 @CheckReturnValue
103 public @NotNull Terabyte subtract(final @NotNull BigInteger bytesToSubtract) {
104 return new Terabyte(bytes.subtract(bytesToSubtract));
107 @Override
108 @CheckReturnValue
109 public @NotNull Terabyte subtract(final @NotNull StorageUnit<?> storageAmount) {
110 return subtract(storageAmount.bytes);
113 @Override
114 @CheckReturnValue
115 protected @NotNull BigInteger getNumberOfBytesPerUnit() {
116 return StorageUnit.BYTES_IN_A_TERABYTE;
119 @Override
120 @CheckReturnValue
121 protected @NotNull String getSymbol() {
122 return "TB";
125 @Override
126 @CheckReturnValue
127 protected @NotNull Function<@NotNull BigInteger, @NotNull StorageUnit<?>> converter() {
128 return StorageUnits::decimalValueOf;