update project meta
[storage-units.git] / storage-units-model / src / main / java / wtf / metio / storageunits / model / Tebibyte.java
blobaec906bb3ef160b8df5ae14b43d5711ffa14b259
1 /*
2 * SPDX-FileCopyrightText: The Storage-Units Authors
3 * SPDX-License-Identifier: 0BSD
4 */
5 package wtf.metio.storageunits.model;
7 import java.io.Serial;
8 import java.math.BigInteger;
9 import java.util.function.Function;
10 import edu.umd.cs.findbugs.annotations.CheckReturnValue;
11 import org.jetbrains.annotations.NotNull;
13 /**
14 * Tebibyte as specified in ISO IEC 80000-13:2008 (1 Tebibyte = 1 099 511 627 776 Byte).
16 public final class Tebibyte extends StorageUnit<Tebibyte> {
18 @Serial
19 private static final long serialVersionUID = 3614537130129620881L;
21 Tebibyte(@NotNull final BigInteger bytes) {
22 super(bytes);
25 /**
26 * @param numberOfBytes The amount of bytes the Tebibyte contains.
27 * @return A new Tebibyte unit with the given value.
29 @NotNull
30 @CheckReturnValue
31 public static Tebibyte valueOf(@NotNull final BigInteger numberOfBytes) {
32 return new Tebibyte(numberOfBytes);
35 /**
36 * @param numberOfBytes The amount of bytes the Tebibyte contains.
37 * @return A new Tebibyte unit with the given value.
39 @NotNull
40 @CheckReturnValue
41 public static Tebibyte valueOf(final long numberOfBytes) {
42 return valueOf(BigInteger.valueOf(numberOfBytes));
45 /**
46 * @param numberOfBytes The amount of bytes the Tebibyte contains.
47 * @return A new Tebibyte unit with the given value.
49 @NotNull
50 @CheckReturnValue
51 public static Tebibyte valueOf(@NotNull final Long numberOfBytes) {
52 return valueOf(numberOfBytes.longValue());
55 @Override
56 @NotNull
57 @CheckReturnValue
58 public Tebibyte add(final long bytesToAdd) {
59 return add(BigInteger.valueOf(bytesToAdd));
62 @Override
63 @NotNull
64 @CheckReturnValue
65 public Tebibyte add(@NotNull final BigInteger bytesToAdd) {
66 return new Tebibyte(bytes.add(bytesToAdd));
69 @Override
70 @NotNull
71 @CheckReturnValue
72 public Tebibyte add(@NotNull final StorageUnit<?> storageAmount) {
73 return add(storageAmount.bytes);
76 @Override
77 @NotNull
78 @CheckReturnValue
79 public Tebibyte divide(final long divisor) {
80 return divide(BigInteger.valueOf(divisor));
83 @Override
84 @NotNull
85 @CheckReturnValue
86 public Tebibyte divide(@NotNull final BigInteger divisor) {
87 return new Tebibyte(bytes.divide(divisor));
90 @Override
91 @NotNull
92 @CheckReturnValue
93 public Tebibyte multiply(final long factor) {
94 return multiply(BigInteger.valueOf(factor));
97 @Override
98 @NotNull
99 @CheckReturnValue
100 public Tebibyte multiply(@NotNull final BigInteger factor) {
101 return new Tebibyte(bytes.multiply(factor));
104 @Override
105 @NotNull
106 @CheckReturnValue
107 public Tebibyte subtract(final long bytesToSubtract) {
108 return subtract(BigInteger.valueOf(bytesToSubtract));
111 @Override
112 @NotNull
113 @CheckReturnValue
114 public Tebibyte subtract(@NotNull final BigInteger bytesToSubtract) {
115 return new Tebibyte(bytes.subtract(bytesToSubtract));
118 @Override
119 @NotNull
120 @CheckReturnValue
121 public Tebibyte subtract(@NotNull final StorageUnit<?> storageAmount) {
122 return subtract(storageAmount.bytes);
125 @Override
126 @NotNull
127 @CheckReturnValue
128 protected BigInteger getNumberOfBytesPerUnit() {
129 return BYTES_IN_A_TEBIBYTE;
132 @Override
133 @NotNull
134 @CheckReturnValue
135 protected String getSymbol() {
136 return "TiB";
139 @Override
140 @NotNull
141 @CheckReturnValue
142 protected Function<@NotNull BigInteger, @NotNull StorageUnit<?>> converter() {
143 return StorageUnits::binaryValueOf;