2 * SPDX-FileCopyrightText: The Storage-Units Authors
3 * SPDX-License-Identifier: 0BSD
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
;
15 * Byte as specified in ISO IEC 80000-13:2008 (1 Byte).
17 public final class Byte
extends StorageUnit
<Byte
> {
20 private static final long serialVersionUID
= 6952239416014811456L;
22 Byte(final @NotNull BigInteger numberOfBytes
) {
27 * @param numberOfBytes The amount of bytes the Byte contains.
28 * @return A new Byte unit with the given value.
31 public static @NotNull Byte
valueOf(final @NotNull BigInteger numberOfBytes
) {
32 return new Byte(numberOfBytes
);
36 * @param numberOfBytes The amount of bytes the Byte contains.
37 * @return A new Byte unit with the given value.
40 public static @NotNull Byte
valueOf(final long numberOfBytes
) {
41 return valueOf(BigInteger
.valueOf(numberOfBytes
));
45 * @param numberOfBytes The amount of bytes the Byte contains.
46 * @return A new Byte unit with the given value.
49 public static @NotNull Byte
valueOf(final @NotNull Long numberOfBytes
) {
50 return valueOf(numberOfBytes
.longValue());
55 public @NotNull Byte
add(final long bytesToAdd
) {
56 return add(BigInteger
.valueOf(bytesToAdd
));
60 public @NotNull Byte
add(final @NotNull BigInteger bytesToAdd
) {
61 return new Byte(bytes
.add(bytesToAdd
));
66 public @NotNull Byte
add(final @NotNull StorageUnit
<?
> storageAmount
) {
67 return add(storageAmount
.bytes
);
72 public @NotNull Byte
divide(final long divisor
) {
73 return divide(BigInteger
.valueOf(divisor
));
77 public @NotNull Byte
divide(final @NotNull BigInteger divisor
) {
78 return new Byte(bytes
.divide(divisor
));
83 public @NotNull Byte
multiply(final long factor
) {
84 return new Byte(bytes
.multiply(BigInteger
.valueOf(factor
)));
88 public @NotNull Byte
multiply(final @NotNull BigInteger factor
) {
89 return new Byte(bytes
.multiply(factor
));
94 public @NotNull Byte
subtract(final long bytesToSubtract
) {
95 return new Byte(bytes
.subtract(BigInteger
.valueOf(bytesToSubtract
)));
99 public @NotNull Byte
subtract(final @NotNull BigInteger bytesToSubtract
) {
100 return new Byte(bytes
.subtract(bytesToSubtract
));
105 public @NotNull Byte
subtract(final @NotNull StorageUnit
<?
> storageAmount
) {
106 return new Byte(bytes
.subtract(storageAmount
.bytes
));
110 protected @NotNull BigInteger
getNumberOfBytesPerUnit() {
111 return BigInteger
.ONE
;
116 protected @NotNull String
getSymbol() {
122 protected @NotNull Function
<@NotNull BigInteger
, @NotNull StorageUnit
<?
>> converter() {
123 return StorageUnits
::binaryValueOf
;